From af7ac510f15e3f84804c750497fcbda4883ace57 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Tue, 17 Jul 2018 11:05:49 +0200 Subject: [PATCH] adding link_by_default option for #49 --- README.md | 1 + config.yaml | 1 + dotdrop/config.py | 4 ++++ dotdrop/dotdrop.py | 7 ++++--- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b7d2302..cf5c0dd 100644 --- a/README.md +++ b/README.md @@ -451,6 +451,7 @@ 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. diff --git a/config.yaml b/config.yaml index 7735d9c..99ad2b4 100644 --- a/config.yaml +++ b/config.yaml @@ -5,5 +5,6 @@ config: banner: true longkey: false keepdot: false + link_by_default: false dotfiles: profiles: diff --git a/dotdrop/config.py b/dotdrop/config.py index 4777073..57acabe 100644 --- a/dotdrop/config.py +++ b/dotdrop/config.py @@ -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""" diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index cc06cba..185eac9 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -279,7 +279,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 @@ -293,11 +294,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: