aboutsummaryrefslogtreecommitdiff
path: root/bash/bash_completion.d/find.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/find.bash
parentMerge branch 'release/v2.6.0' (diff)
parentBump VERSION (diff)
downloaddotfiles-693fc13bb98b17938f2208fbadaec1996822fc5e.tar.gz
dotfiles-693fc13bb98b17938f2208fbadaec1996822fc5e.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/find.bash')
-rw-r--r--bash/bash_completion.d/find.bash70
1 files changed, 18 insertions, 52 deletions
diff --git a/bash/bash_completion.d/find.bash b/bash/bash_completion.d/find.bash
index 7e2ae9c3..f87029e7 100644
--- a/bash/bash_completion.d/find.bash
+++ b/bash/bash_completion.d/find.bash
@@ -1,42 +1,14 @@
-# compopt requires Bash >=4.0, and I don't think it's worth making a compatible
-# version
-((BASH_VERSINFO[0] >= 4)) || return
-
# Semi-intelligent completion for find(1); nothing too crazy
_find() {
- # Backtrack through words so far; if none of them look like options, we're
- # still completing directory names
- local i
- local -i opts
- for ((i = COMP_CWORD; i >= 0; i--)) ; do
- case ${COMP_WORDS[i]} in
- -*)
- opts=1
- break
- ;;
- esac
- done
- if ! ((opts)) ; then
- compopt -o dirnames
- return
- fi
-
- # For the rest of this, if we end up with an empty COMPREPLY, we should
- # just do what Bash would normally do
- compopt -o bashdefault -o default
-
- # Iterate through whatever the subshell gives us; don't add blank items, though
- local item
- while read -r item ; do
- [[ -n $item ]] || continue
- COMPREPLY+=("$item")
+ # Iterate through completions produced by subshell
+ local ci comp
+ while IFS= read -r comp ; do
+ COMPREPLY[ci++]=$comp
done < <(
- # If the word being completed starts with a dash, just complete it as
- # an option; crude, but simple, and will be right the vast majority of
- # the time
- case ${COMP_WORDS[COMP_CWORD]} in
+ # Complete POSIX-specified options
+ case $2 in
(-*)
compgen -W '
-atime
@@ -58,34 +30,28 @@ _find() {
-type
-user
-xdev
- ' -- "${COMP_WORDS[COMP_CWORD]}"
+ ' -- "$2"
+ return
;;
esac
- # Otherwise, look at the word *before* this one to figure out what to
+ # Look at the word *before* this one to figure out what to
# complete
- case ${COMP_WORDS[COMP_CWORD-1]} in
+ case $3 in
# Args to -exec and -execdir should be commands
- (-exec|-execdir)
- compgen -A command -- "${COMP_WORDS[COMP_CWORD]}"
- ;;
-
- # Args to -group should complete group names
- (-group)
- compgen -A group -- "${COMP_WORDS[COMP_CWORD]}"
- ;;
+ (-exec|-execdir) compgen -A command -- "$2" ;;
# Legal POSIX flags for -type
- (-type)
- compgen -W 'b c d f l p s' -- "${COMP_WORDS[COMP_CWORD]}"
- ;;
+ (-type) compgen -W 'b c d f l p s' -- "$2" ;;
+
+ # Args to -group should complete group names
+ (-group) compgen -A group -- "$2" ;;
# Args to -user should complete usernames
- (-user)
- compgen -A user -- "${COMP_WORDS[COMP_CWORD]}"
- ;;
+ (-user) compgen -A user -- "$2" ;;
+
esac
)
}
-complete -F _find find
+complete -F _find -o bashdefault -o default find