diff options
Diffstat (limited to 'bash')
-rw-r--r-- | bash/bashrc.d/vis.bash | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/bash/bashrc.d/vis.bash b/bash/bashrc.d/vis.bash new file mode 100644 index 00000000..23c1199d --- /dev/null +++ b/bash/bashrc.d/vis.bash @@ -0,0 +1,23 @@ +# 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 -d '' -r 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 + [[ -x $file ]] || continue + executables=("${executables[@]}" "${file##*/}") + done + ((${#executables[@]})) || exit 1 + printf '%q\0' "${executables[@]}" + ) +} +complete -F _vis vis + |