summaryrefslogtreecommitdiff
path: root/vsvs-locate
diff options
context:
space:
mode:
authorAleksey Veresov <aleksey@veresov.pro>2020-12-06 22:02:01 +0300
committerAleksey Veresov <aleksey@veresov.pro>2020-12-06 22:02:01 +0300
commitae3ad126181f6f974941190848ed9532edbfc6c5 (patch)
tree80409992c8bb496c30959fb09e281db44538ba23 /vsvs-locate
parentc8550c2ba6bc3f80cbad499a6997d0b903580599 (diff)
downloadvsvs-ae3ad126181f6f974941190848ed9532edbfc6c5.tar
vsvs-ae3ad126181f6f974941190848ed9532edbfc6c5.tar.xz
vsvs-ae3ad126181f6f974941190848ed9532edbfc6c5.zip
.
Diffstat (limited to 'vsvs-locate')
-rw-r--r--vsvs-locate14
1 files changed, 14 insertions, 0 deletions
diff --git a/vsvs-locate b/vsvs-locate
new file mode 100644
index 0000000..009eccc
--- /dev/null
+++ b/vsvs-locate
@@ -0,0 +1,14 @@
+#!/bin/bash
+# Tear $1 into path to file (or directory) and in file,
+# if no such file exit with error.
+after () { test -z "${2##*$1*}" && echo -n "${2#*$1}"; }
+test "${1::1}" == "/" && path=$base || path="."
+lastpath=$1
+until test -n "$lastpath" || test -f "$path"
+do
+ path="$path/${lastpath%%/*}"
+ lastpath=$(after / "$lastpath")
+ test -e "$path" || exit 1
+done
+echo "$path"
+echo "$lastpath"