mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-07 22:39:17 +00:00
Add support for importing dotfiles as links
This commit is contained in:
@@ -87,7 +87,7 @@ class Cfg:
|
|||||||
return absconf
|
return absconf
|
||||||
return dotpath
|
return dotpath
|
||||||
|
|
||||||
def new(self, dotfile, profile):
|
def new(self, dotfile, profile, link=False):
|
||||||
""" import new dotfile """
|
""" import new dotfile """
|
||||||
dots = self.content[self.key_dotfiles]
|
dots = self.content[self.key_dotfiles]
|
||||||
if dots is None:
|
if dots is None:
|
||||||
@@ -103,6 +103,8 @@ class Cfg:
|
|||||||
self.key_dotfiles_dst: dotfile.dst,
|
self.key_dotfiles_dst: dotfile.dst,
|
||||||
self.key_dotfiles_src: dotfile.src
|
self.key_dotfiles_src: dotfile.src
|
||||||
}
|
}
|
||||||
|
if link:
|
||||||
|
dots[dotfile.key][self.key_dotfiles_link] = True
|
||||||
profiles = self.profiles
|
profiles = self.profiles
|
||||||
if profile in profiles and profiles[profile] != [self.key_all]:
|
if profile in profiles and profiles[profile] != [self.key_all]:
|
||||||
if self.content[self.key_profiles][profile] is None:
|
if self.content[self.key_profiles][profile] is None:
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ Usage:
|
|||||||
[(-f | --force)] [--nodiff] [--dry]
|
[(-f | --force)] [--nodiff] [--dry]
|
||||||
dotdrop.py compare [--profile=<profile>] [--cfg=<path>]
|
dotdrop.py compare [--profile=<profile>] [--cfg=<path>]
|
||||||
dotdrop.py list [--cfg=<path>]
|
dotdrop.py list [--cfg=<path>]
|
||||||
dotdrop.py import [--cfg=<path>] [--profile=<profile>] [--dry] <paths>...
|
dotdrop.py import [(-l | --link)] [--cfg=<path>] [--profile=<profile>] [--dry] <paths>...
|
||||||
dotdrop.py (-h | --help)
|
dotdrop.py (-h | --help)
|
||||||
dotdrop.py (-v | --version)
|
dotdrop.py (-v | --version)
|
||||||
|
|
||||||
@@ -43,6 +43,7 @@ Options:
|
|||||||
--cfg=<path> Path to the config [default: %s/config.yaml].
|
--cfg=<path> Path to the config [default: %s/config.yaml].
|
||||||
--dry Dry run.
|
--dry Dry run.
|
||||||
--nodiff Do not diff when installing [default: False].
|
--nodiff Do not diff when installing [default: False].
|
||||||
|
-l --link Import the file and add a link to it [default: False].
|
||||||
-f --force Do not warn if exists [default: False].
|
-f --force Do not warn if exists [default: False].
|
||||||
-v --version Show version.
|
-v --version Show version.
|
||||||
-h --help Show this screen.
|
-h --help Show this screen.
|
||||||
@@ -101,8 +102,7 @@ def importer(opts, conf, paths):
|
|||||||
key = dst.split(os.sep)[-1]
|
key = dst.split(os.sep)[-1]
|
||||||
if key == 'config':
|
if key == 'config':
|
||||||
key = '_'.join(dst.split(os.sep)[-2:])
|
key = '_'.join(dst.split(os.sep)[-2:])
|
||||||
key = key.lstrip('.')
|
key = key.lstrip('.').lower()
|
||||||
key = key.lower()
|
|
||||||
if os.path.isdir(dst):
|
if os.path.isdir(dst):
|
||||||
key = 'd_%s' % (key)
|
key = 'd_%s' % (key)
|
||||||
else:
|
else:
|
||||||
@@ -116,17 +116,22 @@ def importer(opts, conf, paths):
|
|||||||
if os.path.exists(srcf):
|
if os.path.exists(srcf):
|
||||||
LOG.err('\"%s\" already exists, ignored !' % (srcf))
|
LOG.err('\"%s\" already exists, ignored !' % (srcf))
|
||||||
continue
|
continue
|
||||||
conf.new(dotfile, opts['profile'])
|
conf.new(dotfile, opts['profile'], opts['link'])
|
||||||
cmd = ['mkdir', '-p', '%s' % (os.path.dirname(srcf))]
|
cmd = ['mkdir', '-p', '%s' % (os.path.dirname(srcf))]
|
||||||
if opts['dry']:
|
if opts['dry']:
|
||||||
LOG.dry('would run: %s' % (' '.join(cmd)))
|
LOG.dry('would run: %s' % (' '.join(cmd)))
|
||||||
else:
|
else:
|
||||||
utils.run(cmd, raw=False, log=False)
|
utils.run(cmd, raw=False, log=False)
|
||||||
cmd = ['cp', '-r', '%s' % (dst), '%s' % (srcf)]
|
if opts['link']:
|
||||||
|
cmd = ['mv', '%s' % (dst), '%s' % (srcf)]
|
||||||
|
else:
|
||||||
|
cmd = ['cp', '-r', '%s' % (dst), '%s' % (srcf)]
|
||||||
if opts['dry']:
|
if opts['dry']:
|
||||||
LOG.dry('would run: %s' % (' '.join(cmd)))
|
LOG.dry('would run: %s' % (' '.join(cmd)))
|
||||||
else:
|
else:
|
||||||
utils.run(cmd, raw=False, log=False)
|
utils.run(cmd, raw=False, log=False)
|
||||||
|
if opts['link']:
|
||||||
|
os.symlink(srcf, dst)
|
||||||
LOG.sub('\"%s\" imported' % (path))
|
LOG.sub('\"%s\" imported' % (path))
|
||||||
cnt += 1
|
cnt += 1
|
||||||
if opts['dry']:
|
if opts['dry']:
|
||||||
@@ -159,6 +164,7 @@ if __name__ == '__main__':
|
|||||||
opts['profile'] = args['--profile']
|
opts['profile'] = args['--profile']
|
||||||
opts['safe'] = not args['--force']
|
opts['safe'] = not args['--force']
|
||||||
opts['installdiff'] = not args['--nodiff']
|
opts['installdiff'] = not args['--nodiff']
|
||||||
|
opts['link'] = args['--link']
|
||||||
|
|
||||||
header()
|
header()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user