aboutsummaryrefslogtreecommitdiff
path: root/sh/shrc.d/pd.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/pd.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/pd.sh')
-rw-r--r--sh/shrc.d/pd.sh12
1 files changed, 6 insertions, 6 deletions
diff --git a/sh/shrc.d/pd.sh b/sh/shrc.d/pd.sh
index c022b1e8..de4ea23b 100644
--- a/sh/shrc.d/pd.sh
+++ b/sh/shrc.d/pd.sh
@@ -4,16 +4,16 @@
# argument, this just shifts up a directory, i.e. `cd ..`
pd() {
+ # Check argument count
+ if [ "$#" -gt 1 ] ; then
+ printf >&2 'pd(): Too many arguments\n'
+ return 2
+ fi
+
# Change the positional parameters from the target to its containing
# directory
set -- "$(
- # Check argument count
- if [ "$#" -gt 1 ] ; then
- printf >&2 'pd(): Too many arguments\n'
- exit 2
- fi
-
# Figure out target dirname
dirname=${1:-..}
dirname=${dirname%/}