Add environment variable expansion in link paths
This feature was proposed by Brian Knobbs <brian@redlattice.com>.
This commit is contained in:
parent
53c26ba9e6
commit
fd7f3b8551
5 changed files with 64 additions and 1 deletions
|
@ -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.
|
Link commands specify how files and directories should be symbolically linked.
|
||||||
If desired, items can be specified to be forcibly linked, overwriting existing
|
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
|
#### Format
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,8 @@ class Linker(Executor):
|
||||||
def _process_links(self, links):
|
def _process_links(self, links):
|
||||||
success = True
|
success = True
|
||||||
for destination, source in links.items():
|
for destination, source in links.items():
|
||||||
|
source = os.path.expandvars(source)
|
||||||
|
destination = os.path.expandvars(destination)
|
||||||
if isinstance(source, dict):
|
if isinstance(source, dict):
|
||||||
# extended config
|
# extended config
|
||||||
path = source['path']
|
path = source['path']
|
||||||
|
|
18
test/tests/link-environment-variable-expansion-source.bash
Normal file
18
test/tests/link-environment-variable-expansion-source.bash
Normal file
|
@ -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 <<EOF
|
||||||
|
- link:
|
||||||
|
~/.i: \$APPLE
|
||||||
|
EOF
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'test' '
|
||||||
|
grep "grape" ~/.i
|
||||||
|
'
|
25
test/tests/link-environment-variable-expansion-target.bash
Normal file
25
test/tests/link-environment-variable-expansion-target.bash
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
test_description='link expands environment variables in target'
|
||||||
|
. '../test-lib.bash'
|
||||||
|
|
||||||
|
test_expect_success 'setup' '
|
||||||
|
echo "apple" > ${DOTFILES}/f &&
|
||||||
|
echo "grape" > ${DOTFILES}/h
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'run' '
|
||||||
|
export ORANGE=".config" &&
|
||||||
|
export BANANA="g" &&
|
||||||
|
unset PEAR &&
|
||||||
|
run_dotbot <<EOF
|
||||||
|
- link:
|
||||||
|
~/\${ORANGE}/\$BANANA:
|
||||||
|
path: f
|
||||||
|
create: true
|
||||||
|
~/\$PEAR: h
|
||||||
|
EOF
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'test' '
|
||||||
|
grep "apple" ~/.config/g &&
|
||||||
|
grep "grape" ~/\$PEAR
|
||||||
|
'
|
18
test/tests/link-environment-variable-unset.bash
Normal file
18
test/tests/link-environment-variable-unset.bash
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
test_description='link leaves unset environment variables'
|
||||||
|
. '../test-lib.bash'
|
||||||
|
|
||||||
|
test_expect_success 'setup' '
|
||||||
|
echo "apple" > ${DOTFILES}/\$ORANGE
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'run' '
|
||||||
|
unset ORANGE &&
|
||||||
|
run_dotbot <<EOF
|
||||||
|
- link:
|
||||||
|
~/.f: \$ORANGE
|
||||||
|
EOF
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'test' '
|
||||||
|
grep "apple" ~/.f
|
||||||
|
'
|
Loading…
Reference in a new issue