From 9906e0c4176f37be3084fd554e7c7615ef6fdca3 Mon Sep 17 00:00:00 2001 From: oliverhnat Date: Sat, 4 Oct 2025 15:07:30 +0200 Subject: [PATCH] feat(tmuxinator): add autocompletion --- omz-custom/tmux-sessions.sh | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/omz-custom/tmux-sessions.sh b/omz-custom/tmux-sessions.sh index d22852d..72460c1 100644 --- a/omz-custom/tmux-sessions.sh +++ b/omz-custom/tmux-sessions.sh @@ -1,11 +1,11 @@ function mx() { PROJECT_DIR=$1 if [[ -z "$PROJECT_DIR" ]]; then - echo "Usage: mux [SESSION_NAME]" + echo "Usage: mx [SESSION_NAME]" return 1 fi - ALL_PROJECTS=$(tmuxinator list | grep -v tmuxinator) + ALL_PROJECTS=$(get_mux_sessions) IS_VALID_PROJECT=$(echo $ALL_PROJECTS | grep -o "\b$PROJECT_DIR\w*" | head -1) if [[ $IS_VALID_PROJECT != "" ]]; then echo $IS_VALID_PROJECT @@ -33,4 +33,22 @@ function mx() { tmuxinator start $SESSION_NAME } -complete -o default mux + +function get_mux_sessions() { + ALL_PROJECTS=$(tmuxinator list | grep -v tmuxinator) + echo $ALL_PROJECTS +} + +function _mx_autocomplete() { + local cur + cur="${COMP_WORDS[COMP_CWORD]}" + local projects="$(get_mux_sessions)" + COMPREPLY=() + while IFS= read -r line; do + COMPREPLY+=("$line") + done < <( + { compgen -W "$projects" -- "$cur"; compgen -f -- "$cur"; } | sort -u + ) +} + +complete -f -F _mx_autocomplete -o default mx