From 8e20116f74753fa07d2f15b915aa5a700fd1f53c Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 8 Jan 2017 02:05:16 +1300 Subject: Adjust subshell logic in md() --- sh/shrc.d/md.sh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/sh/shrc.d/md.sh b/sh/shrc.d/md.sh index 6fd3d7ca..a7134931 100644 --- a/sh/shrc.d/md.sh +++ b/sh/shrc.d/md.sh @@ -7,11 +7,14 @@ md() { return 2 fi - # If first arg unset or empty, assume the user means the current dir - [ -n "$1" ] || set -- "$PWD" - - # Jump to the dir and emit PWD from a subshell to get an absolute path - set -- "$(cd -- "$1" && printf %s "$PWD")" + # If argument given, change to it in subshell to get absolute path. + # If not, use current working directory. + if [ -n "$1" ] ; then + set -- "$(cd -- "$1" && printf '%s/' "$PWD")" + set -- "${1%%/}" + else + set -- "$PWD" + fi # If that turned up empty, we have failed; the cd call probably threw an # error for us too -- cgit v1.2.3