urchin_root

don't need it just yet
This commit is contained in:
Thomas Levine 2016-02-28 11:22:51 +00:00
parent 062ace88e6
commit c2ab8410c6
1 changed files with 29 additions and 1 deletions

30
urchin
View File

@ -35,8 +35,36 @@ urchin_path() {
fullpath "$1"
}
urchin_root() {
remove_trailing_slash() {
echo "$1" | sed s/\\/$//
}
urchin_root() {
# Call recursively but remember the original argument.
current="$(remove_trailing_slash "$1")"
if test -n "$2"; then
orig="$2"
else
orig="$1"
fi
if test "$(readlink -f -- "$1")" = /; then
# Stop traversing upwards at /
if test -d "$orig"; then
echo "$orig"
else
dirname "$orig"
fi
elif ! test -e "$current"; then
echo "$current: No such file or directory">&2
return 1
elif test -f "$current"; then
urchin_root "$(dirname "$current")" "$orig"
elif test -d "$current"/.urchin; then
remove_trailing_slash "$current"
else
urchin_root "$current"/.. "$orig"
fi
}
# Urchin version number