aboutsummaryrefslogtreecommitdiff
path: root/bash/bash_completion.d/sd.bash
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-12-01 02:48:02 +1300
committerTom Ryder <tom@sanctum.geek.nz>2018-12-01 02:48:02 +1300
commit32ca9ad0fa8d7691022a44989c1832672fb51548 (patch)
tree9ef3779f21a9f2c500d62ca3a31ec37aec930af8 /bash/bash_completion.d/sd.bash
parentMerge branch 'release/v2.5.0' (diff)
parentBump VERSION (diff)
downloaddotfiles-32ca9ad0fa8d7691022a44989c1832672fb51548.tar.gz
dotfiles-32ca9ad0fa8d7691022a44989c1832672fb51548.zip
Merge branch 'release/v2.6.0'v2.6.0
* release/v2.6.0: (26 commits) Bump VERSION Overhaul and expand abook address Bash completion Restore correct completion function for mutt(1) Use simpler keyword complete for `path` subcommand Break up a couple of long lines Remove unneeded local array declaration Remove unneeded empty result short circuit Remove redundant error code in short circuits Adjust loop short circuits and pattern matches Remove unneeded quoting in case statement Remove needless line breaks from git completion Use inverting exclam mark outside conditional Remove stray comment no longer applicable Use array+=() syntax in two Bash completion files Remove null-result guard from completion gens Use simpler method of no case completion check Overhaul `keep` completion Simplify an array operation in `bd` completion Overhaul text filename generation Use full `if` condition for SSH hostname comp src ...
Diffstat (limited to 'bash/bash_completion.d/sd.bash')
-rw-r--r--bash/bash_completion.d/sd.bash39
1 files changed, 16 insertions, 23 deletions
diff --git a/bash/bash_completion.d/sd.bash b/bash/bash_completion.d/sd.bash
index 578a69fd..e7e82f80 100644
--- a/bash/bash_completion.d/sd.bash
+++ b/bash/bash_completion.d/sd.bash
@@ -2,10 +2,12 @@
_sd() {
# Only makes sense for the first argument
- ((COMP_CWORD == 1)) || return 1
+ ((COMP_CWORD == 1)) || return
# Current directory can't be root directory
- [[ $PWD != / ]] || return 1
+ case $PWD in
+ /) return 1 ;;
+ esac
# Build list of matching sibling directories
local dirname
@@ -17,17 +19,12 @@ _sd() {
# Set options to glob correctly
shopt -s dotglob nullglob
- # Make globbing case-insensitive if appropriate; is there a cleaner way
- # to find this value?
- while read -r _ option value ; do
- case $option in
- (completion-ignore-case)
- case $value in
- (on)
- shopt -s nocaseglob
- break
- ;;
- esac
+ # 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)
@@ -42,18 +39,14 @@ _sd() {
local -a sibs
local dirname
for dirname in "${dirnames[@]}" ; do
- [[ $dirname != "${PWD##*/}" ]] || continue
- sibs[${#sibs[@]}]=$dirname
+ case $dirname in
+ "${PWD##*/}") ;;
+ *) sibs[${#sibs[@]}]=$dirname ;;
+ esac
done
- # Print quoted sibs, null-delimited, if there was at least one;
- # otherwise, just print a null character to stop this hanging in Bash
- # 4.4
- if ((${#sibs[@]})) ; then
- printf '%q\0' "${sibs[@]}"
- else
- printf '\0'
- fi
+ # Print quoted sibling directories, null-delimited
+ printf '%q\0' "${sibs[@]}"
)
}
complete -F _sd sd