mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-04 20:54:51 +00:00
Merge branch 'link_by_default'
This commit is contained in:
@@ -451,9 +451,10 @@ the following entries:
|
||||
* `banner`: display the banner (default *true*)
|
||||
* `longkey`: use long keys for dotfiles when importing (default *false*)
|
||||
* `keepdot`: preserve leading dot when importing hidden file in the `dotpath` (default *false*)
|
||||
* `link_by_default`: when importing a dotfile set `link` to that value per default (default *false*)
|
||||
|
||||
* **dotfiles** entry: a list of dotfiles
|
||||
* When `link` is true, dotdrop will create a symlink instead of copying. Template generation (as in [template](#template)) is not supported when `link` is true.
|
||||
* When `link` is true, dotdrop will create a symlink instead of copying. Template generation (as in [template](#template)) is not supported when `link` is true (default *false*).
|
||||
* `actions` contains a list of action keys that need to be defined in the **actions** entry below.
|
||||
* `trans` contains a list of transformation keys that need to be defined in the **trans** entry below.
|
||||
```
|
||||
|
||||
@@ -5,5 +5,6 @@ config:
|
||||
banner: true
|
||||
longkey: false
|
||||
keepdot: false
|
||||
link_by_default: false
|
||||
dotfiles:
|
||||
profiles:
|
||||
|
||||
@@ -28,6 +28,7 @@ class Cfg:
|
||||
key_banner = 'banner'
|
||||
key_long = 'longkey'
|
||||
key_keepdot = 'keepdot'
|
||||
key_deflink = 'link_by_default'
|
||||
|
||||
# actions keys
|
||||
key_actions = 'actions'
|
||||
@@ -57,6 +58,7 @@ class Cfg:
|
||||
default_link = False
|
||||
default_longkey = False
|
||||
default_keepdot = False
|
||||
default_link_by_default = False
|
||||
|
||||
def __init__(self, cfgpath):
|
||||
if not os.path.exists(cfgpath):
|
||||
@@ -288,6 +290,8 @@ class Cfg:
|
||||
self.lnk_settings[self.key_long] = self.default_longkey
|
||||
if self.key_keepdot not in self.lnk_settings:
|
||||
self.lnk_settings[self.key_keepdot] = self.default_keepdot
|
||||
if self.key_deflink not in self.lnk_settings:
|
||||
self.lnk_settings[self.key_deflink] = self.default_link_by_default
|
||||
|
||||
def abs_dotpath(self, path):
|
||||
"""transform path to an absolute path based on config path"""
|
||||
|
||||
@@ -289,7 +289,8 @@ def importer(opts, conf, paths):
|
||||
|
||||
# create a new dotfile
|
||||
dotfile = Dotfile('', dst, src)
|
||||
retconf, new_dotfile = conf.new(dotfile, opts['profile'], opts['link'])
|
||||
linkit = opts['link'] or opts['link_by_default']
|
||||
retconf, new_dotfile = conf.new(dotfile, opts['profile'], linkit)
|
||||
dotfile = new_dotfile
|
||||
|
||||
# prepare hierarchy for dotfile
|
||||
@@ -303,11 +304,11 @@ def importer(opts, conf, paths):
|
||||
cmd = ['cp', '-R', '-L', dst, srcf]
|
||||
if opts['dry']:
|
||||
LOG.dry('would run: {}'.format(' '.join(cmd)))
|
||||
if opts['link']:
|
||||
if linkit:
|
||||
LOG.dry('would symlink {} to {}'.format(srcf, dst))
|
||||
else:
|
||||
run(cmd, raw=False, debug=opts['debug'])
|
||||
if opts['link']:
|
||||
if linkit:
|
||||
remove(dst)
|
||||
os.symlink(srcf, dst)
|
||||
if retconf:
|
||||
|
||||
58
scripts/change-link.py
Executable file
58
scripts/change-link.py
Executable file
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
author: deadc0de6 (https://github.com/deadc0de6)
|
||||
Copyright (c) 2018, deadc0de6
|
||||
|
||||
change the `link` key in all dotfiles
|
||||
to a specific value
|
||||
|
||||
usage example:
|
||||
./change-link.py --true ../config.yaml --ignore f_vimrc --ignore f_xinitrc
|
||||
"""
|
||||
|
||||
from docopt import docopt
|
||||
import sys
|
||||
import os
|
||||
import yaml
|
||||
|
||||
USAGE = """
|
||||
change-link.py
|
||||
|
||||
Usage:
|
||||
change-link.py (--true | --false) [--ignore=<dotfile-name>...] <config.yaml>
|
||||
change-link.py --help
|
||||
|
||||
Options:
|
||||
-h --help Show this screen.
|
||||
|
||||
"""
|
||||
|
||||
key = 'dotfiles'
|
||||
entry = 'link'
|
||||
|
||||
|
||||
def main():
|
||||
args = docopt(USAGE)
|
||||
path = os.path.expanduser(args['<config.yaml>'])
|
||||
if args['--true']:
|
||||
value = True
|
||||
if args['--false']:
|
||||
value = False
|
||||
|
||||
ignores = args['--ignore']
|
||||
|
||||
with open(path, 'r') as f:
|
||||
content = yaml.load(f)
|
||||
for k, v in content[key].items():
|
||||
if k in ignores:
|
||||
continue
|
||||
v[entry] = value
|
||||
|
||||
ret = yaml.dump(content, default_flow_style=False, indent=2)
|
||||
print(ret)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if main():
|
||||
sys.exit(0)
|
||||
sys.exit(1)
|
||||
Reference in New Issue
Block a user