diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-07-30 01:17:09 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-07-30 02:09:30 +1200 |
commit | 4cbbd121c012b3962f12fdff0f1820c3b8636a44 (patch) | |
tree | 00149270df365ed0b7a1b9e9f4922fe7d5a80eb3 /bash/bash_completion.d/vis.bash | |
parent | Change ca from Bash func to sh script (diff) | |
download | dotfiles-4cbbd121c012b3962f12fdff0f1820c3b8636a44.tar.gz dotfiles-4cbbd121c012b3962f12fdff0f1820c3b8636a44.zip |
Move bash completion setup into separate dir
Diffstat (limited to 'bash/bash_completion.d/vis.bash')
-rw-r--r-- | bash/bash_completion.d/vis.bash | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/bash/bash_completion.d/vis.bash b/bash/bash_completion.d/vis.bash new file mode 100644 index 00000000..f84cb702 --- /dev/null +++ b/bash/bash_completion.d/vis.bash @@ -0,0 +1,22 @@ +# Complete args to vis(1) with existing executables in $VISPATH, defaulting to +# ~/.local/bin +_vis() { + local vispath + vispath=${VISPATH:-"$HOME"/.local/bin} + [[ -d $vispath ]] || return + while IFS= read -rd '' executable ; do + COMPREPLY[${#COMPREPLY[@]}]=$executable + done < <( + shopt -s dotglob nullglob + declare -a files + files=("${VISPATH:-"$HOME"/.local/bin}"/"${COMP_WORDS[COMP_CWORD]}"*) + declare -a executables + for file in "${files[@]}" ; do + [[ -f $file && -x $file ]] || continue + executables[${#executables[@]}]=${file##*/} + done + ((${#executables[@]})) || exit 1 + printf '%q\0' "${executables[@]}" + ) +} +complete -F _vis vis |