From e0f01773010ceef6fedda85e33d3222693fd0a87 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sat, 8 Mar 2014 13:29:07 +0000 Subject: [PATCH] Expand Dotfile syntax support to not require a argument Supported action syntax: - `: -> ` - `: -> ` - ` -> ` - `-> ` --- examples/Dotfile | 10 +++++++--- src/lib/internals/compile-dotfile.sh | 10 ++++++++++ test/lib/internals/compile-dotfile-test.sh | 18 ++++++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/examples/Dotfile b/examples/Dotfile index 85efbf4..be9a111 100644 --- a/examples/Dotfile +++ b/examples/Dotfile @@ -24,9 +24,13 @@ gitignore -> .gitignore hgrc -> .hgrc irbrc -> .irbrc powconfig -> .powconfig -rspec -> .rspec -tmux -> .tmux -tmux.conf -> .tmux.conf + +# The following examples uses the link action, without specifying a , +# in this case the link action is smart enough to determine the source value +# for ".rspec" for example to be "rspec". +link: -> .rspec +-> .tmux +-> .tmux.conf # The same source can be symlinked to multiple targets. load_shellrc.sh -> .profile diff --git a/src/lib/internals/compile-dotfile.sh b/src/lib/internals/compile-dotfile.sh index 6ba06dc..c1d9298 100644 --- a/src/lib/internals/compile-dotfile.sh +++ b/src/lib/internals/compile-dotfile.sh @@ -20,12 +20,22 @@ compile-dotfile() { output="${output}$(trim "${BASH_REMATCH[3]}") " output="${output}$(trim "${BASH_REMATCH[4]}")\n" + # Parse ": -> " lines. + elif [[ "$line" =~ ^(\ +)?([a-zA-Z0-9_-]+):\ *-[\>]\ +(.+)$ ]]; then + output="${output}${BASH_REMATCH[1]}dotify-action ${BASH_REMATCH[2]} " + output="${output}$(trim "${BASH_REMATCH[3]}")\n" + # Parse " -> " lines. elif [[ "$line" =~ ^(\ +)?(.+)\ -[\>]\ (.+)$ ]]; then output="${output}${BASH_REMATCH[1]}dotify-action default " output="${output}$(trim "${BASH_REMATCH[2]}") " output="${output}$(trim "${BASH_REMATCH[3]}")\n" + # Parse "-> " lines. + elif [[ "$line" =~ ^(\ +)?-[\>]\ (.+)$ ]]; then + output="${output}${BASH_REMATCH[1]}dotify-action default " + output="${output}$(trim "${BASH_REMATCH[2]}")\n" + # Append line without modifications. else output="${output}${line}\n" diff --git a/test/lib/internals/compile-dotfile-test.sh b/test/lib/internals/compile-dotfile-test.sh index c6c0743..850d8e8 100755 --- a/test/lib/internals/compile-dotfile-test.sh +++ b/test/lib/internals/compile-dotfile-test.sh @@ -39,6 +39,15 @@ dotify-action link ackrc .ackrc dotify-action link gitconfig \".gitconfig\"" +# Compiles standard actions without a +echo -e "root_link .dotfiles +link: -> .ackrc +link:-> \".gitconfig\"" > $dotfile +assert "compile-dotfile $dotfile" "root_link .dotfiles +dotify-action link .ackrc +dotify-action link \".gitconfig\"" + + # Compiles default (shorthand) actions echo -e "root_link .dotfiles link: ackrc -> .ackrc @@ -48,6 +57,15 @@ dotify-action link ackrc .ackrc dotify-action default gitconfig \".gitconfig\"" +# Compiles default (shorthand) actions without a +echo -e "root_link .dotfiles +-> .ackrc + -> \".gitconfig\"" > $dotfile +assert "compile-dotfile $dotfile" "root_link .dotfiles +dotify-action default .ackrc + dotify-action default \".gitconfig\"" + + # Correctly indents actions echo -e "root_link .dotfiles if [ true ]; then