aboutsummaryrefslogtreecommitdiff
path: root/sh/shrc.d/md.sh
diff options
context:
space:
mode:
Diffstat (limited to 'sh/shrc.d/md.sh')
-rw-r--r--sh/shrc.d/md.sh13
1 files 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