diff options
author | xiubuzhe <xiubuzhe@sina.com> | 2023-10-17 00:47:21 +0800 |
---|---|---|
committer | xiubuzhe <xiubuzhe@sina.com> | 2023-10-17 00:47:21 +0800 |
commit | b89a492b6aab2245380958bac738f1de26e3c803 (patch) | |
tree | f513cd2064da8bce725c9e2ae5a3db163a10739e /etc | |
parent | 6cb42d6b8d889a832c19b6e0f58d29af78009d99 (diff) | |
download | sunhpc-b89a492b6aab2245380958bac738f1de26e3c803.tar.gz sunhpc-b89a492b6aab2245380958bac738f1de26e3c803.tar.bz2 sunhpc-b89a492b6aab2245380958bac738f1de26e3c803.zip |
fix bash-completion
Diffstat (limited to 'etc')
-rw-r--r-- | etc/bash-complete-sunhpc | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/etc/bash-complete-sunhpc b/etc/bash-complete-sunhpc new file mode 100644 index 0000000..fb272fe --- /dev/null +++ b/etc/bash-complete-sunhpc @@ -0,0 +1,55 @@ +# sunhpc(1) completion +# +# /etc/bash_completion.d/sunhpc +# + +_sunhpc_array_delete_at() +{ + eval "local ARRAY=(\"\${$1[@]}\")" + local i + local tmp=() + local lower=$2 + local upper=${3:-$lower} + + for i in "${!ARRAY[@]}"; do + if [[ "$i" -lt "$2" || "$i" -gt "${3-$2}" ]]; then + tmp=("${tmp[@]}" "${ARRAY[$i]}") + fi + done + eval "$1=(\"\${tmp[@]}\")" +} + +_sunhpc() +{ + local cur prev words cword i output + _init_completion || return + + _sunhpc_array_delete_at words $((cword+1)) ${#words[@]} + _sunhpc_array_delete_at words 0 + + for i in ${!words[@]}; do + words[i]="$(printf '%s' "${words[i]}" | xargs printf '%s\n' 2>/dev/null || true)" + done + + if [[ "$cur" =~ ^[[:space:]]+ ]]; then + cur='' + fi + + output="$(sunhpc report completion ${words[@]} 2>/dev/null)" + + if [ $? = 65 ]; then + compopt -o default + COMPREPLY=() + return 0 + fi + + #local IFS=$'\n' + COMPREPLY=( $( compgen -W '$output' -- ${cur} ) ) + + # do not append a space to words that end with = + [[ $COMPREPLY == *= ]] && compopt -o nospace + +} && +complete -F _sunhpc sunhpc + +# ex: ts=4 sw=4 et filetype=sh |