aboutsummaryrefslogtreecommitdiff
path: root/bash/bash_completion.d/mex.bash
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-12-02 18:03:15 +1300
committerTom Ryder <tom@sanctum.geek.nz>2018-12-02 18:03:15 +1300
commit693fc13bb98b17938f2208fbadaec1996822fc5e (patch)
tree4a9cc6179f521528c663c8ab5f3bbc59dc57eaa0 /bash/bash_completion.d/mex.bash
parentMerge branch 'release/v2.6.0' (diff)
parentBump VERSION (diff)
downloaddotfiles-9b89a290b863e960f8ebe72812a98cc7fe49c262.tar.gz (sig)
dotfiles-9b89a290b863e960f8ebe72812a98cc7fe49c262.zip
Merge branch 'release/v2.7.0'v2.7.0
* release/v2.7.0: (22 commits) Bump VERSION Make separate install-bash-completion target Overhaul Bash completion scripts Reduce ud() completion to just dirnames Upgrade uncap_ex.vim plugin to v0.3.0 Apply syntax fixes to last _text_filenames specs Rearrange _text_filenames completion a little Remove prompt() completion Throw away chgrp completion Throw away Git Bash completion Remove mysql(1) completion Use consistent temp names for shell subfile vars Overhaul pass(1) completion Adjust syntax of two more completion loads Remove ftp(1) completion Remove `kill` completion Use the positional parameter aliases for words Overhaul bd() completion again Remove unneeded -q option to shopt -s commands Don't include dotfiles in keep() names ...
Diffstat (limited to 'bash/bash_completion.d/mex.bash')
-rw-r--r--bash/bash_completion.d/mex.bash60
1 files changed, 49 insertions, 11 deletions
diff --git a/bash/bash_completion.d/mex.bash b/bash/bash_completion.d/mex.bash
index bc3d2c7b..b1e0e1a7 100644
--- a/bash/bash_completion.d/mex.bash
+++ b/bash/bash_completion.d/mex.bash
@@ -1,16 +1,54 @@
+# Load _completion_ignore_case helper function
+if ! declare -F _completion_ignore_case >/dev/null ; then
+ source "$HOME"/.bash_completion.d/_completion_ignore_case.bash
+fi
+
# Completion setup for mex(1df), completing non-executable files in $PATH
_mex() {
- local -a path
- IFS=: read -ra path < <(printf '%s\n' "$PATH")
- local dir name
- for dir in "${path[@]}" ; do
- [[ -d $dir ]] || continue
- for name in "$dir"/* ; do
- [[ -e $name ]] || continue
- ! [[ -d $name ]] || continue
- ! [[ -x $name ]] || continue
- COMPREPLY[${#COMPREPLY[@]}]=${name##*/}
+
+ # Iterate through completions produced by subshell
+ local ci comp
+ while IFS= read -d / -r comp ; do
+ COMPREPLY[ci++]=$comp
+ done < <(
+
+ # Make globs expand appropriately
+ shopt -u dotglob
+ shopt -s nullglob
+ if _completion_ignore_case ; then
+ shopt -s nocaseglob
+ fi
+
+ # Break $PATH up into an array
+ declare -a paths
+ IFS=: read -a paths -r \
+ < <(printf '%s\n' "$PATH")
+
+ # Iterate through each path, collecting non-executable filenames
+ for path in "${paths[@]}" ; do
+ for name in "$path"/"$2"* ; do
+
+ # Skip anything that is not a plain file
+ [[ -f $name ]] || continue
+ # Skip files that are already executable
+ ! [[ -x $name ]] || continue
+
+ # Chop off leading path
+ name=${name##*/}
+
+ # Skip certain filename patterns
+ case $name in
+ # DOS batch file
+ (*.bat) continue ;;
+ # README files
+ (README*) continue ;;
+ esac
+
+ # Print name of the file
+ printf '%s/' "${name##*/}"
+
+ done
done
- done
+ )
}
complete -F _mex mex