Add k script

This commit is contained in:
Digital Studium 2024-04-06 17:07:25 +03:00
parent f30d0805aa
commit 35af86de58
5 changed files with 35 additions and 23 deletions

View File

@ -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

View File

@ -1 +1 @@
1.7
1.8

31
k Executable file
View File

@ -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

18
lk
View File

@ -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

2
r
View File

@ -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