Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Manually specify key/dodrop-location #220

Closed
pheerai opened this issue Apr 6, 2020 · 10 comments
Closed

[feature] Manually specify key/dodrop-location #220

pheerai opened this issue Apr 6, 2020 · 10 comments
Labels

Comments

@pheerai
Copy link

pheerai commented Apr 6, 2020

First of: Thanks for your work on this great tool!

Now for the Feature Request:

Situation

I have a profile for my servers, and one for my desktop machines, both of which require a specific file f in the same location.
The content for the profiles is almost non-overlapping.

What I'd like to do

My proposal would be a command for importing files somewhat like this:

dotdrop [...] --as=~/.config/file_profile import ~/.config/file

E.g. introducing an argument to tell dotdrop to import a file "as if it was named differently".

This should:

  • Copy/link ~/.config/file to $DOTDIR/config/file_profile
  • Generate a dotfile-entry in the dotfile-config:
    f_file_profile:
      src: config/file_profile
      dst: ~/.config/file
    
  • Add the key to the profile

What I currently do

Either I generate a templated dotfile (tedious), or I copy the second file manually to some different location in my repo and modify the config by hand (say, I have f from profile S imported as f, then I'd manually create a file f_D as well as a corresponding key and dotfile entry for profile D).

@pheerai pheerai added the feature label Apr 6, 2020
@deadc0de6
Copy link
Owner

That should be doable, I'll look into that and keep you updated.

deadc0de6 added a commit that referenced this issue Apr 11, 2020
@deadc0de6
Copy link
Owner

This was more complex than expected (avoid duplicates, multiple dotfiles with same destination, etc) but I think I have something in branch import-as. Could you give it a try and let me know what you think?

The new feature should allow you to do:

./dotdrop.sh import ~/.config/file --as=~/.config/file_profile 

@pheerai
Copy link
Author

pheerai commented Apr 12, 2020

Looks good 👍

The only thing irritating me a bit (though no deal breaker): It seems as if handling of path expansion (e.g when calling --as=~/.foo_test) is different than with the regular import command. Usually, the tilde get's stripped away. With above option set it will generate a directory ~ in the dotdrop file hierarchy.

@deadc0de6
Copy link
Owner

I don't get the same behavior as you (see below), can you give me a complete example where that fails?

$ touch ~/.dotdrop.test
$ ./dotdrop.sh import ~/.dotdrop.test --as ~/.dotdrop.test2 
	-> "/home/user/.dotdrop.test" imported
$ cat config.yaml               
config:
  backup: true
  banner: true
  create: true
  dotpath: dotfiles
  keepdot: false
  link_dotfile_default: nolink
  link_on_import: nolink
  longkey: false
dotfiles:
  f_dotdrop.test:
    src: dotdrop.test2
    dst: ~/.dotdrop.test
profiles:
  hostname:
    dotfiles:
    - f_dotdrop.test
$ tree dotfiles        
dotfiles
└── dotdrop.test2

@pheerai
Copy link
Author

pheerai commented Apr 13, 2020

Can you retry with long keys enabled, please? I guess that might cause the issue.

@deadc0de6
Copy link
Owner

nope, same behavior:

$ ./dotdrop.sh import ~/.dotdrop.test --as ~/.dotdrop.test2 
	-> "/home/user/.dotdrop.test" imported

1 file(s) imported.
$ cat config.yaml 
config:
  backup: true
  banner: true
  create: true
  dotpath: dotfiles
  keepdot: false
  link_dotfile_default: nolink
  link_on_import: nolink
  longkey: true
dotfiles:
  f_dotdrop.test:
    src: dotdrop.test2
    dst: ~/.dotdrop.test
profiles:
  hostname:
    dotfiles:
    - f_dotdrop.test
$ tree dotfiles 
dotfiles
└── dotdrop.test2

I have also tested with keepdot and subdirectory or files within a directory in home, they all end up with the correct behavior.

You can't reproduce above issue?

@pheerai
Copy link
Author

pheerai commented Apr 14, 2020

Sorry for the delay. Yes, I can reproduce the issue locally.

Here's the head of my dotdrop-config:

dotdrop.yaml
config:
  backup: true
  banner: true
  create: true
  dotpath: ~/.dot/dotfiles
  workdir: ~/.config/dotdrop/
  keepdot: false
  link_dotfile_default: nolink
  link_on_import: nolink
  longkey: true
  minversion: 0.32.0
dotfiles:
  [...]

my versions:

  • python: 3.8.2
  • dotdrop: from branch, locally sourced
  • jinja: 2.11.2
  • docopt: 0.6.2
  • ruamel-yaml: 0.16.10

When I issue

$HOME/.dot/dotdrop/dotdrop.sh -b -c ~/.dot/dotfiles/config/dotdrop/config.yaml import -p test --as=~/.zshrc.test ~/.zshrc

this is the resulting diff of the config:

Git dotdrop config diff
diff --git a/dotfiles/config/dotdrop/config.yaml b/dotfiles/config/dotdrop/config.yaml
index 2bd1521..b551cb8 100644
--- a/dotfiles/config/dotdrop/config.yaml
+++ b/dotfiles/config/dotdrop/config.yaml
@@ -89,6 +89,9 @@ dotfiles:
   f_zshrc.pre:
     src: zshrc.pre
     dst: ~/.zshrc.pre
+  f_zshrc_1:
+    src: dot/dotdrop/~/.zshrc.test
+    dst: ~/.zshrc
 profiles:
   pheerai:
     include:
@@ -143,3 +146,6 @@ profiles:
     - f_config_vdirsyncer_config
     - f_config_khal_config
     - f_config_khard_khard.conf
+  test:
+    dotfiles:
+    - f_zshrc_1

As you can see, this results in a src-entry containing a folder with name ~. Also, I'm a bit confused about the dot/dotfiles-repository that gets generated, shouldn't the entry be src: zshrc.test?

deadc0de6 added a commit that referenced this issue Apr 14, 2020
@deadc0de6
Copy link
Owner

Yeah it should and above commit should have fixed that. Thanks for pointing that out!

@pheerai
Copy link
Author

pheerai commented Apr 15, 2020

Works like charm, thank you!

@deadc0de6 deadc0de6 mentioned this issue Apr 16, 2020
@deadc0de6
Copy link
Owner

This was merged into master and will be available on pypi on the next release. Thanks again for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants