Updates to use global variables

This commit is contained in:
2013-07-01 12:01:54 +02:00
parent 0c523bc5cf
commit f286a1b369
2 changed files with 20 additions and 36 deletions

View File

@@ -1,10 +1,10 @@
dotify-install() { dotify-install() {
local dotfile="$(locate-dotfile)" locate-dotfile
if [ -z "$dotfile" ]; then return 1; fi if [ -n "$?" ]; then return 1; fi
local target="$(locate-target)" locate-target
if [ -z "$target" ]; then return 1; fi if [ -n "$?" ]; then return 1; fi
parse-dotfile "$dotfile" "$target" execute-dotfile
return $? return $?
} }

View File

@@ -28,58 +28,45 @@ locate-target() {
fi fi
} }
create-rootlink() {
local root="$1"
local rootlink="$2"
}
create-symlink() { create-symlink() {
local source="$1" local source="$1"
local target="$2" local target="$2"
} }
parse-dotfile() { execute-dotfile() {
local dotfile="$1" parse-dotfile-rootlink
local target="$2" ROOTDIR="$(dirname "$DOTFILE")"
local rootlink="$(parse-dotfile-rootlink "$dotfile")"
local rootdir="$(dirname "$dotfile")"
local cwd="$(pwd)" local cwd="$(pwd)"
cd "$rootdir" cd "$rootdir"
create-rootlink "$rootdir" "$target/$rootlink" create-symlink "$rootdir" "$TARGET/$ROOTLINK"
if [ -n "$?" ]; then return 1; fi if [ -n "$?" ]; then return 1; fi
while read line; do while read line; do
parse-dotfile-line "$dotfile" "$target" "$rootdir" "$rootlink" "$line" parse-dotfile-line "$line"
if [ -n "$?" ]; then return 1; fi if [ -n "$?" ]; then return 1; fi
done < "$dotfile" done < "$DOTFILE"
cd "$cwd" cd "$cwd"
} }
parse-dotfile-rootlink() { parse-dotfile-rootlink() {
local dotfile="$1"
local rootlink
while read line; do while read line; do
if [[ "$line" == "root_link "* ]]; then if [[ "$line" == "root_link "* ]]; then
rootlink=${line/#root_link /} ROOTLINK="$(trim "${line/#root_link /}")"
break break
fi fi
done < "$dotfile" done < "$DOTFILE"
if [ -z "$rootlink" ]; then rootlink=".dotfiles"; fi if [ -z "$ROOTLINK" ]; then ROOTLINK=".dotfiles"; fi
echo "$ROOTLINK"
echo "$root_link"
} }
parse-dotfile-line() { parse-dotfile-line() {
local dotfile="$1" local line="$1"
local target="$2" local dotfile="$DOTFILE"
local rootdir="$3" if [ -n "$2" ]; then dotfile="$2"; fi
local rootlink="$4"
local line="$5"
# Ignore comment lines starting with "#". # Ignore comment lines starting with "#".
if [[ "$line" == "#"* ]]; then return 0; fi if [[ "$line" == "#"* ]]; then return 0; fi
@@ -89,7 +76,7 @@ parse-dotfile-line() {
# Handle include command. # Handle include command.
if [[ "$line" == "include "* ]]; then if [[ "$line" == "include "* ]]; then
include-dotfile "${line/#include /}" "$target" "$rootdir" "$rootlink" include-dotfile "$(trim "${line/#include /}")"
return "$?" return "$?"
fi fi
@@ -98,9 +85,6 @@ parse-dotfile-line() {
include-dotfile() { include-dotfile() {
local dotfile="$1" local dotfile="$1"
local target="$2"
local rootdir="$3"
local rootlink="$4"
local cwd="$(pwd)" local cwd="$(pwd)"
cd "$rootdir" cd "$rootdir"
@@ -111,7 +95,7 @@ include-dotfile() {
fi fi
while read line; do while read line; do
parse-dotfile-line "$dotfile" "$target" "$rootdir" "$rootlink" "$line" parse-dotfile-line "$line" "$dotfile"
if [ -n "$?" ]; then return 1; fi if [ -n "$?" ]; then return 1; fi
done < "$dotfile" done < "$dotfile"