summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnish Athalye <me@anishathalye.com>2016-08-17 18:15:02 -0700
committerAnish Athalye <me@anishathalye.com>2016-08-17 18:27:47 -0700
commit28959a3f31d8632975de4e18d0a0e47476b5a413 (patch)
treed80168df64b54671e3785e815762316fbe1d38b1
parentf04b94d4ae98599568d868c6d14d2ea428d4f16a (diff)
Fix user expansion in link source
Previous to this patch, having a config like the following would not work properly: - link: ~/a: ~/b This was because the '~' was expanded on the left hand side (the link target), but not the right hand side (the link source). It was necessary to use a workaround like this: - link: ~/a: $HOME/b This was because variable expansion was being done, but user expansion was not being done. This commit adds support for using '~' in the link source.
-rw-r--r--plugins/link.py5
-rw-r--r--test/tests/link-environment-user-expansion-target.bash17
2 files changed, 20 insertions, 2 deletions
diff --git a/plugins/link.py b/plugins/link.py
index 9e1dce0..483d35e 100644
--- a/plugins/link.py
+++ b/plugins/link.py
@@ -30,9 +30,10 @@ class Link(dotbot.Plugin):
force = source.get('force', force)
relink = source.get('relink', relink)
create = source.get('create', create)
- path = os.path.expandvars(source['path'])
+ path = source['path']
else:
- path = os.path.expandvars(source)
+ path = source
+ path = os.path.expandvars(os.path.expanduser(path))
if create:
success &= self._create(destination)
if force or relink:
diff --git a/test/tests/link-environment-user-expansion-target.bash b/test/tests/link-environment-user-expansion-target.bash
new file mode 100644
index 0000000..9cb3424
--- /dev/null
+++ b/test/tests/link-environment-user-expansion-target.bash
@@ -0,0 +1,17 @@
+test_description='link expands user in target'
+. '../test-lib.bash'
+
+test_expect_success 'setup' '
+echo "apple" > ~/f
+'
+
+test_expect_success 'run' '
+run_dotbot <<EOF
+- link:
+ ~/g: ~/f
+EOF
+'
+
+test_expect_success 'test' '
+grep "apple" ~/g
+'