From 5981cb248e399b5594f9227b7de8f1c2b31e2c3f Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 23 Jan 2017 14:04:51 +1300 Subject: Work around trailing newlines in vr() This is ugly, but a better fix isn't evident to me just now. --- sh/shrc.d/vr.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'sh') diff --git a/sh/shrc.d/vr.sh b/sh/shrc.d/vr.sh index 1902e3ba..8b35357c 100644 --- a/sh/shrc.d/vr.sh +++ b/sh/shrc.d/vr.sh @@ -19,10 +19,16 @@ vr() { cd -- "$path" || exit # Ask Git the top level (good) - git rev-parse --show-toplevel 2>/dev/null && exit + if git rev-parse --show-toplevel 2>/dev/null ; then + printf / + exit + fi # Ask Mercurial the top level (great) - hg root 2>/dev/null && exit + if hg root 2>/dev/null ; then + printf / + exit + fi # If we can get SVN info, iterate upwards until we cannot; hopefully # that is the root (bad) @@ -32,7 +38,7 @@ vr() { cd .. || exit done if [ -n "$root" ] ; then - printf '%s\n' "$root" + printf '%s\n/' "$root" exit fi @@ -41,6 +47,9 @@ vr() { exit 1 )" + # Chop the trailing newline and slash + set -- "${1%?/}" + # Check we figured out a target, or bail [ -n "$1" ] || return -- cgit v1.2.3