diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-05-26 17:48:49 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-05-26 17:48:49 +1200 |
commit | cd114eec94fd07e831ef6c70b7732408d0a59e90 (patch) | |
tree | 6dadb976a2a03fa4db4a5ef36c1a209b2152a6d7 /sh | |
parent | Reimplement sd() without subshell (diff) | |
download | dotfiles-cd114eec94fd07e831ef6c70b7732408d0a59e90.tar.gz dotfiles-cd114eec94fd07e831ef6c70b7732408d0a59e90.zip |
Correct default behaviour for bd() with no args
Diffstat (limited to 'sh')
-rw-r--r-- | sh/shrc.d/bd.sh | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/sh/shrc.d/bd.sh b/sh/shrc.d/bd.sh index 2dc21173..7901e115 100644 --- a/sh/shrc.d/bd.sh +++ b/sh/shrc.d/bd.sh @@ -1,14 +1,17 @@ # 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\n' - return 2 - fi + # Check argument count; default to ".." + case $# in + 0) set -- .. ;; + 1) ;; + *) + printf >&2 'bd(): Too many arguments\n' + return 2 + esac # Look at argument given; default to going up one level - case ${1:-..} in + case $1 in # If it has a leading slash or is . or .., don't touch the arguments /*|.|..) ;; |