Files
sunhpc/etc/bash-complete-sunhpc

56 lines
1.2 KiB
Plaintext
Raw Normal View History

2023-10-15 23:51:49 +08:00
# sunhpc(1) completion
2023-10-17 00:47:21 +08:00
#
# /etc/bash_completion.d/sunhpc
#
2023-10-15 23:51:49 +08:00
_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
2023-10-15 23:51:49 +08:00
done
eval "$1=(\"\${tmp[@]}\")"
}
2023-10-15 23:51:49 +08:00
_sunhpc()
{
local cur prev words cword i output
_init_completion || return
2023-10-15 23:51:49 +08:00
_sunhpc_array_delete_at words $((cword+1)) ${#words[@]}
_sunhpc_array_delete_at words 0
2023-10-15 23:51:49 +08:00
for i in ${!words[@]}; do
words[i]="$(printf '%s' "${words[i]}" | xargs printf '%s\n' 2>/dev/null || true)"
done
2023-10-15 23:51:49 +08:00
if [[ "$cur" =~ ^[[:space:]]+ ]]; then
cur=''
fi
2023-10-15 23:51:49 +08:00
output="$(sunhpc report completion ${words[@]} 2>/dev/null)"
if [ $? = 65 ]; then
compopt -o default
COMPREPLY=()
return 0
fi
2023-10-17 00:47:21 +08:00
#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
2023-10-15 23:51:49 +08:00
# ex: ts=4 sw=4 et filetype=sh