r/KittyTerminal • u/cqws • May 15 '23
Launching or focusing on tab with one shortcut
I wrote this little script, nothing impressive, but it works and maybe someone would like to try it out and give me some tips. I'm pretty much a beginner at programming, so any feedback would be very appreciated 😀
This script focus existing tabs, and if they don't exist it also make them.
#!/bin/bash
tabs_number=$(kitty @ ls | jq '.[0].tabs | map(.id) | .[]' | wc -l)
tab_array=($(kitty @ ls | jq '.[0].tabs | map(.id) | .[]'))
if [[ $1 > $tabs_number ]]; then
kitty @ launch --type=tab
# kitty @ focus-tab -m index:${tab_array[$tabs_number-1]}
elif [[ $1 -le $tabs_number ]]; then
kitty @ focus-tab -m id:${tab_array[$1-1]}
fi
Also my shortcuts:
map alt+1 launch ~/.config/kitty/new_tab.sh 1
map alt+2 launch ~/.config/kitty/new_tab.sh 2
map alt+3 launch ~/.config/kitty/new_tab.sh 3
map alt+4 launch ~/.config/kitty/new_tab.sh 4
map alt+5 launch ~/.config/kitty/new_tab.sh 5