aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-01-02 16:00:15 +1300
committerTom Ryder <tom@sanctum.geek.nz>2017-01-02 16:00:15 +1300
commitcd7b34f27453b222c9b9fd26c14d56f7c88a3643 (patch)
treeb4cd8f8601e6eb70b0a4d73e2d9b91714b4ff40f
parentAdd completion for md() (diff)
downloaddotfiles-cd7b34f27453b222c9b9fd26c14d56f7c88a3643.tar.gz
dotfiles-cd7b34f27453b222c9b9fd26c14d56f7c88a3643.zip
Handle simple relative dirs in md()
And add an issue about handling complex ones
-rw-r--r--ISSUES.markdown2
-rw-r--r--sh/shrc.d/md.sh9
2 files changed, 11 insertions, 0 deletions
diff --git a/ISSUES.markdown b/ISSUES.markdown
index dda99334..0b31661f 100644
--- a/ISSUES.markdown
+++ b/ISSUES.markdown
@@ -17,3 +17,5 @@ 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 worhwhile.
diff --git a/sh/shrc.d/md.sh b/sh/shrc.d/md.sh
index cf44abb3..1f8a8aaf 100644
--- a/sh/shrc.d/md.sh
+++ b/sh/shrc.d/md.sh
@@ -10,6 +10,15 @@ 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
+
# If specified path not a directory, refuse to mark it
if ! [ -d "$1" ] ; then
printf >&2 'md(): Not a directory\n'