diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2015-11-13 13:26:45 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2015-11-13 13:26:45 +1300 |
commit | e41e349d4b9b8aade8e90d3edc1e794c47dcf69b (patch) | |
tree | 8ffe376f9d47dc371c382fa81e1b59815b1c02f8 /bash/bashrc.d/vis.bash | |
parent | Correct man page summary (diff) | |
download | dotfiles-e41e349d4b9b8aade8e90d3edc1e794c47dcf69b.tar.gz dotfiles-e41e349d4b9b8aade8e90d3edc1e794c47dcf69b.zip |
Completion for vis(1)
Diffstat (limited to 'bash/bashrc.d/vis.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 + |