Skip to content

Commit

Permalink
Merge branch 'casey/empty-source'
Browse files Browse the repository at this point in the history
  • Loading branch information
anishathalye committed Nov 23, 2016
2 parents 4468fff + d2e20c7 commit 847cb10
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,49 @@ symbolic link should have a relative path.
path: zshrc
```

If the source location is omitted or set to `null`, Dotbot will use the
basename of the destination, with a leading `.` stripped 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
Expand Down
14 changes: 12 additions & 2 deletions plugins/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ def _process_links(self, links):
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 not self._exists(os.path.join(self._context.base_directory(), path)):
success = False
Expand All @@ -53,6 +53,16 @@ def _process_links(self, links):
self._log.error('Some links were not successfully set up')
return success

def _default_source(self, destination, source):
if source is 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.
Expand Down
26 changes: 26 additions & 0 deletions test/tests/link-default-source.bash
Original file line number Diff line number Diff line change
@@ -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
'

0 comments on commit 847cb10

Please sign in to comment.