From 6bb597791f9e08ecc4a5e41fa574ebf0cc5fd724 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 5 Aug 2015 14:38:50 +1200 Subject: Pass bd options to cd --- bash/bashrc.d/bd.bash | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'bash/bashrc.d/bd.bash') 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 -- cgit v1.2.3