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

Trouble ignoring certain files #3780

Open
3 tasks done
lilHermit opened this issue May 27, 2024 · 5 comments
Open
3 tasks done

Trouble ignoring certain files #3780

lilHermit opened this issue May 27, 2024 · 5 comments
Labels
support Support request

Comments

@lilHermit
Copy link

lilHermit commented May 27, 2024

What exactly are you trying to do?

I have the following layout for my tmux config

ll ~/.config/tmux/ 
drwxrwxr-x     - : 2024-05-24 21:33 plugins
.rw-rw-r-- 2.6Ki : 2024-05-24 21:45 tmux.conf
.rw-rw-r-- 1.1Ki : 2024-05-24 21:33 tmux.reset.conf

and plugins contains

ll ~/.config/tmux/plugins
drwxrwxr-x - : 2024-05-24 21:31 tmux
drwxrwxr-x - : 2024-05-24 21:33 tmux-continuum
.... (trimmed for brevity)
drwxrwxr-x - : 2024-05-24 21:33 tmux-yank
drwxrwxr-x - : 2024-05-24 21:31 tpm

I want add the whole tmux directory and the tpm plugin but ignore any future plugins as they will be installed by tpm. That was it makes it more manageable.

What have you tried so far?

I've added the following ~/.local/share/chezmoi/.chezmoiignore

.config/tmux/plugins/*

!.config/tmux/plugins/tpm/
!.config/tmux/plugins/tpm/**

Describe what you have tried so far.

Where else have you checked for solutions?

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

The output of the add looks ok to me all plugins except tpm ignored however the managed command shows no files

chezmoi --verbose add -r ~/.config/tmux
chezmoi: warning: ignoring .config/tmux/plugins/tmux
chezmoi: warning: ignoring .config/tmux/plugins/tmux-continuum
chezmoi: warning: ignoring .config/tmux/plugins/tmux-floax
chezmoi: warning: ignoring .config/tmux/plugins/tmux-fzf
chezmoi: warning: ignoring .config/tmux/plugins/tmux-fzf-url
chezmoi: warning: ignoring .config/tmux/plugins/tmux-resurrect
chezmoi: warning: ignoring .config/tmux/plugins/tmux-sensible
chezmoi: warning: ignoring .config/tmux/plugins/tmux-sessionx
chezmoi: warning: ignoring .config/tmux/plugins/tmux-thumbs
chezmoi: warning: ignoring .config/tmux/plugins/tmux-yank
chezmoi: /home/scott/.config/tmux/plugins/tmux-continuum/.git: parent directory not in source statechezmoi --verbose managed | grep tmux

Adding files separately works

chezmoi --verbose add -r ~/.config/tmux/tmux.conf ~/.config/tmux/tmux.reset.conf
-- Removed file contents display --chezmoi --verbose managed | grep tmux
.config/tmux
.config/tmux/tmux.conf
.config/tmux/tmux.reset.conf

However I can't then add plugins (which I would expect to add the tpm folder) unless mt assumption is incorrect

chezmoi --verbose add -r ~/.config/tmux/plugins
chezmoi: warning: ignoring .config/tmux/plugins/tmux
chezmoi: warning: ignoring .config/tmux/plugins/tmux-continuum
chezmoi: warning: ignoring .config/tmux/plugins/tmux-floax
chezmoi: warning: ignoring .config/tmux/plugins/tmux-fzf
chezmoi: warning: ignoring .config/tmux/plugins/tmux-fzf-url
chezmoi: warning: ignoring .config/tmux/plugins/tmux-resurrect
chezmoi: warning: ignoring .config/tmux/plugins/tmux-sensible
chezmoi: warning: ignoring .config/tmux/plugins/tmux-sessionx
chezmoi: warning: ignoring .config/tmux/plugins/tmux-thumbs
chezmoi: warning: ignoring .config/tmux/plugins/tmux-yank
chezmoi: /home/scott/.config/tmux/plugins/tmux-continuum/.git: parent directory not in source statechezmoi --verbose managed | grep tmux
.config/tmux
.config/tmux/tmux.conf
.config/tmux/tmux.reset.conf

Output of chezmoi doctor

$ chezmoi doctor
RESULT    CHECK                       MESSAGE
ok        version                     v2.47.1, commit 1ce6b2eeb0caf75bd91883e5a968e713a26e7be2, built at 2024-03-03T01:06:52Z, built by goreleaser
warning   latest-version              v2.48.1
ok        os-arch                     linux/amd64 (Ubuntu 23.10 (Mantic Minotaur))
ok        uname                       Linux nero 6.5.0-35-generic #35-Ubuntu SMP PREEMPT_DYNAMIC Fri Apr 26 11:23:57 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
ok        go-version                  go1.22.0 (gc)
ok        executable                  ~/bin/chezmoi
ok        upgrade-method              replace-executable
ok        config-file                 ~/.config/chezmoi/chezmoi.yaml, last modified 2024-05-25T08:47:42+01:00
warning   source-dir                  ~/.local/share/chezmoi is a git working tree (dirty)
ok        suspicious-entries          no suspicious entries
warning   working-tree                ~/.local/share/chezmoi is a git working tree (dirty)
ok        dest-dir                    ~ is a directory
ok        umask                       002
ok        cd-command                  found /bin/zsh
ok        cd-args                     /bin/zsh
info      diff-command                not set
ok        edit-command                found /usr/local/bin/nvim
ok        edit-args                   /usr/local/bin/nvim
ok        git-command                 found /usr/bin/git, version 2.40.1
ok        merge-command               found /usr/bin/vimdiff
ok        shell-command               found /bin/zsh
ok        shell-args                  /bin/zsh
info      age-command                 age not found in $PATH
ok        gpg-command                 found /usr/bin/gpg, version 2.2.40
info      pinentry-command            not set
info      1password-command           op not found in $PATH
info      bitwarden-command           bw not found in $PATH
info      bitwarden-secrets-command   bws not found in $PATH
info      dashlane-command            dcli not found in $PATH
info      doppler-command             doppler not found in $PATH
info      gopass-command              gopass not found in $PATH
info      keepassxc-command           keepassxc-cli not found in $PATH
info      keepassxc-db                not set
info      keeper-command              keeper not found in $PATH
info      lastpass-command            lpass not found in $PATH
info      pass-command                pass not found in $PATH
info      passhole-command            ph not found in $PATH
info      rbw-command                 rbw not found in $PATH
info      vault-command               vault not found in $PATH
info      vlt-command                 vlt not found in $PATH
info      secret-command              not set

Additional context

BTW I love the project and it's been amazing to sync my systems and help would be appreciated.

What I was looking for was a way to re-add in future without having to manually choose what to add. For example

chezmoi re-add -r ~/.config/tmux
@lilHermit lilHermit added the support Support request label May 27, 2024
@lilHermit lilHermit changed the title Trouble is ignoring certain files Trouble ignoring certain files May 29, 2024
@nipuna-perera
Copy link

I want to do the same. Did you find a solution to this?

@twpayne
Copy link
Owner

twpayne commented Sep 9, 2024

Running chezmoi ignored will list all the files that chezmoi ignores, which may help you debug your .chezmoiignore file.

@make-github-pseudonymous-again

Was struggling with a similar issue. Essentially, the following does not work:

*
!a/b/**

You need

*
!a/
!a/b/**

@tomdottom
Copy link

This does feel like unexpected behaviour. I would expect the following to work, but I can confirm it causes all files to be ignored:

*
!a/b/**

@NiceGuyIT
Copy link

I wanted to exclude a directory except for certain files and had a difficult time figuring out how to get it to work. Here's what I discovered.

The chezmoiignore docs state it uses the Match function in the doublestar library. Match states a doublestar ** should be surrounded by paths /**/ and if you want to match a file it should be /path/**/*.txt instead of /path/**.txt. The chezmoiignore docs state all excludes ! take priority over all includes and that's where I think the bug is. As others have noted, this does not work because the doublestar exclusion does not take priority over the doublestar inclusion and all files are included (ignored).

sandbox/**/
!sandbox/**/*.txt

Removing the doublestar also does not work.

sandbox/
!sandbox/**/*.txt

Using the gitignore syntax to ignore a folder except certain files, I found this to work.

sandbox/*
!sandbox/path1/
sandbox/path1/*
!sandbox/path1/sub1/
sandbox/path1/sub1/*
!sandbox/path1/sub2/
sandbox/path1/sub2/*
!sandbox/path1/sub3/
sandbox/path1/sub3/*
!sandbox/path2/
sandbox/path2/*
!sandbox/**/*.txt

Adding the directory excludes other file types.

~/ $ chezmoi add ~/sandbox
chezmoi: warning: ignoring sandbox/path1/sub2/findme.bin
chezmoi: warning: ignoring sandbox/path1/sub3/findme.bin
chezmoi: warning: ignoring sandbox/path2/sub1
chezmoi: warning: ignoring sandbox/path2/sub2
chezmoi: warning: ignoring sandbox/path2/sub3
chezmoi: warning: ignoring sandbox/path3

And includes text files. This was run in the source directory. Notice the .keep file for path2.

~/.local/share/chezmoi/ $ fd --no-ignore --hidden . sandbox/
sandbox/path1/
sandbox/path1/sub1/
sandbox/path1/sub1/text1.txt
sandbox/path1/sub2/
sandbox/path1/sub2/text1.txt
sandbox/path1/sub3/
sandbox/path1/sub3/text1.txt
sandbox/path2/
sandbox/path2/.keep

For completeness, here's the target structure.

~/ $ fd --no-ignore --hidden . sandbox/
sandbox/path1/
sandbox/path1/sub1/
sandbox/path1/sub1/text1.txt
sandbox/path1/sub2/
sandbox/path1/sub2/findme.bin
sandbox/path1/sub2/text1.txt
sandbox/path1/sub3/
sandbox/path1/sub3/findme.bin
sandbox/path1/sub3/text1.txt
sandbox/path2/
sandbox/path2/sub1/
sandbox/path2/sub1/text1.txt
sandbox/path2/sub2/
sandbox/path2/sub2/text1.txt
sandbox/path2/sub3/
sandbox/path2/sub3/findme.bin
sandbox/path2/sub3/text1.txt
sandbox/path3/
sandbox/path3/sub1/
sandbox/path3/sub1/text1.txt
sandbox/path3/sub2/
sandbox/path3/sub2/text1.txt
sandbox/path3/sub3/
sandbox/path3/sub3/findme.bin
sandbox/path3/sub3/text1.txt

My real-world use case has a lot more sub-directories which makes this cumbersome but it works.

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

No branches or pull requests

6 participants