This commit is contained in:
Your Name 2025-04-21 19:59:00 +12:00
parent b622adfcf8
commit 2f180c900e

View File

@ -15,6 +15,9 @@ _dropshell_completions() {
return 0 return 0
fi fi
# Get available commands from dropshell
local commands=($(dropshell autocomplete_list_commands))
# Command-specific completions # Command-specific completions
case "${prev}" in case "${prev}" in
status|templates|autocomplete_list_servers|autocomplete_list_services|autocomplete_list_commands) status|templates|autocomplete_list_servers|autocomplete_list_services|autocomplete_list_commands)
@ -28,31 +31,43 @@ _dropshell_completions() {
COMPREPLY=( $(compgen -W "${servers[*]}" -- ${cur}) ) COMPREPLY=( $(compgen -W "${servers[*]}" -- ${cur}) )
return 0 return 0
;; ;;
run|install|backup)
# Handle completion for run/install/backup commands
if [[ ${COMP_CWORD} -eq 2 ]]; then
# Second argument is server name
local servers=($(dropshell autocomplete_list_servers))
COMPREPLY=( $(compgen -W "${servers[*]}" -- ${cur}) )
return 0
elif [[ ${COMP_CWORD} -eq 3 ]]; then
# Third argument is service name
local server_name="${COMP_WORDS[2]}"
local services=($(dropshell autocomplete_list_services "$server_name"))
COMPREPLY=( $(compgen -W "${services[*]}" -- ${cur}) )
return 0
elif [[ ${COMP_CWORD} -eq 4 && "${COMP_WORDS[1]}" == "run" ]]; then
# Fourth argument is command name - only for run command
COMPREPLY=( $(compgen -W "${commands[*]}" -- ${cur}) )
return 0
fi
;;
*) *)
# Handle completion for service names and commands after run/install/backup/etc # if ${prev} is not in ${commands}
if [[ ${COMP_CWORD} -ge 2 ]]; then if [[ ! " ${commands[*]} " =~ " ${prev} " ]]; then
if [[ ${COMP_CWORD} -eq 2 ]]; then COMPREPLY=()
# Second argument is server name return 0
local servers=($(dropshell autocomplete_list_servers)) fi
COMPREPLY=( $(compgen -W "${servers[*]}" -- ${cur}) ) # Handle completion for template commands
return 0 if [[ ${COMP_CWORD} -eq 2 ]]; then
elif [[ ${COMP_CWORD} -eq 3 ]]; then # Second argument is server name
# Third argument is service name local servers=($(dropshell autocomplete_list_servers))
local server_name="${COMP_WORDS[2]}" COMPREPLY=( $(compgen -W "${servers[*]}" -- ${cur}) )
local services=($(dropshell autocomplete_list_services "$server_name")) return 0
COMPREPLY=( $(compgen -W "${services[*]}" -- ${cur}) ) elif [[ ${COMP_CWORD} -eq 3 ]]; then
return 0 # Third argument is service name
elif [[ ${COMP_CWORD} -eq 4 ]]; then local server_name="${COMP_WORDS[2]}"
if [[ ${COMP_WORDS[1]} == "run" ]]; then local services=($(dropshell autocomplete_list_services "$server_name"))
# Fourth argument is command name - only relevant for run. COMPREPLY=( $(compgen -W "${services[*]}" -- ${cur}) )
local commands=($(dropshell autocomplete_list_commands)) return 0
COMPREPLY=( $(compgen -W "${commands[*]}" -- ${cur}) )
return 0
else
COMPREPLY=()
return 0
fi
fi
fi fi
;; ;;
esac esac