Skip to content

Commit

Permalink
Add no_dot_prefix option
Browse files Browse the repository at this point in the history
This utility can easily be used for synchronizing arbitrary
configuration folders with symlinks that may not necessarily be the home
directory.  I have encountered several use cases where the files that
I want to manage with 'dotfiles' should not/can not be prefixed with
a '.'.

Fixes #47
  • Loading branch information
colonelpanic8 authored and jbernard committed Jan 13, 2015
1 parent 572a728 commit 201bec5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
5 changes: 5 additions & 0 deletions dotfiles/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ def add_global_flags(parser):
action="store_true", default=False,
help="don't modify anything, just print commands")

parser.add_option("-n", "--no-dot-prefix",
action="store_true", default=False,
help="don't prefix symlinks in target directory with a '.'")


def add_action_group(parser):
action_group = OptionGroup(parser, "Actions")
Expand Down Expand Up @@ -237,6 +241,7 @@ def main():
repo_config_opts.get('prefix') or
config_opts.get('prefix') or
repo_settings['prefix'])
repo_settings['no_dot_prefix'] = cli_opts.no_dot_prefix

update_settings(repo_config_opts, 'ignore')
update_settings(repo_config_opts, 'externals')
Expand Down
4 changes: 3 additions & 1 deletion dotfiles/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class Dotfiles(object):
'ignore': set(['.dotfilesrc']),
'homedir': os.path.expanduser('~/'),
'path': os.path.expanduser('~/Dotfiles'),
'no_dot_prefix': False
}

def __init__(self, **kwargs):
Expand Down Expand Up @@ -156,9 +157,10 @@ def _load_recursive(self, sub_dir=''):
if pkg_path in self.packages:
self._load_recursive(pkg_path)
else:
add_dot = False if self.no_dot_prefix else not bool(sub_dir)
self.dotfiles.append(Dotfile(dotfile[len(self.prefix):],
os.path.join(src_dir, dotfile), dst_dir,
add_dot=not bool(sub_dir), dry_run=self.dry_run))
add_dot=add_dot, dry_run=self.dry_run))

# Externals are top-level only
if not sub_dir:
Expand Down
21 changes: 20 additions & 1 deletion tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ def test_missing_package(self):

dotfiles.add([os.path.join(self.homedir, package_file)])


def test_single_sync(self):
"""
Test syncing a single file in the repo
Expand Down Expand Up @@ -361,6 +360,26 @@ def test_add_package(self):
dotfiles.add(['.config'])
self.assertFalse(os.path.islink(os.path.join(self.homedir, '.config')))

def test_no_dot_prefix(self):
# define the repository contents
repo_files = ('bashrc', 'netrc', 'vimrc')

# populate the repository
for dotfile in repo_files:
touch(os.path.join(self.repository, dotfile))

dotfiles = Dotfiles(
homedir=self.homedir, path=self.repository,
prefix='', ignore=[], externals={}, packages=[],
dry_run=False, no_dot_prefix=True)

dotfiles.sync()

# verify home directory contents
for dotfile in repo_files:
self.assertPathEqual(
os.path.join(self.repository, dotfile),
os.path.join(self.homedir, dotfile))

@pytest.mark.xfail()
def test_add_package_file(self):
Expand Down

0 comments on commit 201bec5

Please sign in to comment.