45 lines
1.2 KiB
Bash
Executable File
45 lines
1.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
_dropshell_completions() {
|
|
local cur prev opts
|
|
COMPREPLY=()
|
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
|
|
|
# List of main commands
|
|
opts="help version status servers"
|
|
|
|
# If we're completing the first argument, show all commands
|
|
if [[ ${COMP_CWORD} -eq 1 ]] ; then
|
|
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
|
return 0
|
|
fi
|
|
|
|
# Command-specific completions
|
|
case "${prev}" in
|
|
status)
|
|
# No additional completions for status
|
|
COMPREPLY=()
|
|
;;
|
|
servers)
|
|
# List servers from _server.env files
|
|
local servers_dir="/opt/dropshell/user/servers"
|
|
local servers=()
|
|
|
|
# Read all _server.env files
|
|
for server_file in "$servers_dir"/*/_server.env; do
|
|
if [ -f "$server_file" ]; then
|
|
local server_name=$(basename "$(dirname "$server_file")")
|
|
servers+=("$server_name")
|
|
fi
|
|
done
|
|
COMPREPLY=( $(compgen -W "${servers[@]}" -- ${cur}) )
|
|
return 0
|
|
;;
|
|
*)
|
|
;;
|
|
esac
|
|
}
|
|
|
|
# Register the completion function
|
|
complete -F _dropshell_completions dropshell |