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

New feature: copy/initialize a file instead of linking #355

Open
denilsonsa opened this issue Feb 14, 2024 · 1 comment
Open

New feature: copy/initialize a file instead of linking #355

denilsonsa opened this issue Feb 14, 2024 · 1 comment

Comments

@denilsonsa
Copy link

denilsonsa commented Feb 14, 2024

The problem

With the current capabilities of dotbot, I can have a ~/.vim/vimrc file in my dotfiles, and dotbot will correctly create the link. Inside that file, I am sourcing another file ~/.vimrc/vimrc-local, which should contain local changes that should not be stored in the dotfiles. So far, so good.

However, the tricky part is initializing the -local file. It should have a certain structure, it should declare a few functions. In other words, there is some boilerplate it should have.

The proposed solution

I am proposing a new directive: skel (or initialize or seed or copy or copy_without_overwriting or… well, naming is hard!)

It would be declared in a similar way to the link directive, but instead of creating a symlink, it would just copy the file over there. Look:

- link:
    '~/.vim/vimrc': 'base/.vim/vimrc'
- skel:
    '~/.vim/vimrc-local': 'base/.vim/vimrc-local'

On a fresh machine, the outcome would be:

  • ~/.vim/vimrc~/dotfiles/base/.vim/vimrc (symlink)
  • ~/.vim/vimrc-local (regular file, copied from ~/dotfiles/base/.vim/vimrc)

On subsequent runs on the same machine:

  • ~/.vim/vimrc~/dotfiles/base/.vim/vimrc (the tool ensures the symlink is still correct)
  • ~/.vim/vimrc-local
    • If it still exists, it is not touched at all. It is assumed to have local changes.
    • If it doesn't exist, it is recreated (copied) from ~/dotfiles/base/.vim/vimrc

The proposed behavior reminds me of /etc/skel/.

Additional configuration

Maybe the name should be copy, and it should have the same configuration keys as link:

  • path
  • create parent directories as needed.
  • relink not relevant.
  • force overwrites the existing file. Dangerous, should be off by default, but maybe useful in some exotic configuration. (e.g. A separate YAML config could be used to "reset" a certain application configuration to a known state.)
  • canonicalize, if, ignore-missing
  • glob, exclude, prefix

Alternatives

  1. I keep the -local file in my dotfiles, and I have to remember to copy/create it manually.
  2. I keep the -local file in my dotfiles, and I add some custom shell directive to copy only if it doesn't exist.
  3. I can keep different versions of -local, one for each machine. Many people do that, but it is not desirable for files that contain sensitive information (such as API keys or tokens).
  4. Templating as requested in Templating support? #117. It has the same drawbacks as alternative 3, plus the additional complexity of requiring additional Python modules.

Compared to the alternatives, the skel/copy solution has the following advantages:

  • Automatic, I don't have to remember to copy it manually.
  • Clean configuration. I don't have to write shell script code inside an YAML file.
  • Easy to learn and easy to understand, as it is very similar to link.
  • Simple to implement, can be implemented using the standard library, should require no additional modules. In fact, most of the behavior would be identical to link.
denilsonsa added a commit to denilsonsa/dotfiles that referenced this issue Feb 14, 2024
This will be cleaner after this new feature gets implemented:
anishathalye/dotbot#355
@kurtmckee
Copy link
Contributor

Nice suggestion! I'm currently doing this with my shared git config:

- shell:
    - description: "Copy shared/git/gitconfig.ini to ~/.gitconfig (if needed)"
      command: >
        if [ ! -e ~/.gitconfig ]; then
            cp shared/git/gitconfig.ini ~/.gitconfig;
        fi
      quiet: true

A copy directive might be just the ticket in this situation.

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

No branches or pull requests

2 participants