This commit is contained in:
abrown38 committed 2026-09-30 17:11:22 +00:00
1 parent 4f0886b6cd
commit 02017d470f
16 files changed
+2665 -84

No files matched your search

+75 -5
View File
@@ -32,6 +32,33 @@ _terractl_instances() {
fi
}
# Remotes this user added with 'terractl remote add'
_terractl_remotes() {
local f=${TERRACTL_CONFIG_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/terractl}/remotes.json
[[ -r $f ]] || return 0
python3 -c 'import json, sys; print("\n".join(json.load(open(sys.argv[1]))["remotes"]))' "$f" 2>/dev/null
}
# Instance names on a remote. This asks its daemon, so it can take a moment.
_terractl_remote_instances() {
timeout 5 terractl --host "$1" info 2>/dev/null </dev/null | sed -n 's/^instance=//p'
}
# [<remote>:]<name> for copy and move
_terractl_places() {
if [[ $cur == -* ]]; then
_terractl_reply "--with-server"
elif [[ $cur == *:* ]]; then
mapfile -t COMPREPLY < <(compgen -P "${cur%:*}:" -W "$(_terractl_remote_instances "${cur%:*}")" -- "${cur##*:}")
else
mapfile -t COMPREPLY < <(compgen -W "$(_terractl_instances) $(_terractl_remotes | sed 's/$/:/')" -- "$cur")
# After "<remote>:" comes an instance name, not a space
if [[ ${#COMPREPLY[@]} -eq 1 && ${COMPREPLY[0]} == *: ]]; then compopt -o nospace 2>/dev/null; fi
fi
# Readline sees only the part after the last ':'
if declare -F __ltrim_colon_completions >/dev/null 2>&1; then __ltrim_colon_completions "$cur"; fi
}
# Mods installed in an instance (*.tmod files), or enabled ones (enabled.json)
_terractl_mods() {
local mdir f
@@ -70,16 +97,33 @@ _terractl() {
if declare -F _init_completion >/dev/null 2>&1; then
# shellcheck disable=SC2034 # prev is set by _init_completion but not needed here
local prev
_init_completion || return
# -n : keeps "<remote>:<name>" (copy, move) in one word
_init_completion -n : || return
else
cur=${COMP_WORDS[COMP_CWORD]}
words=("${COMP_WORDS[@]}")
cword=$COMP_CWORD
fi
local commands="new list attach cmd mods reinstall delete export import prepare run --help --version"
local commands="new list info start stop restart enable disable attach watch cmd mods reinstall delete rename export import"
local console="save say playing kick ban motd password time dawn noon dusk midnight settle seed version maxplayers port clear help"
# terractl --host <remote> <command> ...: the same as on this host, except
# that instance names come from the remote and mod names aren't offered
local host=""
if [[ ${words[1]:-} == --host || ${words[1]:-} == -H ]]; then
if (( cword == 2 )); then
_terractl_reply "$(_terractl_remotes)"
return
fi
host=${words[2]}
words=("${words[0]}" "${words[@]:3}")
cword=$((cword - 2))
commands+=" --help --version"
else
commands+=" copy move remote daemon prepare run --host --help --version"
fi
if (( cword == 1 )); then
_terractl_reply "$commands"
return
@@ -97,10 +141,31 @@ _terractl() {
# import <new name> <file.tar.gz>: the name is new, so nothing to offer
if (( cword == 3 )); then _terractl_files tar.gz; fi
return ;;
copy|move)
_terractl_places
return ;;
remote)
if (( cword == 2 )); then
_terractl_reply "add list remove"
elif (( cword == 3 )) && [[ ${words[2]} == remove ]]; then
_terractl_reply "$(_terractl_remotes)"
fi
return ;;
daemon)
if (( cword == 2 )); then
_terractl_reply "enable disable status trust"
elif (( cword == 3 )) && [[ ${words[2]} == trust ]]; then
_terractl_reply "add list remove"
fi
return ;;
esac
if (( cword == 2 )); then
_terractl_reply "$(_terractl_instances)"
if [[ -n $host ]]; then
_terractl_reply "$(_terractl_remote_instances "$host")"
else
_terractl_reply "$(_terractl_instances)"
fi
return
fi
@@ -110,6 +175,11 @@ _terractl() {
if (( cword == 3 )); then _terractl_reply "$console"; fi ;;
reinstall)
if (( cword == 3 )); then _terractl_reply "--clean"; fi ;;
enable|disable)
if (( cword == 3 )); then _terractl_reply "--now"; fi ;;
watch)
# the number after -n is free-form
if [[ $cur == -* ]]; then _terractl_reply "-n -q"; fi ;;
delete)
_terractl_reply "-y --yes --no-backup" ;;
export)
@@ -124,9 +194,9 @@ _terractl() {
# .tmod files and folders (e.g. the Windows export folder)
_terractl_files tmod ;;
enable|remove)
_terractl_reply "$(_terractl_mods "$instance" installed)" ;;
if [[ -z $host ]]; then _terractl_reply "$(_terractl_mods "$instance" installed)"; fi ;;
disable)
_terractl_reply "$(_terractl_mods "$instance" enabled)" ;;
if [[ -z $host ]]; then _terractl_reply "$(_terractl_mods "$instance" enabled)"; fi ;;
esac ;;
esac
}