All contributions

twpayne/chezmoi

chezmoi

A dotfiles manager that keeps the same settings on many different machines, securely.

Language
Go
GitHub stars
22,342
Merged changes
2
Project site
chezmoi.io

What we changed

shellQuote no longer doubles backslashes inside single quotes, and choosing diff in apply --interactive for a file that does not exist yet compares it with /dev/null, the way chezmoi diff does.

What this work shows

  • POSIX sh quoting
  • Calling external commands from Go
  • txtar script tests
What was broken

shellQuote doubled backslashes

Inside POSIX sh single quotes a backslash has no special meaning, yet shellQuote doubled it. For the value \n the function returned '\\n', so the shell received different text from the one in the template.

How we fixed it

Backslashes are kept as they are

shellQuote now copies a backslash unchanged, while a single quote still closes the quoted run and gets a backslash before it. Tests cover \n and \', and we checked a few quoted values through sh -c.

#5233

What was broken

Diffing a new file passed a missing path

Choosing diff in apply --interactive for a file that is not on disk yet passed the destination path to diff.command. The external diff program was handed a file that does not exist.

How we fixed it

A new file is compared with /dev/null

The command now gets /dev/null, or NUL: on Windows, as in chezmoi diff, through the same DevNullAbsPath function. A test in diffcommand_unix.txtar uses a diff command that fails if any argument does not exist.

#5232

Merged changes 2

  1. #5233 fix: Don't double backslashes in shellQuote Merged 11 October 2026
  2. #5232 fix: Pass /dev/null to diff command for missing files in apply --interactive Merged 11 October 2026

What it taught us

Inside POSIX sh single quotes a backslash means nothing, so quoting has to leave it as it is. A tool that calls an outside program has to hand it paths that exist, on Linux and on Windows.

More about this technology: Golang

Other projects we write code for

Describe your project.

A free quote comes back within an hour during working hours.