-
Notifications
You must be signed in to change notification settings - Fork 3
/
kitty-ctrl
executable file
·65 lines (59 loc) · 1.72 KB
/
kitty-ctrl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env bash
# Allow to control kitty https://sw.kovidgoyal.net/kitty/
#
# It will detect the socket (hopefully you should have only one)
# It will by default launch kitty script commands to it
# It has a simple raise to focus support for example if you do :
#
# kitty-ctrl -t TITLE Binary
#
# It will go over the tabs with TITLE see if it's there and then focus or launch
# a tab with the binary name Binary and set the tab tile as TITLE to it.
#
# you will need this configuration in your kitty.conf :
# allow_remote_control yes
# listen_on unix:/tmp/mykitty
#
set -eu
socket=$(find /tmp -maxdepth 1 -type s -name "mykitty-*" -printf "%T@ %Tc %p\n" | sort -rn|sed -n 's/.* //;p;Q')
verbose=
title=
export KITTY_LISTEN_ON=unix:${socket}
TMP=$(mktemp /tmp/.mm.XXXXXX)
clean() { rm -f ${TMP}; }
trap clean EXIT
if [[ -n ${2:-""} && $1 == "jump" ]];then
shift
while getopts "vt:" arg; do
case $arg in
v)
verbose=yes;
set -x
;;
t)
title=$OPTARG
;;
*)
echo "unkown option: ${OPTARG}";
exit 1
;;
esac
done
shift $((OPTIND-1))
[[ -z ${title} ]] && title=${1^}
if ! pgrep kitty >/dev/null || [[ -z ${socket} ]];then
exec /usr/bin/kitty $@
exit 0
fi
kitty @ launch --type=tab --tab-title "${title}" --title "${title}" /bin/bash -c "${@}" &&
kitty @ focus-window --match title:"${title}" >${TMP} 2>&1
[[ -n $SWAYSOCK ]] && sway-focus kitty
exit
elif ! pgrep kitty >/dev/null;then
echo $@
exec /usr/bin/kitty "/bin/bash -c $@" &
exit 0
fi
[[ -z ${socket} ]] && exit 1
kitty @ "$@"
exit $?