mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-16 12:16:11 +00:00
provide an option to install all dotfiles to a temporary directory
This commit is contained in:
37
README.md
37
README.md
@@ -272,6 +272,10 @@ $ dotdrop.sh compare
|
|||||||
The diffing is done by diff in the backend, one can provide specific
|
The diffing is done by diff in the backend, one can provide specific
|
||||||
options to diff using the `-o` switch.
|
options to diff using the `-o` switch.
|
||||||
|
|
||||||
|
It is also possible to install all dotfiles for a specific profile
|
||||||
|
in a temporary directory in order to manually compare them with
|
||||||
|
the local version by using `install` and the `-t` switch.
|
||||||
|
|
||||||
## Import dotfiles
|
## Import dotfiles
|
||||||
|
|
||||||
Dotdrop allows to import dotfiles directly from the
|
Dotdrop allows to import dotfiles directly from the
|
||||||
@@ -477,16 +481,37 @@ $ sudo pip3 install dotdrop --upgrade
|
|||||||
## Update dotfiles
|
## Update dotfiles
|
||||||
|
|
||||||
Dotfiles managed by dotdrop can be updated using the `update` command.
|
Dotfiles managed by dotdrop can be updated using the `update` command.
|
||||||
|
|
||||||
There are two cases:
|
There are two cases:
|
||||||
|
|
||||||
* the dotfile doesn't use [templating](#template): the new version of the dotfile is copied to the
|
**The dotfile doesn't use [templating](#template)**
|
||||||
*dotfiles* directory and overwrites the old version. If git is used to version the dotfiles stored
|
|
||||||
by dotdrop, the git command `diff` can be used to view the changes.
|
|
||||||
* the dotfile uses [templating](#template): the dotfile must be manually updated, the use of
|
|
||||||
the dotdrop command `compare` can be helpful to identify the changes to apply to the template.
|
|
||||||
|
|
||||||
```
|
The new version of the dotfile is copied to the *dotfiles* directory and overwrites
|
||||||
|
the old version. If git is used to version the dotfiles stored by dotdrop, the git command
|
||||||
|
`diff` can be used to view the changes.
|
||||||
|
|
||||||
|
```bash
|
||||||
$ dotdrop.sh update ~/.vimrc
|
$ dotdrop.sh update ~/.vimrc
|
||||||
|
$ git diff
|
||||||
|
```
|
||||||
|
|
||||||
|
**The dotfile uses [templating](#template)**
|
||||||
|
|
||||||
|
The dotfile must be manually updated, two solutions can be used to identify the
|
||||||
|
changes to apply to the template:
|
||||||
|
|
||||||
|
* Use dotdrop's `compare` command
|
||||||
|
* Install the dotfiles to a temporary directory (using the `install` command and the
|
||||||
|
`-t` switch) and compare the generated dotfile with the local one.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# use compare to identify change(s)
|
||||||
|
$ ./dotdrop.sh compare --files=~/.vimrc
|
||||||
|
|
||||||
|
# use install to identify change(s)
|
||||||
|
$ ./dotdrop.sh install -t
|
||||||
|
Installed to tmp /tmp/dotdrop-6kix7555
|
||||||
|
$ diff ~/.vimrc /tmp/dotdrop-6kix7555/home/user/.vimrc
|
||||||
```
|
```
|
||||||
|
|
||||||
## Store sensitive dotfiles
|
## Store sensitive dotfiles
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ USAGE = """
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
dotdrop install [-fndVb] [-c <path>] [-p <profile>]
|
dotdrop install [-tfndVb] [-c <path>] [-p <profile>]
|
||||||
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>] [-i <name>...]
|
||||||
@@ -59,6 +59,7 @@ Options:
|
|||||||
-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.
|
||||||
-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.
|
||||||
@@ -74,7 +75,7 @@ Options:
|
|||||||
###########################################################
|
###########################################################
|
||||||
|
|
||||||
|
|
||||||
def install(opts, conf):
|
def install(opts, conf, temporary=False):
|
||||||
"""install all dotfiles for this profile"""
|
"""install all dotfiles for this profile"""
|
||||||
dotfiles = conf.get_dotfiles(opts['profile'])
|
dotfiles = conf.get_dotfiles(opts['profile'])
|
||||||
if dotfiles == []:
|
if dotfiles == []:
|
||||||
@@ -83,10 +84,13 @@ def install(opts, conf):
|
|||||||
return False
|
return False
|
||||||
t = Templategen(opts['profile'], base=opts['dotpath'],
|
t = Templategen(opts['profile'], base=opts['dotpath'],
|
||||||
variables=opts['variables'], debug=opts['debug'])
|
variables=opts['variables'], debug=opts['debug'])
|
||||||
|
tmpdir = None
|
||||||
|
if temporary:
|
||||||
|
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'], base=opts['dotpath'],
|
||||||
workdir=opts['workdir'], diff=opts['installdiff'],
|
workdir=opts['workdir'], diff=opts['installdiff'],
|
||||||
debug=opts['debug'])
|
debug=opts['debug'], totemp=tmpdir)
|
||||||
installed = []
|
installed = []
|
||||||
for dotfile in dotfiles:
|
for dotfile in dotfiles:
|
||||||
if dotfile.actions and Cfg.key_actions_pre in dotfile.actions:
|
if dotfile.actions and Cfg.key_actions_pre in dotfile.actions:
|
||||||
@@ -126,6 +130,8 @@ def install(opts, conf):
|
|||||||
LOG.dbg('executing post action {}'.format(action))
|
LOG.dbg('executing post action {}'.format(action))
|
||||||
action.execute()
|
action.execute()
|
||||||
installed.extend(r)
|
installed.extend(r)
|
||||||
|
if temporary:
|
||||||
|
LOG.log('\nInstalled to tmp {}.'.format(tmpdir))
|
||||||
LOG.log('\n{} dotfile(s) installed.'.format(len(installed)))
|
LOG.log('\n{} dotfile(s) installed.'.format(len(installed)))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -154,7 +160,6 @@ def apply_trans(opts, dotfile):
|
|||||||
|
|
||||||
|
|
||||||
def _select(selections, dotfiles):
|
def _select(selections, dotfiles):
|
||||||
ret = True
|
|
||||||
selected = []
|
selected = []
|
||||||
for selection in selections:
|
for selection in selections:
|
||||||
df = next(
|
df = next(
|
||||||
@@ -166,8 +171,7 @@ def _select(selections, dotfiles):
|
|||||||
selected.append(df)
|
selected.append(df)
|
||||||
else:
|
else:
|
||||||
LOG.err('no dotfile matches \"{}\"'.format(selection))
|
LOG.err('no dotfile matches \"{}\"'.format(selection))
|
||||||
ret = False
|
return selected
|
||||||
return selected, ret
|
|
||||||
|
|
||||||
|
|
||||||
def compare(opts, conf, tmp, focus=None, ignore=[]):
|
def compare(opts, conf, tmp, focus=None, ignore=[]):
|
||||||
@@ -181,7 +185,7 @@ def compare(opts, conf, tmp, focus=None, ignore=[]):
|
|||||||
same = True
|
same = True
|
||||||
selected = dotfiles
|
selected = dotfiles
|
||||||
if focus:
|
if focus:
|
||||||
selected, ret = _select(focus.replace(' ', '').split(','), dotfiles)
|
selected = _select(focus.replace(' ', '').split(','), dotfiles)
|
||||||
|
|
||||||
if len(selected) < 1:
|
if len(selected) < 1:
|
||||||
return False
|
return False
|
||||||
@@ -362,13 +366,14 @@ def main():
|
|||||||
|
|
||||||
elif args['install']:
|
elif args['install']:
|
||||||
# install the dotfiles stored in dotdrop
|
# install the dotfiles stored in dotdrop
|
||||||
ret = install(opts, conf)
|
ret = install(opts, conf, temporary=args['--temp'])
|
||||||
|
|
||||||
elif args['compare']:
|
elif args['compare']:
|
||||||
# compare local dotfiles with dotfiles stored in dotdrop
|
# compare local dotfiles with dotfiles stored in dotdrop
|
||||||
tmp = get_tmpdir()
|
tmp = get_tmpdir()
|
||||||
opts['dopts'] = args['--dopts']
|
opts['dopts'] = args['--dopts']
|
||||||
ret = compare(opts, conf, tmp, args['--files'], args['--ignore'])
|
ret = compare(opts, conf, tmp, focus=args['--files'],
|
||||||
|
ignore=args['--ignore'])
|
||||||
if os.listdir(tmp):
|
if os.listdir(tmp):
|
||||||
LOG.raw('\ntemporary files available under {}'.format(tmp))
|
LOG.raw('\ntemporary files available under {}'.format(tmp))
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -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):
|
debug=False, diff=True, totemp=None):
|
||||||
self.create = create
|
self.create = create
|
||||||
self.backup = backup
|
self.backup = backup
|
||||||
self.dry = dry
|
self.dry = dry
|
||||||
@@ -29,6 +29,7 @@ class Installer:
|
|||||||
self.base = base
|
self.base = base
|
||||||
self.debug = debug
|
self.debug = debug
|
||||||
self.diff = diff
|
self.diff = diff
|
||||||
|
self.totemp = totemp
|
||||||
self.comparing = False
|
self.comparing = False
|
||||||
self.log = Logger()
|
self.log = Logger()
|
||||||
|
|
||||||
@@ -36,6 +37,8 @@ class Installer:
|
|||||||
"""install the src to dst using a template"""
|
"""install the src to dst using a template"""
|
||||||
src = os.path.join(self.base, os.path.expanduser(src))
|
src = os.path.join(self.base, os.path.expanduser(src))
|
||||||
dst = os.path.expanduser(dst)
|
dst = os.path.expanduser(dst)
|
||||||
|
if self.totemp:
|
||||||
|
dst = self._pivot_path(dst, self.totemp)
|
||||||
if utils.samefile(src, dst):
|
if utils.samefile(src, dst):
|
||||||
# symlink loop
|
# symlink loop
|
||||||
self.log.err('dotfile points to itself: {}'.format(dst))
|
self.log.err('dotfile points to itself: {}'.format(dst))
|
||||||
@@ -50,6 +53,8 @@ class Installer:
|
|||||||
"""set src as the link target of dst"""
|
"""set src as the link target of dst"""
|
||||||
src = os.path.join(self.base, os.path.expanduser(src))
|
src = os.path.join(self.base, os.path.expanduser(src))
|
||||||
dst = os.path.expanduser(dst)
|
dst = os.path.expanduser(dst)
|
||||||
|
if self.totemp:
|
||||||
|
return self.install(templater, src, dst)
|
||||||
|
|
||||||
if Templategen.is_template(src):
|
if Templategen.is_template(src):
|
||||||
if self.debug:
|
if self.debug:
|
||||||
|
|||||||
Reference in New Issue
Block a user