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,9 +31,8 @@ _dropshell_completions() {
COMPREPLY=( $(compgen -W "${servers[*]}" -- ${cur}) ) COMPREPLY=( $(compgen -W "${servers[*]}" -- ${cur}) )
return 0 return 0
;; ;;
*) run|install|backup)
# Handle completion for service names and commands after run/install/backup/etc # Handle completion for run/install/backup commands
if [[ ${COMP_CWORD} -ge 2 ]]; then
if [[ ${COMP_CWORD} -eq 2 ]]; then if [[ ${COMP_CWORD} -eq 2 ]]; then
# Second argument is server name # Second argument is server name
local servers=($(dropshell autocomplete_list_servers)) local servers=($(dropshell autocomplete_list_servers))
@ -42,17 +44,30 @@ _dropshell_completions() {
local services=($(dropshell autocomplete_list_services "$server_name")) local services=($(dropshell autocomplete_list_services "$server_name"))
COMPREPLY=( $(compgen -W "${services[*]}" -- ${cur}) ) COMPREPLY=( $(compgen -W "${services[*]}" -- ${cur}) )
return 0 return 0
elif [[ ${COMP_CWORD} -eq 4 ]]; then elif [[ ${COMP_CWORD} -eq 4 && "${COMP_WORDS[1]}" == "run" ]]; then
if [[ ${COMP_WORDS[1]} == "run" ]]; then # Fourth argument is command name - only for run command
# Fourth argument is command name - only relevant for run.
local commands=($(dropshell autocomplete_list_commands))
COMPREPLY=( $(compgen -W "${commands[*]}" -- ${cur}) ) COMPREPLY=( $(compgen -W "${commands[*]}" -- ${cur}) )
return 0 return 0
else fi
;;
*)
# if ${prev} is not in ${commands}
if [[ ! " ${commands[*]} " =~ " ${prev} " ]]; then
COMPREPLY=() COMPREPLY=()
return 0 return 0
fi fi
fi # Handle completion for template 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
fi fi
;; ;;
esac esac