From f286a1b369a2d5bfe0c7db244a4d766b5520a718 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Mon, 1 Jul 2013 12:01:54 +0200 Subject: [PATCH] Updates to use global variables --- src/lib/dotify-install.sh | 10 ++++----- src/lib/internals.sh | 46 +++++++++++++-------------------------- 2 files changed, 20 insertions(+), 36 deletions(-) diff --git a/src/lib/dotify-install.sh b/src/lib/dotify-install.sh index 3e48cd0..8cef231 100644 --- a/src/lib/dotify-install.sh +++ b/src/lib/dotify-install.sh @@ -1,10 +1,10 @@ dotify-install() { - local dotfile="$(locate-dotfile)" - if [ -z "$dotfile" ]; then return 1; fi + locate-dotfile + if [ -n "$?" ]; then return 1; fi - local target="$(locate-target)" - if [ -z "$target" ]; then return 1; fi + locate-target + if [ -n "$?" ]; then return 1; fi - parse-dotfile "$dotfile" "$target" + execute-dotfile return $? } diff --git a/src/lib/internals.sh b/src/lib/internals.sh index 733231f..65376e9 100644 --- a/src/lib/internals.sh +++ b/src/lib/internals.sh @@ -28,58 +28,45 @@ locate-target() { fi } -create-rootlink() { - local root="$1" - local rootlink="$2" -} - create-symlink() { local source="$1" local target="$2" } -parse-dotfile() { - local dotfile="$1" - local target="$2" - local rootlink="$(parse-dotfile-rootlink "$dotfile")" +execute-dotfile() { + parse-dotfile-rootlink + ROOTDIR="$(dirname "$DOTFILE")" - local rootdir="$(dirname "$dotfile")" local cwd="$(pwd)" cd "$rootdir" - create-rootlink "$rootdir" "$target/$rootlink" + create-symlink "$rootdir" "$TARGET/$ROOTLINK" if [ -n "$?" ]; then return 1; fi while read line; do - parse-dotfile-line "$dotfile" "$target" "$rootdir" "$rootlink" "$line" + parse-dotfile-line "$line" if [ -n "$?" ]; then return 1; fi - done < "$dotfile" + done < "$DOTFILE" cd "$cwd" } parse-dotfile-rootlink() { - local dotfile="$1" - local rootlink - while read line; do if [[ "$line" == "root_link "* ]]; then - rootlink=${line/#root_link /} + ROOTLINK="$(trim "${line/#root_link /}")" break fi - done < "$dotfile" + done < "$DOTFILE" - if [ -z "$rootlink" ]; then rootlink=".dotfiles"; fi - - echo "$root_link" + if [ -z "$ROOTLINK" ]; then ROOTLINK=".dotfiles"; fi + echo "$ROOTLINK" } parse-dotfile-line() { - local dotfile="$1" - local target="$2" - local rootdir="$3" - local rootlink="$4" - local line="$5" + local line="$1" + local dotfile="$DOTFILE" + if [ -n "$2" ]; then dotfile="$2"; fi # Ignore comment lines starting with "#". if [[ "$line" == "#"* ]]; then return 0; fi @@ -89,7 +76,7 @@ parse-dotfile-line() { # Handle include command. if [[ "$line" == "include "* ]]; then - include-dotfile "${line/#include /}" "$target" "$rootdir" "$rootlink" + include-dotfile "$(trim "${line/#include /}")" return "$?" fi @@ -98,9 +85,6 @@ parse-dotfile-line() { include-dotfile() { local dotfile="$1" - local target="$2" - local rootdir="$3" - local rootlink="$4" local cwd="$(pwd)" cd "$rootdir" @@ -111,7 +95,7 @@ include-dotfile() { fi while read line; do - parse-dotfile-line "$dotfile" "$target" "$rootdir" "$rootlink" "$line" + parse-dotfile-line "$line" "$dotfile" if [ -n "$?" ]; then return 1; fi done < "$dotfile"