aboutsummaryrefslogtreecommitdiff
path: root/bash/bash_completion.d/sd.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/sd.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/sd.bash')
-rw-r--r--bash/bash_completion.d/sd.bash60
1 files changed, 20 insertions, 40 deletions
diff --git a/bash/bash_completion.d/sd.bash b/bash/bash_completion.d/sd.bash
index e7e82f80..66dea73b 100644
--- a/bash/bash_completion.d/sd.bash
+++ b/bash/bash_completion.d/sd.bash
@@ -1,52 +1,32 @@
+# 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 function for sd; any sibling directories, excluding the self
_sd() {
- # Only makes sense for the first argument
- ((COMP_CWORD == 1)) || return
-
- # Current directory can't be root directory
- case $PWD in
- /) return 1 ;;
- esac
-
# Build list of matching sibling directories
- local dirname
- while IFS= read -rd '' dirname ; do
- [[ -n $dirname ]] || continue
- COMPREPLY[${#COMPREPLY[@]}]=$dirname
+ local ci comp
+ while IFS= read -d / -r comp ; do
+ COMPREPLY[ci++]=$comp
done < <(
- # Set options to glob correctly
+ # Make globs expand appropriately
shopt -s dotglob nullglob
-
- # Make globbing case-insensitive if appropriate
- while read -r _ setting ; do
- case $setting in
- ('completion-ignore-case on')
- shopt -s nocaseglob
- break
- ;;
- esac
- done < <(bind -v)
-
- # Collect directory names, strip leading ../ and trailing /
- local -a dirnames
- dirnames=(../"${COMP_WORDS[COMP_CWORD]}"*/)
- dirnames=("${dirnames[@]#../}")
- dirnames=("${dirnames[@]%/}")
-
- # Iterate again, but exclude the current directory this time
- local -a sibs
- local dirname
- for dirname in "${dirnames[@]}" ; do
- case $dirname in
- "${PWD##*/}") ;;
- *) sibs[${#sibs[@]}]=$dirname ;;
+ if _completion_ignore_case ; then
+ shopt -s nocaseglob
+ fi
+
+ # Print matching sibling dirs that are not the current dir
+ for sibling in ../"$2"*/ ; do
+ sibling=${sibling%/}
+ sibling=${sibling#../}
+ case $sibling in
+ ("${PWD##*/}") ;;
+ (*) printf '%q/' "${sibling}" ;;
esac
done
-
- # Print quoted sibling directories, null-delimited
- printf '%q\0' "${sibs[@]}"
)
}
complete -F _sd sd