iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🏑

My Collection of chezmoi Tips

に公開

These are some quick chezmoi tips.

Checking only filenames with chezmoi diff

Running chezmoi diff shows the differences.

 $ chezmoi diff
diff --git a/.config/zsh-abbr/user-abbreviations b/.config/zsh-abbr/user-abbreviations
index 44858ff65ed4d489d13ae84f34177869917eec0d..dddae84d604c07f9385ceb0c4a2add18e5d83c26 100600
--- a/.config/zsh-abbr/user-abbreviations
+++ b/.config/zsh-abbr/user-abbreviations
@@ -18,3 +18,4 @@ abbr ga='git add'
 abbr gm='git merge'
 abbr grh='git reset HEAD'
 abbr grhh='git reset HEAD --hard'
+foo

I want to check only the filenames that have differences.

 $ chezmoi diff | grep -E '^diff '
diff --git a/.config/zsh-abbr/user-abbreviations b/.config/zsh-abbr/user-abbreviations

Making it a just task.

diff:
    @chezmoi diff | grep -E '^diff ' || echo "No differences"

Using the filenames shown by chezmoi diff when running chezmoi re-add

However, the displayed file paths are formatted like absolute paths from the Chezmoi home directory, so if you just copy them, you have to manually convert the leading a/ or b/ to ~/, which is a hassle.

  • a/.config/zsh-abbr/user-abbreviations
  • b/.config/zsh-abbr/user-abbreviations

Making it a just task.

re-add file:
    @echo {{file}} | sed 's/^./~/' | xargs chezmoi re-add

Reloading the shell after running chezmoi apply

Because I want to reflect the configuration changes.

Making it a just task.

apply:
    chezmoi apply && exec $SHELL -l

Summary

Example justfile:

set shell := ["bash", "-eu", "-o", "pipefail", "-c"]

[private]
@default:
    echo "Usage: just <recipe>" && just --list

diff:
    @chezmoi diff | grep -E '^diff ' || echo -e "No differences"

re-add file:
    @echo {{file}} | sed 's/^./~/' | xargs chezmoi re-add

apply:
    chezmoi apply && exec $SHELL -l

Usage example:

 $ just diff                                        
diff --git a/.config/zsh-abbr/user-abbreviations b/.config/zsh-abbr/user-abbreviations

# Copying the path from above
 $ just re-add a/.config/zsh-abbr/user-abbreviations

Challenges

I feel like there might be a better solution. I might be overlooking some options in the first place.

Actually, I wanted to register them in zsh-abbr as chezmoi d, chezmoi ra, or chezmoi a, but it didn't work out.

Discussion