add: shortcut handler for kitty
This commit is contained in:
@@ -3,8 +3,8 @@
|
|||||||
# @file_name: dao.sh
|
# @file_name: dao.sh
|
||||||
# @description: main script handle for dao
|
# @description: main script handle for dao
|
||||||
# @date: 2025-11-12
|
# @date: 2025-11-12
|
||||||
# @version: 0.0.1
|
# @version: 0.1.0
|
||||||
# @usage: ./dao.sh {update|transfer|pwgen|mount|firewall} [args]
|
# @usage: ./dao.sh {kitty|mount|pwgen|update} [args]
|
||||||
#
|
#
|
||||||
# @author: Jamie Albert
|
# @author: Jamie Albert
|
||||||
# @author_contact: <mailto:jamie.albert@flatmail.me
|
# @author_contact: <mailto:jamie.albert@flatmail.me
|
||||||
@@ -40,36 +40,33 @@ exit 0
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[ "${1:-}" == "-h" || "${1:-}" == "--help" ]] && show_help
|
[[ "${1:-}" == "-h" || "${1:-}" == "--help" ]] && show_help
|
||||||
|
declare -g COMMAND=${1:-}
|
||||||
|
shift || true
|
||||||
|
|
||||||
# ---
|
# ---
|
||||||
# shellcheck disable=1091
|
# shellcheck disable=1091
|
||||||
# ---
|
# ---
|
||||||
setup() {
|
main() {
|
||||||
. /usr/local/share/dao/libs/libs_dao.sh
|
. /usr/local/share/dao/libs/libs_dao.sh
|
||||||
. /usr/local/share/dao/config/dao.conf
|
. /usr/local/share/dao/config/dao.conf
|
||||||
}
|
|
||||||
|
|
||||||
declare -g COMMAND=$1
|
|
||||||
shift
|
|
||||||
|
|
||||||
main() {
|
|
||||||
setup
|
|
||||||
case "${COMMAND}" in
|
case "${COMMAND}" in
|
||||||
update)
|
kitty)
|
||||||
"${DAO_SCRIPTS_DIR}/on_demand/update.sh" "$@"
|
"${DAO_SCRIPTS_DIR}/patches/kitty_handler.sh" "$@"
|
||||||
;;
|
|
||||||
transfer)
|
|
||||||
"${DAO_SCRIPTS_DIR}/on_demand/transfer.sh" "$@"
|
|
||||||
;;
|
|
||||||
pwgen)
|
|
||||||
"${DAO_SCRIPTS_DIR}/on_demand/pwgen.sh" "$@"
|
|
||||||
;;
|
;;
|
||||||
mount)
|
mount)
|
||||||
"${DAO_SCRIPTS_DIR}/reboot/mount.sh" "$@"
|
"${DAO_SCRIPTS_DIR}/reboot/mount.sh" "$@"
|
||||||
;;
|
;;
|
||||||
|
pwgen)
|
||||||
|
"${DAO_SCRIPTS_DIR}/on_demand/pwgen.sh" "$@"
|
||||||
|
;;
|
||||||
|
update)
|
||||||
|
"${DAO_SCRIPTS_DIR}/on_demand/update.sh" "$@"
|
||||||
|
;;
|
||||||
|
"")
|
||||||
|
dao::error 1 "No command provided. Use -h for help." >&2
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Usage: dao {update|transfer|pwgen|mount|firewall} [args]"
|
dao::error 1 "Unknown command: ${COMMAND}" >&2
|
||||||
exit 1
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ _dao_completion() {
|
|||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
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
|
case "${COMP_CWORD}" in
|
||||||
1)
|
1)
|
||||||
@@ -17,8 +17,8 @@ _dao_completion() {
|
|||||||
pwgen)
|
pwgen)
|
||||||
mapfile -t COMPREPLY < <(compgen -W "3 4 5 6 7 8 9 10" -- "${cur}")
|
mapfile -t COMPREPLY < <(compgen -W "3 4 5 6 7 8 9 10" -- "${cur}")
|
||||||
;;
|
;;
|
||||||
transfer)
|
kitty)
|
||||||
mapfile -t COMPREPLY < <(compgen -W "-d -u -uc -ur" -- "${cur}")
|
mapfile -t COMPREPLY < <(compgen -W "--list --new-instance --new-tab" -- "${cur}")
|
||||||
;;
|
;;
|
||||||
*) ;;
|
*) ;;
|
||||||
esac
|
esac
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ shell_integration enabled
|
|||||||
strip_trailing_spaces smart
|
strip_trailing_spaces smart
|
||||||
editor codium
|
editor codium
|
||||||
allow_remote_control yes
|
allow_remote_control yes
|
||||||
listen_on unix:~/.config/kitty/.kitty_socket
|
listen_on unix:/tmp/kitty.socket
|
||||||
strip_trailing_spaces smart
|
strip_trailing_spaces smart
|
||||||
|
|
||||||
# --- Keybinds
|
# --- Keybinds
|
||||||
|
|||||||
86
scripts/patches/kitty_handler.sh
Executable file
86
scripts/patches/kitty_handler.sh
Executable file
@@ -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: <mailto:jamie.albert@flatmail.me
|
||||||
|
# @license: GNU Affero General Public License v3.0 (Included in LICENSE)
|
||||||
|
# Copyright (C) 2025, Jamie Albert
|
||||||
|
# ---
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
show_help() {
|
||||||
|
cat <<'EOF'
|
||||||
|
Usage: ./kitty_handler.sh [OPTIONS]
|
||||||
|
|
||||||
|
A script to launch an new instance, or if opened, then a new tab in the kitty terminal emulator.
|
||||||
|
|
||||||
|
OPTIONS:
|
||||||
|
-h, --help Show this help message and exit
|
||||||
|
-l, --list Returns current kitty instances
|
||||||
|
-ni, --new-instance Launches a new kitty instance
|
||||||
|
-nt, --new-tab Launches a new kitty tab
|
||||||
|
|
||||||
|
EXAMPLES:
|
||||||
|
./kitty_handler.sh -h Show this help
|
||||||
|
./kitty_handler.sh -l Returns current kitty instances
|
||||||
|
./kitty_handler.sh -ni Launches a new kitty instance
|
||||||
|
./kitty_handler.sh -nt Launches a new kitty tab
|
||||||
|
EOF
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# ---
|
||||||
|
# shellcheck disable=1091
|
||||||
|
# ---
|
||||||
|
main() {
|
||||||
|
[[ $# -eq 0 ]] && set -- "-nt"
|
||||||
|
[[ "$1" == "-h" || "$1" == "--help" ]] && show_help
|
||||||
|
|
||||||
|
. /usr/local/share/dao/libs/libs_dao.sh
|
||||||
|
case "$1" in
|
||||||
|
-nt | --new-tab)
|
||||||
|
dao::info "Looking for a kitty instance"
|
||||||
|
socket=$(find /tmp -name "kitty.socket-*" -type s 2>/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 "$@"
|
||||||
Reference in New Issue
Block a user