Allow empty link sources
If the source for a link is null, use the basename of the destination with a single leading '.' removed, if present.
This commit is contained in:
parent
b482cbda58
commit
4bfa3291ba
3 changed files with 79 additions and 2 deletions
41
README.md
41
README.md
|
@ -189,6 +189,47 @@ symbolic link should have a relative path.
|
|||
path: zshrc
|
||||
```
|
||||
|
||||
If the source location is omitted or NULL, dotbot will use the destination instead, without a leading `.` if present. This makes the following three config files equivalent:
|
||||
|
||||
```yaml
|
||||
- link:
|
||||
~/bin/ack: ack
|
||||
~/.vim: vim
|
||||
~/.vimrc:
|
||||
relink: true
|
||||
path: vimrc
|
||||
~/.zshrc:
|
||||
force: true
|
||||
path: zshrc
|
||||
```
|
||||
|
||||
```yaml
|
||||
- link:
|
||||
~/bin/ack:
|
||||
~/.vim:
|
||||
~/.vimrc:
|
||||
relink: true
|
||||
~/.zshrc:
|
||||
force: true
|
||||
```
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"link": {
|
||||
"~/bin/ack": null,
|
||||
"~/.vim": null,
|
||||
"~/.vimrc": {
|
||||
"relink": true
|
||||
},
|
||||
"~/.zshrc": {
|
||||
"force": true
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
### Shell
|
||||
|
||||
Shell commands specify shell commands to be run. Shell commands are run in the
|
||||
|
|
|
@ -30,9 +30,9 @@ class Link(dotbot.Plugin):
|
|||
force = source.get('force', force)
|
||||
relink = source.get('relink', relink)
|
||||
create = source.get('create', create)
|
||||
path = source['path']
|
||||
path = self._default_source(destination, source.get('path'))
|
||||
else:
|
||||
path = source
|
||||
path = self._default_source(destination, source)
|
||||
path = os.path.expandvars(os.path.expanduser(path))
|
||||
if create:
|
||||
success &= self._create(destination)
|
||||
|
@ -46,6 +46,16 @@ class Link(dotbot.Plugin):
|
|||
self._log.error('Some links were not successfully set up')
|
||||
return success
|
||||
|
||||
def _default_source(self, destination, source):
|
||||
if source == None:
|
||||
basename = os.path.basename(destination)
|
||||
if basename.startswith('.'):
|
||||
return basename[1:]
|
||||
else:
|
||||
return basename
|
||||
else:
|
||||
return source
|
||||
|
||||
def _is_link(self, path):
|
||||
'''
|
||||
Returns true if the path is a symbolic link.
|
||||
|
|
26
test/tests/link-default-source.bash
Normal file
26
test/tests/link-default-source.bash
Normal file
|
@ -0,0 +1,26 @@
|
|||
test_description='link uses destination if source is null'
|
||||
. '../test-lib.bash'
|
||||
|
||||
test_expect_success 'setup' '
|
||||
echo "apple" > ${DOTFILES}/f &&
|
||||
echo "grape" > ${DOTFILES}/fd
|
||||
'
|
||||
|
||||
test_expect_success 'run' '
|
||||
run_dotbot <<EOF
|
||||
- link:
|
||||
~/f:
|
||||
~/.f:
|
||||
~/fd:
|
||||
force: false
|
||||
~/.fd:
|
||||
force: false
|
||||
EOF
|
||||
'
|
||||
|
||||
test_expect_success 'test' '
|
||||
grep "apple" ~/f &&
|
||||
grep "apple" ~/.f &&
|
||||
grep "grape" ~/fd &&
|
||||
grep "grape" ~/.fd
|
||||
'
|
Loading…
Reference in a new issue