Update locate-* functions to use global variables

This commit is contained in:
2013-06-28 13:55:23 +02:00
parent 2e9bd7ce53
commit 5423c61c1c

View File

@@ -1,39 +1,31 @@
locate-dotfile() { locate-dotfile() {
local dotfile
if [ -n "$DOTFILE" ]; then if [ -n "$DOTFILE" ]; then
dotfile="$DOTFILE" if [ ! -f "$DOTFILE" ]; then
if [ ! -f "$dotfile" ]; then echo "ERROR: \"$DOTFILE\" does not exist." >&2
echo "ERROR: \"$dotfile\" does not exist." >&2
return 1 return 1
fi fi
elif [ -f "$(pwd)/Dotfile" ]; then elif [ -f "$(pwd)/Dotfile" ]; then
dotfile="$(pwd)/Dotfile" DOTFILE="$(pwd)/Dotfile"
else else
echo "ERROR: \"$(pwd)\" does not have a Dotfile." >&2 echo "ERROR: \"$(pwd)\" does not have a Dotfile." >&2
return 1 return 1
fi fi
echo "$dotfile"
} }
locate-target() { locate-target() {
local target if [ -n "$TARGET" ]; then
if [ -n "$DOTFILE" ]; then if [ ! -d "$TARGET" ]; then
target="$TARGET" echo "ERROR: Target \"$TARGET\" is not a directory." >&2
if [ ! -d "$target" ]; then
echo "ERROR: Target \"$target\" is not a directory." >&2
return 1 return 1
fi fi
elif [ -n "$HOME" ] && [ -d "$HOME" ]; then elif [ -n "$HOME" ] && [ -d "$HOME" ]; then
target="$HOME" TARGET="$HOME"
elif [ -d ~ ]; then elif [ -d ~ ]; then
target=~ TARGET=~
else else
echo "ERROR: Your \$HOME folder could not be found." >&2 echo "ERROR: Your \$HOME folder could not be found." >&2
return 1 return 1
fi fi
echo "$target"
} }
create-rootlink() { create-rootlink() {