diff options
-rw-r--r-- | ISSUES.markdown | 3 | ||||
-rw-r--r-- | sh/shrc.d/md.sh | 18 |
2 files changed, 5 insertions, 16 deletions
diff --git a/ISSUES.markdown b/ISSUES.markdown index 109de041..383d7906 100644 --- a/ISSUES.markdown +++ b/ISSUES.markdown @@ -15,9 +15,6 @@ Known issues jobspecs around that flee after a jobs builtin run; only saw this manifest after 90dcadf; either I understand job specs really poorly or this may be a bug in bash -* md() does not handle e.g. "../..". If there's a tidy way of making it do so - that would probably be worthwhile. Maybe by trying to go there in a - subshell and printing PWD? * I can't find a clean way of detecting a restricted shell for ksh instances to prevent trying to load anything fancy (works for Bash) * Zsh, either! $options[restricted] is "off" within the startup file 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 |