Files
sshyp/extra/sshyp-completion.bash
T
RandyTheSilly 0920dcf004 Fixed completions not generating
Former-commit-id: 3f8c64047f12456fd3c1ce8243293beb323912a2 [formerly 915a17b8e9]
Former-commit-id: 0e322f3cda6e75f2db8b9e649028fccbf1ae09ad
2022-09-05 14:29:43 -04:00

51 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
_path_gen() {
local sshyp_path="$HOME/.local/share/sshyp"
local sshyp_path_length="$(("${#sshyp_path}" + 1))"
readarray -t full_paths < <(find "$sshyp_path" -type f -exec ls {} \;)
for path in "${full_paths[@]}"; do
trimmed_path=$(echo $path | sed 's/.\{4\}$//' | cut -c"$sshyp_path_length"-)
trimmed_path=$(echo ${trimmed_path// /\\ })
trimmed_paths+=("$trimmed_path")
done
} &&
# from this point, this completions script was partially generated by
# completely (https://github.com/dannyben/completely)
_sshyp_completions() {
if [ "${#COMP_WORDS[@]}" -gt "4" ]; then
return
fi
local cur=${COMP_WORDS[COMP_CWORD]}
local compline="${COMP_WORDS[@]:1:$COMP_CWORD-1}"
case "$compline" in
'add password'* | 'add -p'* | 'add note'* | 'add -n'* | 'add folder'*| 'add -f'* | 'edit relocate'* | 'edit -r'* | 'edit username'* | 'edit -u'* | 'edit password'* | 'edit -p'* | 'edit url'* | 'edit -l'* | 'edit note'* | 'edit -n'* | 'copy username'* | 'copy -u'* | 'copy password'* | 'copy -p'* | 'copy note'* | 'copy -n'* | 'copy url'* | 'copy -l'* | 'gen update'* | 'gen -u'*)
while read; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(printf "'%s' " "${trimmed_paths[@]}")" -- "$cur" )
;;
'edit'*)
while read; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "relocate username password note url" -- "$cur" )
;;
'copy'*)
while read; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "username password url note" -- "$cur" )
;;
'add'*)
while read; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "password note folder" -- "$cur" )
;;
'gen'*)
while read; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "update" -- "$cur" )
;;
*)
while read; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "help version tweak add gen edit copy shear sync $(printf "'%s' " "${trimmed_paths[@]}")" -- "$cur" )
;;
esac
} &&
_path_gen && complete -F _sshyp_completions sshyp