aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2015-11-13 13:26:45 +1300
committerTom Ryder <tom@sanctum.geek.nz>2015-11-13 13:26:45 +1300
commite41e349d4b9b8aade8e90d3edc1e794c47dcf69b (patch)
tree8ffe376f9d47dc371c382fa81e1b59815b1c02f8
parentCorrect man page summary (diff)
downloaddotfiles-e41e349d4b9b8aade8e90d3edc1e794c47dcf69b.tar.gz
dotfiles-e41e349d4b9b8aade8e90d3edc1e794c47dcf69b.zip
Completion for vis(1)
-rw-r--r--bash/bashrc.d/vis.bash23
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
+