Expand Dotfile syntax support to not require a <source> argument

Supported action syntax:

- `<action>: <source> -> <target>`
- `<action>: -> <target>`
- `<source> -> <target>`
- `-> <target>`
This commit is contained in:
2014-03-08 13:29:07 +00:00
parent 8fa09ea3c3
commit e0f0177301
3 changed files with 35 additions and 3 deletions

View File

@@ -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 <source>,
# 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

View File

@@ -20,12 +20,22 @@ compile-dotfile() {
output="${output}$(trim "${BASH_REMATCH[3]}") "
output="${output}$(trim "${BASH_REMATCH[4]}")\n"
# Parse "<action>: -> <target>" 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 "<source> -> <target>" 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 "-> <target>" 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"

View File

@@ -39,6 +39,15 @@ dotify-action link ackrc .ackrc
dotify-action link gitconfig \".gitconfig\""
# Compiles standard actions without a <source>
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 <source>
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