From 812d1925529a8457c82076fd774e1577691d08dc Mon Sep 17 00:00:00 2001 From: Jamie Albert Date: Thu, 13 Nov 2025 20:54:37 +0000 Subject: [PATCH] add: shortcut handler for kitty --- dotfiles/dao.sh/local/bin/dao.sh | 39 ++++----- .../share/bash-completion/completions/dao.sh | 6 +- dotfiles/theme/.config/kitty/kitty.conf | 2 +- scripts/patches/kitty_handler.sh | 86 +++++++++++++++++++ 4 files changed, 108 insertions(+), 25 deletions(-) create mode 100755 scripts/patches/kitty_handler.sh diff --git a/dotfiles/dao.sh/local/bin/dao.sh b/dotfiles/dao.sh/local/bin/dao.sh index bc22e5f..d4e9b93 100755 --- a/dotfiles/dao.sh/local/bin/dao.sh +++ b/dotfiles/dao.sh/local/bin/dao.sh @@ -3,8 +3,8 @@ # @file_name: dao.sh # @description: main script handle for dao # @date: 2025-11-12 -# @version: 0.0.1 -# @usage: ./dao.sh {update|transfer|pwgen|mount|firewall} [args] +# @version: 0.1.0 +# @usage: ./dao.sh {kitty|mount|pwgen|update} [args] # # @author: Jamie Albert # @author_contact: &2 + ;; *) - echo "Usage: dao {update|transfer|pwgen|mount|firewall} [args]" - exit 1 + dao::error 1 "Unknown command: ${COMMAND}" >&2 ;; esac } diff --git a/dotfiles/dao.sh/local/share/bash-completion/completions/dao.sh b/dotfiles/dao.sh/local/share/bash-completion/completions/dao.sh index d14243b..826efb4 100644 --- a/dotfiles/dao.sh/local/share/bash-completion/completions/dao.sh +++ b/dotfiles/dao.sh/local/share/bash-completion/completions/dao.sh @@ -6,7 +6,7 @@ _dao_completion() { COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" - mapfile -t commands < <(printf "update\ntransfer\npwgen\nmount\n") + mapfile -t commands < <(printf "kitty\nmount\npwgen\nupdate\n") case "${COMP_CWORD}" in 1) @@ -17,8 +17,8 @@ _dao_completion() { pwgen) mapfile -t COMPREPLY < <(compgen -W "3 4 5 6 7 8 9 10" -- "${cur}") ;; - transfer) - mapfile -t COMPREPLY < <(compgen -W "-d -u -uc -ur" -- "${cur}") + kitty) + mapfile -t COMPREPLY < <(compgen -W "--list --new-instance --new-tab" -- "${cur}") ;; *) ;; esac diff --git a/dotfiles/theme/.config/kitty/kitty.conf b/dotfiles/theme/.config/kitty/kitty.conf index 6952c23..a3b8ae9 100644 --- a/dotfiles/theme/.config/kitty/kitty.conf +++ b/dotfiles/theme/.config/kitty/kitty.conf @@ -57,7 +57,7 @@ shell_integration enabled strip_trailing_spaces smart editor codium allow_remote_control yes -listen_on unix:~/.config/kitty/.kitty_socket +listen_on unix:/tmp/kitty.socket strip_trailing_spaces smart # --- Keybinds diff --git a/scripts/patches/kitty_handler.sh b/scripts/patches/kitty_handler.sh new file mode 100755 index 0000000..4379938 --- /dev/null +++ b/scripts/patches/kitty_handler.sh @@ -0,0 +1,86 @@ +#!/usr/bin/env bash +# --- +# @file_name: kitty_handler.sh +# @description: A script to launch an new instance, or if opened, then a new tab in the kitty terminal emulator +# @date: 2025-11-13 +# @version: 0.0.1 +# @usage: ./kitty_handler.sh [-h|--help] +# +# @author: Jamie Albert +# @author_contact: /dev/null | head -1 || true) + if pgrep -x kitty >/dev/null; then + new_window=$(kitty @ --to "unix:${socket}" launch --type=tab) + kitty @ --to "unix:${socket}" focus-window --match "id:${new_window}" + else + /usr/bin/kitty + fi + ;; + -ni | --new-instance) + /usr/bin/kitty + ;; + -l | --list) + if pgrep -x kitty >/dev/null; then + dao::info "Available Kitty sessions:" + /usr/bin/kitty @ ls | python3 -c " +import sys, json +data = json.load(sys.stdin) +for i, os_window in enumerate(data): + print(f'OS Window {i+1}:') + for tab in os_window['tabs']: + print(f' Tab {tab[\"id\"]}: {tab[\"title\"]} (Focused: {tab.get(\"is_focused\", False)})') + for window in tab['windows']: + print(f' Window {window[\"id\"]}: {window[\"title\"]}') + if 'cwd' in window: + print(f' CWD: {window[\"cwd\"]}') + if 'pid' in window: + print(f' PID: {window[\"pid\"]}') +" + else + dao::error "No kitty instances are running." + fi + ;; + *) + dao::error 1 "Unknown option: $1" >&2 + ;; + esac +} + +main "$@"