diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2015-08-05 14:38:50 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2015-08-05 14:38:50 +1200 |
commit | 6bb597791f9e08ecc4a5e41fa574ebf0cc5fd724 (patch) | |
tree | 8eaae42785d78aed2bc7798b39e40044419c1cb1 /bash/bashrc.d | |
parent | Remove unnecessary trailing slash strip (diff) | |
download | dotfiles-6bb597791f9e08ecc4a5e41fa574ebf0cc5fd724.tar.gz dotfiles-6bb597791f9e08ecc4a5e41fa574ebf0cc5fd724.zip |
Pass bd options to cd
Diffstat (limited to 'bash/bashrc.d')
-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 |