mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-11 03:14:15 +00:00
add option to show diff before asking to overwrite
This commit is contained in:
@@ -610,6 +610,7 @@ the following entries:
|
|||||||
* `keepdot`: preserve leading dot when importing hidden file in the `dotpath` (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*)
|
* `link_by_default`: when importing a dotfile set `link` to that value per default (default *false*)
|
||||||
* `workdir`: directory where templates are installed before being symlink when using `link` (default *~/.config/dotdrop*)
|
* `workdir`: directory where templates are installed before being symlink when using `link` (default *~/.config/dotdrop*)
|
||||||
|
* `showdiff`: on install show a diff before asking to overwrite (see `--showdiff`) (default *false*)
|
||||||
|
|
||||||
* **dotfiles** entry: a list of dotfiles
|
* **dotfiles** entry: a list of dotfiles
|
||||||
* When `link` is true, dotdrop will create a symlink instead of copying (default *false*).
|
* When `link` is true, dotdrop will create a symlink instead of copying (default *false*).
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ class Cfg:
|
|||||||
key_banner = 'banner'
|
key_banner = 'banner'
|
||||||
key_long = 'longkey'
|
key_long = 'longkey'
|
||||||
key_keepdot = 'keepdot'
|
key_keepdot = 'keepdot'
|
||||||
|
key_showdiff = 'showdiff'
|
||||||
key_deflink = 'link_by_default'
|
key_deflink = 'link_by_default'
|
||||||
key_workdir = 'workdir'
|
key_workdir = 'workdir'
|
||||||
|
|
||||||
@@ -64,6 +65,7 @@ class Cfg:
|
|||||||
default_link = False
|
default_link = False
|
||||||
default_longkey = False
|
default_longkey = False
|
||||||
default_keepdot = False
|
default_keepdot = False
|
||||||
|
default_showdiff = False
|
||||||
default_link_by_default = False
|
default_link_by_default = False
|
||||||
default_workdir = '~/.config/dotdrop'
|
default_workdir = '~/.config/dotdrop'
|
||||||
|
|
||||||
@@ -315,6 +317,8 @@ class Cfg:
|
|||||||
self.lnk_settings[self.key_deflink] = self.default_link_by_default
|
self.lnk_settings[self.key_deflink] = self.default_link_by_default
|
||||||
if self.key_workdir not in self.lnk_settings:
|
if self.key_workdir not in self.lnk_settings:
|
||||||
self.lnk_settings[self.key_workdir] = self.default_workdir
|
self.lnk_settings[self.key_workdir] = self.default_workdir
|
||||||
|
if self.key_showdiff not in self.lnk_settings:
|
||||||
|
self.lnk_settings[self.key_showdiff] = self.default_showdiff
|
||||||
|
|
||||||
def abs_dotpath(self, path):
|
def abs_dotpath(self, path):
|
||||||
"""transform path to an absolute path based on config path"""
|
"""transform path to an absolute path based on config path"""
|
||||||
|
|||||||
@@ -42,26 +42,26 @@ USAGE = """
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
dotdrop install [-tfndVb] [-c <path>] [-p <profile>] [<key>...]
|
dotdrop install [-tfndVbD] [-c <path>] [-p <profile>] [<key>...]
|
||||||
dotdrop import [-ldVb] [-c <path>] [-p <profile>] <paths>...
|
dotdrop import [-ldVb] [-c <path>] [-p <profile>] <paths>...
|
||||||
dotdrop compare [-Vb] [-c <path>] [-p <profile>]
|
dotdrop compare [-Vb] [-c <path>] [-p <profile>]
|
||||||
[-o <opts>] [-i <name>...]
|
[-o <opts>] [-C <files>] [-i <name>...]
|
||||||
[--files=<files>]
|
dotdrop update [-fdVb] [-c <path>] <paths>...
|
||||||
dotdrop update [-fdVb] [-c <path>] <paths>...
|
dotdrop listfiles [-VTb] [-c <path>] [-p <profile>]
|
||||||
dotdrop listfiles [-VTb] [-c <path>] [-p <profile>]
|
dotdrop list [-Vb] [-c <path>]
|
||||||
dotdrop list [-Vb] [-c <path>]
|
|
||||||
dotdrop --help
|
dotdrop --help
|
||||||
dotdrop --version
|
dotdrop --version
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-p --profile=<profile> Specify the profile to use [default: {}].
|
-p --profile=<profile> Specify the profile to use [default: {}].
|
||||||
-c --cfg=<path> Path to the config [default: config.yaml].
|
-c --cfg=<path> Path to the config [default: config.yaml].
|
||||||
--files=<files> Comma separated list of files to compare.
|
-C --files=<files> Comma separated list of files to compare.
|
||||||
-i --ignore=<name> File name to ignore when diffing.
|
-i --ignore=<name> File name to ignore when diffing.
|
||||||
-o --dopts=<opts> Diff options [default: ].
|
-o --dopts=<opts> Diff options [default: ].
|
||||||
-n --nodiff Do not diff when installing.
|
-n --nodiff Do not diff when installing.
|
||||||
-t --temp Install to a temporary directory for review.
|
-t --temp Install to a temporary directory for review.
|
||||||
-T --template Only template dotfiles.
|
-T --template Only template dotfiles.
|
||||||
|
-D --showdiff Show a diff before overwriting.
|
||||||
-l --link Import and link.
|
-l --link Import and link.
|
||||||
-f --force Do not warn if exists.
|
-f --force Do not warn if exists.
|
||||||
-V --verbose Be verbose.
|
-V --verbose Be verbose.
|
||||||
@@ -94,9 +94,10 @@ def install(opts, conf, temporary=False, keys=[]):
|
|||||||
if temporary:
|
if temporary:
|
||||||
tmpdir = get_tmpdir()
|
tmpdir = get_tmpdir()
|
||||||
inst = Installer(create=opts['create'], backup=opts['backup'],
|
inst = Installer(create=opts['create'], backup=opts['backup'],
|
||||||
dry=opts['dry'], safe=opts['safe'], base=opts['dotpath'],
|
dry=opts['dry'], safe=opts['safe'],
|
||||||
workdir=opts['workdir'], diff=opts['installdiff'],
|
base=opts['dotpath'], workdir=opts['workdir'],
|
||||||
debug=opts['debug'], totemp=tmpdir)
|
diff=opts['installdiff'], debug=opts['debug'],
|
||||||
|
totemp=tmpdir, showdiff=opts['showdiff'])
|
||||||
installed = []
|
installed = []
|
||||||
for dotfile in dotfiles:
|
for dotfile in dotfiles:
|
||||||
preactions = []
|
preactions = []
|
||||||
@@ -361,6 +362,7 @@ def main():
|
|||||||
opts['link'] = args['--link']
|
opts['link'] = args['--link']
|
||||||
opts['debug'] = args['--verbose']
|
opts['debug'] = args['--verbose']
|
||||||
opts['variables'] = conf.get_variables()
|
opts['variables'] = conf.get_variables()
|
||||||
|
opts['showdiff'] = opts['showdiff'] or args['--showdiff']
|
||||||
|
|
||||||
if opts['debug']:
|
if opts['debug']:
|
||||||
LOG.dbg('config file: {}'.format(args['--cfg']))
|
LOG.dbg('config file: {}'.format(args['--cfg']))
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class Installer:
|
|||||||
|
|
||||||
def __init__(self, base='.', create=True, backup=True,
|
def __init__(self, base='.', create=True, backup=True,
|
||||||
dry=False, safe=False, workdir='~/.config/dotdrop',
|
dry=False, safe=False, workdir='~/.config/dotdrop',
|
||||||
debug=False, diff=True, totemp=None):
|
debug=False, diff=True, totemp=None, showdiff=False):
|
||||||
self.create = create
|
self.create = create
|
||||||
self.backup = backup
|
self.backup = backup
|
||||||
self.dry = dry
|
self.dry = dry
|
||||||
@@ -30,6 +30,7 @@ class Installer:
|
|||||||
self.debug = debug
|
self.debug = debug
|
||||||
self.diff = diff
|
self.diff = diff
|
||||||
self.totemp = totemp
|
self.totemp = totemp
|
||||||
|
self.showdiff = showdiff
|
||||||
self.comparing = False
|
self.comparing = False
|
||||||
self.action_executed = False
|
self.action_executed = False
|
||||||
self.log = Logger()
|
self.log = Logger()
|
||||||
@@ -125,7 +126,7 @@ class Installer:
|
|||||||
self.log.err('source dotfile does not exist: {}'.format(src))
|
self.log.err('source dotfile does not exist: {}'.format(src))
|
||||||
return []
|
return []
|
||||||
st = os.stat(src)
|
st = os.stat(src)
|
||||||
ret = self._write(dst, content, st.st_mode, actions=actions)
|
ret = self._write(src, dst, content, st.st_mode, actions=actions)
|
||||||
if ret < 0:
|
if ret < 0:
|
||||||
self.log.err('installing {} to {}'.format(src, dst))
|
self.log.err('installing {} to {}'.format(src, dst))
|
||||||
return []
|
return []
|
||||||
@@ -164,7 +165,7 @@ class Installer:
|
|||||||
cur = f.read()
|
cur = f.read()
|
||||||
return cur == content
|
return cur == content
|
||||||
|
|
||||||
def _write(self, dst, content, rights, actions=[]):
|
def _write(self, src, dst, content, rights, actions=[]):
|
||||||
"""write content to file
|
"""write content to file
|
||||||
return 0 for success,
|
return 0 for success,
|
||||||
1 when already exists
|
1 when already exists
|
||||||
@@ -178,9 +179,17 @@ class Installer:
|
|||||||
if self.debug:
|
if self.debug:
|
||||||
self.log.dbg('{} is the same'.format(dst))
|
self.log.dbg('{} is the same'.format(dst))
|
||||||
return 1
|
return 1
|
||||||
if self.safe and not self.log.ask('Overwrite \"{}\"'.format(dst)):
|
if self.safe:
|
||||||
self.log.warn('ignoring {}, already present'.format(dst))
|
if self.debug:
|
||||||
return 1
|
self.log.dbg('change detected for {}'.format(dst))
|
||||||
|
if self.showdiff:
|
||||||
|
comp = Comparator(debug=self.debug)
|
||||||
|
diff = comp.compare(src, dst)
|
||||||
|
self.log.log('diff \"{}\" VS \"{}\"'.format(src, dst))
|
||||||
|
self.log.emph(diff)
|
||||||
|
if not self.log.ask('Overwrite \"{}\"'.format(dst)):
|
||||||
|
self.log.warn('ignoring {}'.format(dst))
|
||||||
|
return 1
|
||||||
if self.backup and os.path.lexists(dst):
|
if self.backup and os.path.lexists(dst):
|
||||||
self._backup(dst)
|
self._backup(dst)
|
||||||
base = os.path.dirname(dst)
|
base = os.path.dirname(dst)
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ def load_config(confpath, profile):
|
|||||||
opts['safe'] = True
|
opts['safe'] = True
|
||||||
opts['installdiff'] = True
|
opts['installdiff'] = True
|
||||||
opts['link'] = False
|
opts['link'] = False
|
||||||
|
opts['showdiff'] = True
|
||||||
opts['debug'] = True
|
opts['debug'] = True
|
||||||
opts['dopts'] = ''
|
opts['dopts'] = ''
|
||||||
opts['variables'] = {}
|
opts['variables'] = {}
|
||||||
|
|||||||
@@ -174,6 +174,7 @@ exec bspwm
|
|||||||
conf, opts = load_config(confpath, profile)
|
conf, opts = load_config(confpath, profile)
|
||||||
opts['safe'] = False
|
opts['safe'] = False
|
||||||
opts['debug'] = True
|
opts['debug'] = True
|
||||||
|
opts['showdiff'] = True
|
||||||
opts['variables'] = {}
|
opts['variables'] = {}
|
||||||
install(opts, conf)
|
install(opts, conf)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user