aboutsummaryrefslogtreecommitdiff
path: root/sh/shrc.d/bd.sh
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-23 14:28:18 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-23 14:28:18 +1200
commit1e94aa430c0eefce9396e993272309788c6a21d0 (patch)
tree7445e71f88a44f2df461a66cd88cd5f5ee14b405 /sh/shrc.d/bd.sh
parentCorrect stderr redirection for keychain(1) check (diff)
downloaddotfiles-1e94aa430c0eefce9396e993272309788c6a21d0.tar.gz
dotfiles-1e94aa430c0eefce9396e993272309788c6a21d0.zip
Fix up ?d() functions
Count arguments in right places; return 2 on usage errors where possible; minimise subshell activity; move directory replacement functionality to its own function `rd()` rather than overloading `cd`.
Diffstat (limited to 'sh/shrc.d/bd.sh')
-rw-r--r--sh/shrc.d/bd.sh9
1 files changed, 6 insertions, 3 deletions
diff --git a/sh/shrc.d/bd.sh b/sh/shrc.d/bd.sh
index a5344ae7..81ddedb8 100644
--- a/sh/shrc.d/bd.sh
+++ b/sh/shrc.d/bd.sh
@@ -1,13 +1,16 @@
# Move back up the directory tree to the first directory matching the name
bd() {
+ # Check argument count
+ if [ "$#" -gt 1 ] ; then
+ printf >&2 'bd(): Too many arguments'
+ return 2
+ fi
+
# Set positional parameters to an option terminator and what will hopefully
# end up being a target directory
set -- "$(
- # Check there's no more than one argument
- [ "$#" -le 1 ] || exit 1
-
# The requested pattern is the first argument, defaulting to just the
# parent directory
req=${1:-..}