aboutsummaryrefslogtreecommitdiff
path: root/sh
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-01-05 21:12:51 +1300
committerTom Ryder <tom@sanctum.geek.nz>2017-01-05 21:12:51 +1300
commit5c8662d4360429599de579ccd8b1f8c1b4de82c3 (patch)
tree58fa2c4a72cde19cffd207804efa1b713535dadf /sh
parentAdd possibility for handling md() feature (diff)
downloaddotfiles-5c8662d4360429599de579ccd8b1f8c1b4de82c3.tar.gz
dotfiles-5c8662d4360429599de579ccd8b1f8c1b4de82c3.zip
Resolve an md() issue
Made the whole thing tidier, actually
Diffstat (limited to 'sh')
-rw-r--r--sh/shrc.d/md.sh18
1 files changed, 5 insertions, 13 deletions
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