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.bash22
1 files changed, 22 insertions, 0 deletions
diff --git a/bash/bash_completion.d/bd.bash b/bash/bash_completion.d/bd.bash
new file mode 100644
index 00000000..68589dff
--- /dev/null
+++ b/bash/bash_completion.d/bd.bash
@@ -0,0 +1,22 @@
+# Completion setup for bd
+_bd() {
+
+ # Only makes sense for the first argument
+ ((COMP_CWORD == 1)) || return 1
+
+ # Build a list of dirnames in $PWD
+ local -a dirnames
+ IFS=/ read -d '' -a dirnames < <(printf '%s\0' "${PWD#/}")
+
+ # Remove the last element in the array (the current directory)
+ ((${#dirnames[@]})) || return 1
+ dirnames=("${dirnames[@]:0:"$((${#dirnames[@]}-1))"}")
+
+ # Add the matching dirnames to the reply
+ local dirname
+ for dirname in "${dirnames[@]}" ; do
+ [[ $dirname == "${COMP_WORDS[COMP_CWORD]}"* ]] || continue
+ COMPREPLY=("${COMPREPLY[@]}" "$(printf %q "$dirname")")
+ done
+}
+complete -F _bd bd