Skip to content

Commit

Permalink
add scripts folder and fixes for tmux popup
Browse files Browse the repository at this point in the history
  • Loading branch information
khatibomar committed Oct 11, 2024
1 parent 6d22ebc commit 93bebc9
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 9 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
34 changes: 34 additions & 0 deletions backup-scripts/install_scripts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

# Get the current date and time in the format YYYY-MM-DD_HH-MM-SS
current_date=$(date +"%Y-%m-%d_%H-%M-%S")

# Define the source and destination directories for scripts
SCRIPTS_DIR="./scripts" # Change this if the new scripts directory is elsewhere
BACKUP_DIR="$HOME/.config-backup-$current_date"
OLD_SCRIPTS_DIR="$HOME/scripts"

# Create a backup directory
mkdir -p "$BACKUP_DIR"

# Handle the scripts directory as a special case
if [ -d "$OLD_SCRIPTS_DIR" ]; then
BACKUP_SCRIPTS_DIR="$BACKUP_DIR/.scripts"

# Backup the old scripts directory
echo "Backing up the old scripts directory to $BACKUP_SCRIPTS_DIR"
mv "$OLD_SCRIPTS_DIR" "$BACKUP_SCRIPTS_DIR"
else
echo "No existing scripts directory found. No backup needed."
fi

# Copy the new scripts directory if it exists
if [ -d "$SCRIPTS_DIR" ]; then
echo "Copying the new scripts directory from $SCRIPTS_DIR to $OLD_SCRIPTS_DIR"
cp -r "$SCRIPTS_DIR" "$OLD_SCRIPTS_DIR"
else
echo "Error: New scripts directory $SCRIPTS_DIR does not exist."
exit 1
fi

echo "Backup and copy for scripts completed successfully."
File renamed without changes.
8 changes: 1 addition & 7 deletions config/tmux.conf
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,4 @@ set -g window-status-style "fg=#959dcb bg=#292d3e"
set -g window-status-current-style "fg=#89ddff,bold bg=#292d3e"
set -g mode-style "bg=#959dcb fg=#292d3e"

bind-key p run-shell 'if [ "$(tmux display-message -p -F "#{session_name}")" = "popup" ]; then
tmux kill-session -t popup;
else
tmux popup -d "#(pwd)" -xC -yC -w80% -h75% -E "tmux attach -t popup || tmux new -s popup";
fi'


bind-key p run-shell '$HOME/scripts/toggle_tmux_popup.sh'
5 changes: 4 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#!/bin/bash

# Navigate to the scripts folder
SCRIPT_DIR="$(dirname "$0")/scripts"
SCRIPT_DIR="$(dirname "$0")/backup-scripts"

# Run the backup and copy process for Neovim
bash "$SCRIPT_DIR/install_nvim.sh"

# Run the backup and copy process for Config
bash "$SCRIPT_DIR/install_config.sh"

# Run the backup and copy process for Scripts
bash "$SCRIPT_DIR/install_scripts.sh"

# Merge custom gitconfig settings
bash "$SCRIPT_DIR/merge_gitconfig.sh"

Expand Down
2 changes: 1 addition & 1 deletion nvim/lua/config/keymaps.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require("config.keymaps.go-definition")

function OpenTmuxPopup()
local cmd = 'tmux display-popup -E "cd ' .. vim.fn.getcwd() .. ' && $SHELL "'
local cmd = 'bash $HOME/scripts/toggle_tmux_popup.sh'
vim.fn.system(cmd)
end

Expand Down
26 changes: 26 additions & 0 deletions scripts/colors.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# Print basic colors (0-7)
echo "Basic Colors (0-7):"
for i in {0..7}; do
printf "\e[3${i}mColor ${i}\e[0m "
done
echo -e "\n"

# Print bright colors (8-15)
echo "Bright Colors (8-15):"
for i in {0..7}; do
printf "\e[3${i};1mColor $((i + 8))\e[0m "
done
echo -e "\n"

# Print 256 colors
echo "256 Colors:"
for i in {0..255}; do
printf "\e[38;5;${i}mColor ${i}\e[0m "
# Break line after every 16 colors for better readability
if (((i + 1) % 16 == 0)); then
echo
fi
done
echo
45 changes: 45 additions & 0 deletions scripts/k8s_kill_stuck_namespace.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash
#
# NOTE: force deleting a namespace should be absolute last resort,
# you want instead to find which resource is holding up the namespace
# and clean that up (vs leaking resources)
#
# First check what is holding up the ns, if it's for instance:
# custom.metrics.k8s.io/v1beta1: the server is currently
# unable to handle the request
# Then:
# k get apiservice v1beta1.custom.metrics.k8s.io
# NAME SERVICE AVAILABLE AGE
# v1beta1.custom.metrics.k8s.io istio-system/prometheus-adapter False (ServiceNotFound) 2d4h
# k delete apiservice v1beta1.custom.metrics.k8s.io
# (though this shouldn't happen: find out why prom didn't unregister...)
#
# (Very) Partially inspired by knsk.sh
#
echo "Checking for stuck namespaces"
NSS=$(kubectl get ns 2>/dev/null | grep Terminating | cut -f1 -d ' ')
if [[ "$NSS" == "" ]]; then
echo "No stuck namespaces found"
exit 0
fi
# Start kubectl proxy to talk to API server
PORT=8118
kubectl proxy --port=$PORT &
kp_pid=$!
function cleanup {
kill $kp_pid
echo "Done cleanup. killed $kp_pid."
}
trap cleanup exit

for NS in $NSS; do
echo "Found stuck namespace: $NS"
kubectl get all -n "$NS"
echo "While this is bad too (leaks resources),"
# kubectl patch svc -n istio-system istio-ingressgateway -p '{"metadata":{"finalizers":null}}'
echo "Did you try to: kubectl patch -p '{\"metadata\":{\"finalizers\":null}}'"
echo "^C now before delete..."
sleep 5
JSON=$(kubectl get ns "$NS" -o json | jq -r '.spec.finalizers=[]')
curl -X PUT --data-binary "$JSON" -H "Content-Type: application/json" "http://localhost:$PORT/api/v1/namespaces/$NS/finalize"
done
12 changes: 12 additions & 0 deletions scripts/toggle_tmux_popup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/zsh

#! /usr/bin/env bash

tmux_popup_session_name="_popup"

if [ "$(tmux display-message -p -F "#{session_name}")" = "${tmux_popup_session_name}" ];then
tmux detach-client
else
tmux popup -d '#{pane_current_path}' -xC -yC -w80% -h80% -E\
"tmux new-session -A -s ${tmux_popup_session_name}"
fi

0 comments on commit 93bebc9

Please sign in to comment.