From 1e94aa430c0eefce9396e993272309788c6a21d0 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 23 Aug 2016 14:28:18 +1200 Subject: 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`. --- sh/shrc.d/sd.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'sh/shrc.d/sd.sh') 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 -- cgit v1.2.3