diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-08-23 14:28:18 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-08-23 14:28:18 +1200 |
commit | 1e94aa430c0eefce9396e993272309788c6a21d0 (patch) | |
tree | 7445e71f88a44f2df461a66cd88cd5f5ee14b405 /sh/shrc.d/sd.sh | |
parent | Correct stderr redirection for keychain(1) check (diff) | |
download | dotfiles-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/sd.sh')
-rw-r--r-- | sh/shrc.d/sd.sh | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/sh/shrc.d/sd.sh b/sh/shrc.d/sd.sh index 80ae7c12..c5b1106a 100644 --- a/sh/shrc.d/sd.sh +++ b/sh/shrc.d/sd.sh @@ -1,6 +1,6 @@ # -# sd -- sibling/switch directory -- Shortcut to switch to another directory -# with the same parent, i.e. a sibling of the current directory. +# Shortcut to switch to another directory with the same parent, i.e. a sibling +# of the current directory. # # $ pwd # /home/you @@ -34,14 +34,14 @@ # sd() { + # Check argument count + if [ "$#" -gt 1 ] ; then + printf >&2 'sd(): Too many arguments\n' + return 2 + fi + set -- "$( - # Check argument count - if [ "$#" -gt 1 ] ; then - printf >&2 'sd(): Too many arguments\n' - exit 1 - fi - # Set the positional parameters to either the requested directory, or # all siblings of the current directory if no request spec=$1 |