Skip to content

Instantly share code, notes, and snippets.

@mbollmann
Created March 29, 2024 11:44
Show Gist options
  • Save mbollmann/abebe795522a173bd4d4821ac1b6c947 to your computer and use it in GitHub Desktop.
Save mbollmann/abebe795522a173bd4d4821ac1b6c947 to your computer and use it in GitHub Desktop.
Bind this to a system-wide hotkey to toggle visibility of Kitty, whether it's already started or not.
#!/usr/bin/env fish
if not command -q kitty
set error_msg "kitty not found."
else if not command -q xdotool
set error_msg "xdotool not found."
else if not command -q wmctrl
set error_msg "wmctrl not found."
end
if test -n "$error_msg"
if command -q notify-send
notify-send --urgency=normal --icon=emblem-warning --expire-time=3000 --app-name=toggle-kitty "Cannot toggle kitty" "$error_msg"
end
exit 1
end
set -l kitty_id (xdotool search --class "kitty" | tail -n1)
if test -z "$kitty_id"
# Start up kitty ...
kitty &>/dev/null & ; disown
# ... and move it to the desired location
xdotool search --sync --class "kitty" windowsize 90% 80% windowmove --sync 5% 0
else
set -l focus_id (xdotool getwindowfocus)
if test "$kitty_id" = "$focus_id"
# Minimize
xdotool windowminimize "$kitty_id"
else
# Raise to the foreground
wmctrl -x -R kitty
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment