From 5c8662d4360429599de579ccd8b1f8c1b4de82c3 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 5 Jan 2017 21:12:51 +1300 Subject: Resolve an md() issue Made the whole thing tidier, actually --- sh/shrc.d/md.sh | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'sh') diff --git a/sh/shrc.d/md.sh b/sh/shrc.d/md.sh index 7085d258..6fd3d7ca 100644 --- a/sh/shrc.d/md.sh +++ b/sh/shrc.d/md.sh @@ -10,20 +10,12 @@ md() { # If first arg unset or empty, assume the user means the current dir [ -n "$1" ] || set -- "$PWD" - # If specified path is . or .., quietly expand it - case $1 in - .) set -- "${PWD%/}" ;; - ..) - set -- "${PWD%/}" - set -- "${1%/*}" - ;; - esac + # Jump to the dir and emit PWD from a subshell to get an absolute path + set -- "$(cd -- "$1" && printf %s "$PWD")" - # If specified path not a directory, refuse to mark it - if ! [ -d "$1" ] ; then - printf >&2 'md(): Not a directory\n' - return 2 - fi + # If that turned up empty, we have failed; the cd call probably threw an + # error for us too + [ -n "$1" ] || return # Save the specified path in the marked directory var # shellcheck disable=SC2034 -- cgit v1.2.3