aboutsummaryrefslogtreecommitdiff
path: root/bash/bash_completion.d/bd.bash
diff options
context:
space:
mode:
Diffstat (limited to 'bash/bash_completion.d/bd.bash')
-rw-r--r--bash/bash_completion.d/bd.bash39
1 files changed, 16 insertions, 23 deletions
diff --git a/bash/bash_completion.d/bd.bash b/bash/bash_completion.d/bd.bash
index 59f4718f..09134e6a 100644
--- a/bash/bash_completion.d/bd.bash
+++ b/bash/bash_completion.d/bd.bash
@@ -1,15 +1,15 @@
+# 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 bd()
_bd() {
- # The function accepts only one argument, so it doesn't make sense to
- # complete anywhere else
- ((COMP_CWORD == 1)) || return
-
- # Iterate through slash-delimited matching parent path elements, as piped
- # in by the subshell
- local ci word
- while IFS= read -rd/ word ; do
- COMPREPLY[ci++]=$word
+ # Iterate through completions produced by subshell
+ local ci comp
+ while IFS= read -d / -r comp ; do
+ COMPREPLY[ci++]=$comp
done < <(
# Build an array of path nodes, leaf to root
@@ -22,29 +22,22 @@ _bd() {
done
# Continue if we have at least two nodes, counting the leaf
- ((${#nodes} > 1)) || return
+ ((${#nodes[@]} > 1)) || return
- # Shift off the leaf, since it's not meaningful to go "back to" the
+ # Shift off the leaf, since it is not meaningful to go "back to" the
# current directory
nodes=("${nodes[@]:1}")
- # Turn on case-insensitive matching, if configured to do so
- while read -r _ setting ; do
- case $setting in
- ('completion-ignore-case on')
- shopt -s nocasematch 2>/dev/null
- break
- ;;
- esac
- done < <(bind -v)
+ # Make matching behave appropriately
+ if _completion_ignore_case ; then
+ shopt -s nocasematch 2>/dev/null
+ fi
# Iterate through the nodes and print the ones that match the word
# being completed, with a trailing slash as terminator
for node in "${nodes[@]}" ; do
case $node in
- ("$2"*)
- printf '%s/' "$node"
- ;;
+ ("$2"*) printf '%s/' "$node" ;;
esac
done
)