From 35af86de58d8faf1c31da5b59535e8938dfdb535 Mon Sep 17 00:00:00 2001 From: Digital Studium Date: Sat, 6 Apr 2024 17:07:25 +0300 Subject: [PATCH] Add k script --- README.md | 5 ++--- VERSION | 2 +- k | 31 +++++++++++++++++++++++++++++++ lk | 18 ------------------ r | 2 +- 5 files changed, 35 insertions(+), 23 deletions(-) create mode 100755 k delete mode 100755 lk diff --git a/README.md b/README.md index 5e6fc4b..3aec5de 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,8 @@ GUI scripts for popular cli tools, based on dialog and fzf - `a` - for managing apt packages - `g` - for managing git repo - `s` - for managing systemd services +- `k` - for managing kubernetes (depends on kubectl) - `r` - for running named commands from ~/.aliases.txt file -- `f` - open `lf` file manager -- `lk` - listen for keys above (except `r`) See [Screenshots](#screenshots) section @@ -24,7 +23,7 @@ Install dependencies: `fzf`, `dialog`, `xdotool`, `x11-xkb-utils` Then clone this repo and copy all scripts to one of the PATH folder: ``` git clone https://git.digitalstudium.com/digitalstudium/gui-scripts.git -sudo cp gui-scripts/{a,g,s,r} /usr/local/bin/ +sudo cp gui-scripts/{a,g,s,r,k} /usr/local/bin/ ``` ## Screenshots diff --git a/VERSION b/VERSION index d3bdbdf..6259340 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.7 +1.8 diff --git a/k b/k new file mode 100755 index 0000000..cd20219 --- /dev/null +++ b/k @@ -0,0 +1,31 @@ +#!/bin/bash +set -e +trap 'clear' SIGINT +cat > /tmp/.dialogrc << EOL +# Item color +tag_color = (BLACK,WHITE,ON) +EOL +namespace=$(kubectl get ns --no-headers | awk '{ print $1 }' | fzf --multi --cycle --reverse --preview 'kubectl get pods -o wide -n {1}') +resource=$(DIALOGRC=/tmp/.dialogrc dialog --stdout --erase-on-exit --menu "Choose resource in $namespace" 10 40 0 "Pods" 1 "Services" 2 "Ingress" 3 "Secrets" 4) +set +ex + + +if [ "$resource" = "Pods" ]; then + pod=$(kubectl -n $namespace get pods --no-headers | awk '{ print $1 }' | fzf --multi --cycle --reverse --preview "kubectl get pod -n $namespace {1} -o yaml") + if [ ! -z "$pod" ]; then + action=$(DIALOGRC=/tmp/.dialogrc dialog --stdout --erase-on-exit --menu "Choose action for $pod in $namespace" 10 40 0 "Logs" 1 "Describe pod" 2 "Exec -it" 3 "Delete pod" 4) + fi + if [ ! -z "$action" ]; then + xdotool type --delay 0 "kubectl -n $namespace ${action,,} $pod" && xdotool key --delay 0 Return + fi +elif [ "$resource" = "Services" ]; then + svc=$(kubectl -n $namespace get svc --no-headers | awk '{ print $1 }' | fzf --multi --cycle --reverse --preview "kubectl get svc -n $namespace {1} -o yaml") + if [ ! -z "$svc" ]; then + action=$(DIALOGRC=/tmp/.dialogrc dialog --stdout --erase-on-exit --menu "Choose action for $pod in $namespace" 10 40 0 "Get endpoints" 1 "Edit service" 2) + fi + if [ ! -z "$action" ]; then + xdotool type --delay 0 "kubectl -n $namespace ${action,,} $svc" && xdotool key --delay 0 Return + fi +fi + + diff --git a/lk b/lk deleted file mode 100755 index cc99c5b..0000000 --- a/lk +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -clear -while true; do -echo Listen to keys... -read -rsn1 input -if [ "$input" = "a" ]; then - a -elif [ "$input" = "f" ]; then - f -elif [ "$input" = "g" ]; then - g -elif [ "$input" = "s" ]; then - s -elif [ "$input" = "q" ]; then - exit 0 -fi -done diff --git a/r b/r index 0ac7800..d56d102 100755 --- a/r +++ b/r @@ -1,4 +1,4 @@ #!/bin/bash trap 'clear' SIGINT setxkbmap -cat ~/.aliases.txt | fzf | cut -d : -f 2- | (stty -F /dev/tty -echo; xargs -0 -I _ xdotool type --delay 0 _; stty -F /dev/tty echo) && xdotool key Return +cat ~/.aliases.txt | fzf | cut -d : -f 2- | sed s/\ // | (stty -F /dev/tty -echo; xargs -0 -I _ xdotool type --delay 0 _; stty -F /dev/tty echo) && xdotool key Return