summaryrefslogtreecommitdiffstats
path: root/scripts/completions/aichat.bash
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-04-13 19:50:10 +0800
committerGitHub <noreply@github.com>2024-04-13 19:50:10 +0800
commit1c3e81afe9f63fb47303384a82c7239458166f52 (patch)
tree85d89be89fe9347cf4e8b8cbf30993e5d85c38f8 /scripts/completions/aichat.bash
parent568e9a06db7189a28f9346802356b3fd4bdf921b (diff)
downloadaichat-1c3e81afe9f63fb47303384a82c7239458166f52.tar.gz
feat: add completion scripts (#411)
Diffstat (limited to 'scripts/completions/aichat.bash')
-rw-r--r--scripts/completions/aichat.bash93
1 files changed, 93 insertions, 0 deletions
diff --git a/scripts/completions/aichat.bash b/scripts/completions/aichat.bash
new file mode 100644
index 0000000..0d72747
--- /dev/null
+++ b/scripts/completions/aichat.bash
@@ -0,0 +1,93 @@
+_aichat() {
+ local i cur prev opts cmd
+ COMPREPLY=()
+ cur="${COMP_WORDS[COMP_CWORD]}"
+ prev="${COMP_WORDS[COMP_CWORD-1]}"
+ cmd=""
+ opts=""
+
+ for i in ${COMP_WORDS[@]}
+ do
+ case "${cmd},${i}" in
+ ",$1")
+ cmd="aichat"
+ ;;
+ *)
+ ;;
+ esac
+ done
+
+ case "${cmd}" in
+ aichat)
+ opts="-m -r -s -e -c -f -H -S -w -h -V --model --role --session --save-session --execute --code --file --no-highlight --no-stream --wrap --light-theme --dry-run --info --list-models --list-roles --list-sessions --help --version"
+ if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
+ COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
+ return 0
+ fi
+
+ # hacking -m or --model completion value that contains colon
+ if [ "$cur" == ":" ] || [ "$prev" == ":" ]; then
+ local option client
+ if [ "$cur" = ":" ]; then
+ option="${COMP_WORDS[COMP_CWORD-2]}"
+ client="$prev"
+ else
+ option="${COMP_WORDS[COMP_CWORD-3]}"
+ client="${COMP_WORDS[COMP_CWORD-2]}"
+ fi
+ if [ "$option" == "-m" ] || [ "$flag" == "--model" ]; then
+ if [ "$cur" == ":" ]; then
+ cur=""
+ fi
+ COMPREPLY=($(compgen -W "$("$1" --list-models | sed -n '/'"${client}"'/ s/'"${client%:*}"'://p')" -- "${cur}"))
+ return 0
+ fi
+ fi
+
+ case "${prev}" in
+ -m|--model)
+ COMPREPLY=($(compgen -W "$("$1" --list-models)" -- "${cur}"))
+ return 0
+ ;;
+ -r|--role)
+ COMPREPLY=($(compgen -W "$("$1" --list-roles)" -- "${cur}"))
+ return 0
+ ;;
+ -s|--session)
+ COMPREPLY=($(compgen -W "$("$1" --list-sessions)" -- "${cur}"))
+ return 0
+ ;;
+ -f|--file)
+ local oldifs
+ if [[ -v IFS ]]; then
+ oldifs="$IFS"
+ fi
+ IFS=$'\n'
+ COMPREPLY=($(compgen -f "${cur}"))
+ if [[ -v oldifs ]]; then
+ IFS="$oldifs"
+ fi
+ if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
+ compopt -o filenames
+ fi
+ return 0
+ ;;
+ -w|--wrap)
+ COMPREPLY=($(compgen -f "${cur}"))
+ return 0
+ ;;
+ *)
+ COMPREPLY=()
+ ;;
+ esac
+ COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
+ return 0
+ ;;
+ esac
+}
+
+if [[ "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 || "${BASH_VERSINFO[0]}" -gt 4 ]]; then
+ complete -F _aichat -o nosort -o bashdefault -o default aichat
+else
+ complete -F _aichat -o bashdefault -o default aichat
+fi