diff options
Diffstat (limited to 'bash/bashrc.d/bd.bash')
-rw-r--r-- | bash/bashrc.d/bd.bash | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/bash/bashrc.d/bd.bash b/bash/bashrc.d/bd.bash index 10c9161d..9ea0e3ca 100644 --- a/bash/bashrc.d/bd.bash +++ b/bash/bashrc.d/bd.bash @@ -1,7 +1,27 @@ # Move back up the directory tree to the first directory matching the name bd() { - # We should have zero or one arguments, bail if there are more + # For completeness' sake, we'll pass any options to cd + local arg + local -a opts + for arg ; do + case $arg in + --) + shift + break + ;; + -*) + shift + opts=("${opts[@]}" "$arg") + ;; + *) + break + ;; + esac + done + + # We should have zero or one arguments after all that, bail if there are + # more if (($# > 1)) ; then printf 'bash: %s: usage: %s [PATH]\n' \ "$FUNCNAME" "$FUNCNAME" >&2 @@ -55,7 +75,7 @@ bd() { esac # Try to change into the determined directory - builtin cd -- "$dir" + builtin cd "${opts[@]}" -- "$dir" } # Completion setup for bd |