twpayne / chezmoi

Manage your dotfiles across multiple diverse machines, securely.
https://www.chezmoi.io/
MIT License
13.32k stars 493 forks source link

using chezmoiignore #1237

Closed richukuttan closed 2 years ago

richukuttan commented 3 years ago

What exactly are you trying to do?

Ignore the bitwarden config file (~/.config/Bitwarden\ CLI/*)

What have you tried so far?

Attempt 1: Add ".config/Bitwarden\ CLI/*" to $(chezmoi source-path)/.chezmoiignore Attempt 2: Add ".config/Bitwarden\ CLI/**" to $(chezmoi source-path)/.chezmoiignore Attempt 3: Add ".config/Bitwarden\ CLI/**/*" to $(chezmoi source-path)/.chezmoiignore Attempt 4: Add ".config/Bitwarden\ CLI/**/*" to $(chezmoi source-path)/.chezmoiignore Attempt 4: Add ".config/**" to $(chezmoi source-path)/.chezmoiignore Attempt 5: Add "private_dot_config/private_Bitwarden\ CLI/*" to $(chezmoi source-path)/.chezmoiignore Attempt 6: Add private_dot_config/private_Bitwarden\ CLI/**" to $(chezmoi source-path)/.chezmoiignore Attempt 7: Add private_dot_config/private_Bitwarden\ CLI/**/*" to $(chezmoi source-path)/.chezmoiignore

Where else have you checked for solutions?

Output of any commands you've tried with --verbose

$ chezmoi add .config --verbose
...
diff --git a/private_dot_config b/private_dot_config
new file mode 40755
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
--- /dev/null
+++ b/private_dot_config
diff --git a/private_dot_config/private_Bitwarden CLI b/private_dot_config/private_Bitwarden CLI
new file mode 40755
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
--- /dev/null
+++ b/private_dot_config/private_Bitwarden CLI
diff --git a/private_dot_config/private_Bitwarden CLI/private_data.json b/private_dot_config/private_Bitwarden CLI/private_data.json
new file mode 100644
index 0000000000000000000000000000000000000000..c42e5f26ade1c27b623d2bda58fcc3a918715866
--- /dev/null
+++ b/private_dot_config/private_Bitwarden CLI/private_data.json
<contents of the file>
...

Output of chezmoi doctor

$ chezmoi doctor
RESULT   CHECK                MESSAGE
ok       version              v2.0.12, commit 2256a83c51b97f4a326feb66fd3ebdc3f1833a15, built at 2021-05-10T22:46:04Z, built by goreleaser
ok       os-arch              linux/amd64
info     config-file          /home/hrishi/.config/chezmoi/chezmoi.toml does not exist
ok       source-dir           /home/hrishi/.local/share/chezmoi is a directory
ok       suspicious-entries   no suspicious entries found in /home/hrishi/.local/share/chezmoi
ok       dest-dir             /home/hrishi is a directory
ok       shell                found /usr/bin/fish
ok       editor               found /usr/bin/vi
ok       git-cli              found /usr/bin/git, version 2.31.1
ok       merge-cli            found /usr/bin/vimdiff
ok       age-cli              age not found in $PATH
ok       gnupg-cli            found /usr/bin/gpg, version 2.2.27
info     1password-cli        op not found in $PATH
ok       bitwarden-cli        found /home/hrishi/bin/bw, version 1.16.0
info     gopass-cli           gopass not found in $PATH
info     keepassxc-cli        keepassxc-cli not found in $PATH
info     keepassxc-db         not set
info     lastpass-cli         lpass not found in $PATH
info     pass-cli             pass not found in $PATH
info     vault-cli            vault not found in $PATH
info     secret-cli           not set
twpayne commented 3 years ago

It's not necessary to escape the space with \. Try:

.config/Bitwarden CLI
.config/Bitwarden CLI/**

to ignore the .config/Bitwarden CLI directory and everything in it.

richukuttan commented 3 years ago

That doesn't work either. Unlike the output of 721, I do not see any warning about files being skipped either.

Since I'm just starting to create my dotfiles, I'm trying to get this right by removing the local chezmoi folder and reinitializing it. This is what I'm doing to check:

`

rm -rf ~/.local/share/chezmoi chezmoi init echo ".config/Bitwarden CLI/" > $(chezmoi source-path)/.chezmoiignore echo ".config/Bitwarden CLI/**" >> $(chezmoi source-path)/.chezmoiignore cat $(chezmoi source-path)/.chezmoiignore .config/Bitwarden CLI/ .config/Bitwarden CLI/** chezmoi add .config ls private_dot_config/private_Bitwarden\ CLI/ | wc -l 1 `

This gives me one file in the folder. Is there some other config that saves the previous state of the bitwarden file and rewrites it when it doesn't see it? Or a better way to clean chezmoi?

(Please note that I don't actually type in the $ signs above, since I'm using fish. I just added them in to make the syntax more readable)

twpayne commented 3 years ago

Thanks for testing, I'll try to reproduce the problem locally.

This gives me one file in the folder. Is there some other config that saves the previous state of the bitwarden file and rewrites it when it doesn't see it? Or a better way to clean chezmoi?

Yes. You can use create_ files for this. They're not well documented but they do work. If you add a file called create_dot_file with some contents in your source directory then chezmoi will create a file called .file in the target directory with those contents if .file doesn't already exist, or leave .file untouched if it already exists.

gotgenes commented 3 years ago

I had a similar question. I'm trying to prevent chezmoi add ~/.config/nvim from including ~/.config/nvim/plugin/packer_compiled.lua. I tried adding .config/nvim/plugin/packer_compiled.lua to my .chezmoiignore (located at ~/.local/share/chezmoi/.chezmoiignore), and various other patterns using **/ globbing, however, none prevented chezmoi add from adding the file into the source directory.

I tried a simpler case of putting foo in the .chezmoiignore and adding a foo file to my home directory. chezmoi add foo still added foo to the source directory, with no warning or complaints.

I understand from #721 that .chezmoiignore was initially implemented for chezmoi apply, however, a mechanism to prevent chezmoi add from adding files to the source directory would be most welcome. Controlling the chezmoi add behavior is what I initially expected. That would be analogous to .gitignore patterns preventing Git from adding changes from the working directory to the index. The actual behavior right now is more like the converse of .gitignore: it would be like if .gitignore prevented Git from overwriting the working directory contents with contents of the index.

I need the existing behavior of .chezmoiignore, for example, to prevent chezmoi from copying my dotfiles repository's README.md into my home directory. I could also use a way to stop chezmoi add from adding certain files or directories from my home directory into the repository.

mhalano commented 3 years ago

I have the same feeling of @gotgenes. I want to add a directory, ~/.task/ and all the content, except some, well known, standards, like file *.data and the .git directory. My idea was Chezmoi used .chezmoiignore the same way as .gitignore, to avoid add the files to the repository.

nkgm commented 2 years ago

I could also use a way to stop chezmoi add from adding certain files or directories from my home directory into the repository.

This is something I'm sorely missing as well. I have a nodejs project living in its own directory in my dotfiles (for generating a certain kind of repetitive config) and right now I can't figure out a way to chezmoi add ~/.dotfiles without also copying node_modules taking several minutes in the process. Other than manually adding each and every file in .dotfiles, sidestepping node_modules, I opted to go for a full chezmoi add ~/.dotfiles, wait it out, create a .gitignore in the source directory, add/commit the files, then do a git clean -fX to get rid of the files that should have been ignored in the first place. Hopefully you only have to do this kind of thing once or twice so it's not all that bad, but it took me a lot of fiddling around with .chezmoiignore before realizing it was meant for something completely different and finding this issue.

twpayne commented 2 years ago

chezmoi add will not add files that are ignored by .chezmoiignore. There's a test for this. If you have observed different behavior, please give details.

nkgm commented 2 years ago

Please forgive any oversight as I'm new to chezmoi. My confusion partly stems from the fact I couldn't get it to work excluding directories. Here's an example:

.nkgm/dir/subdir/   # as suggested in docs/reference/#chezmoiignore examples
# or
**/subdir
$ tree .nkgm/dir
/Users/nkgm/.nkgm/dir
└── subdir
    └── file

$ chezmoi add ~/.nkgm/dir
chezmoi: /Users/nkgm/.nkgm/dir/subdir/file: parent directory not in source state

The problem goes away for:

**/subdir
**/subdir/*

... which feels counterintuitive. We should clarify if this is intended behavior, and amend the docs accordingly.

Edit:

To exclude node_modules and avoid the parent directory not in source state error I actually have to use:

**/node_modules
**/node_modules/**/*

which I guess should come as no surprise as the nesting is several levels deep. Even though it does the right thing in the end, it does feel like chezmoi is doing some unnecessary processing traversing the excluded directories introducing a long delay in the process.

twpayne commented 2 years ago

1942 adds an explicit test for the issue reported here, and passes on all operating systems. So, closing this for now. Please re-open if needed.