1
0
Fork 0
mirror of synced 2024-12-22 14:11:07 -05:00

Merge branch 'eengstrom/259-link-prefix'

This commit is contained in:
Anish Athalye 2021-06-02 20:21:40 -04:00
commit 24f88c4584
3 changed files with 33 additions and 0 deletions

View file

@ -185,6 +185,7 @@ mapped to extended configuration dictionaries.
| `ignore-missing` | Do not fail if the source is missing and create the link anyway (default: false) |
| `glob` | Treat `path` as a glob pattern, expanding patterns referenced below, linking all *files** matched. (default: false) |
| `exclude` | Array of glob patterns to remove from glob matches. Uses same syntax as `path`. Ignored if `glob` is `false`. (default: empty, keep all matches) |
| `prefix` | Prepend prefix prefix to basename of each file when linked, when `glob` is `true`. (default: '') |
When `glob: True`, Dotbot uses [glob.glob](https://docs.python.org/3/library/glob.html#glob.glob) to resolve glob paths, expanding Unix shell-style wildcards, which are **not** the same as regular expressions; Only the following are expanded:
@ -217,6 +218,10 @@ However, due to the design of `glob.glob`, using a glob pattern such as `config/
path: hammerspoon
~/.config/:
path: dotconf/config/**
~/:
glob: true
path: dotconf/*
prefix: '.'
```
If the source location is omitted or set to `null`, Dotbot will use the

View file

@ -34,6 +34,7 @@ class Link(dotbot.Plugin):
relink = defaults.get('relink', False)
create = defaults.get('create', False)
use_glob = defaults.get('glob', False)
base_prefix = defaults.get('prefix', '')
test = defaults.get('if', None)
ignore_missing = defaults.get('ignore-missing', False)
exclude_paths = defaults.get('exclude', [])
@ -46,6 +47,7 @@ class Link(dotbot.Plugin):
relink = source.get('relink', relink)
create = source.get('create', create)
use_glob = source.get('glob', use_glob)
base_prefix = source.get('prefix', base_prefix)
ignore_missing = source.get('ignore-missing', ignore_missing)
exclude_paths = source.get('exclude', exclude_paths)
path = self._default_source(destination, source.get('path'))
@ -81,6 +83,9 @@ class Link(dotbot.Plugin):
# Find common dirname between pattern and the item:
glob_dirname = os.path.dirname(os.path.commonprefix([path, glob_full_item]))
glob_item = (glob_full_item if len(glob_dirname) == 0 else glob_full_item[len(glob_dirname) + 1:])
# Add prefix to basepath, if provided
if base_prefix:
glob_item = base_prefix + glob_item
# where is it going
glob_link_destination = os.path.join(destination, glob_item)
if create:

View file

@ -0,0 +1,23 @@
test_description='link prefix'
. '../test-lib.bash'
test_expect_success 'setup' '
mkdir ${DOTFILES}/conf &&
echo "apple" > ${DOTFILES}/conf/a &&
echo "banana" > ${DOTFILES}/conf/b &&
echo "cherry" > ${DOTFILES}/conf/c
'
test_expect_success 'test glob w/ prefix' '
run_dotbot -v <<EOF
- link:
~/:
glob: true
path: conf/*
prefix: '.'
EOF
grep "apple" ~/.a &&
grep "banana" ~/.b &&
grep "cherry" ~/.c
'