From fd7f3b85514b3aca17afda51ff0ee22937388451 Mon Sep 17 00:00:00 2001 From: Anish Athalye Date: Tue, 12 May 2015 20:04:42 -0400 Subject: [PATCH] Add environment variable expansion in link paths This feature was proposed by Brian Knobbs . --- README.md | 2 +- dotbot/executor/linker.py | 2 ++ ...environment-variable-expansion-source.bash | 18 +++++++++++++ ...environment-variable-expansion-target.bash | 25 +++++++++++++++++++ .../link-environment-variable-unset.bash | 18 +++++++++++++ 5 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 test/tests/link-environment-variable-expansion-source.bash create mode 100644 test/tests/link-environment-variable-expansion-target.bash create mode 100644 test/tests/link-environment-variable-unset.bash diff --git a/README.md b/README.md index 3534dba..367e562 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ Following the formatting used in the examples is a good idea. Link commands specify how files and directories should be symbolically linked. If desired, items can be specified to be forcibly linked, overwriting existing -files if necessary. +files if necessary. Environment variables in paths are automatically expanded. #### Format diff --git a/dotbot/executor/linker.py b/dotbot/executor/linker.py index f0e94bc..5c12ea0 100644 --- a/dotbot/executor/linker.py +++ b/dotbot/executor/linker.py @@ -19,6 +19,8 @@ class Linker(Executor): def _process_links(self, links): success = True for destination, source in links.items(): + source = os.path.expandvars(source) + destination = os.path.expandvars(destination) if isinstance(source, dict): # extended config path = source['path'] diff --git a/test/tests/link-environment-variable-expansion-source.bash b/test/tests/link-environment-variable-expansion-source.bash new file mode 100644 index 0000000..50456d6 --- /dev/null +++ b/test/tests/link-environment-variable-expansion-source.bash @@ -0,0 +1,18 @@ +test_description='link expands environment variables in source' +. '../test-lib.bash' + +test_expect_success 'setup' ' +echo "grape" > ${DOTFILES}/h +' + +test_expect_success 'run' ' +export APPLE="h" && +run_dotbot < ${DOTFILES}/f && +echo "grape" > ${DOTFILES}/h +' + +test_expect_success 'run' ' +export ORANGE=".config" && +export BANANA="g" && +unset PEAR && +run_dotbot < ${DOTFILES}/\$ORANGE +' + +test_expect_success 'run' ' +unset ORANGE && +run_dotbot <