templ icon indicating copy to clipboard operation
templ copied to clipboard

bug: templ fmt fails in nushell

Open shadr opened this issue 3 months ago • 0 comments

Currently templ fmt fails when SHELL is set to nushell

(✗) hello.templ [ error=failed to format file "hello.templ": prettier error: unable to format with command ["/run/current-system/sw/bin/nu" "-c" "prettier --use-tabs --stdin-filepath $TEMPL_PRETTIER_FILENAME"], output: "Error: nu::parser::env_var_not_var\n\n  x Use $env.TEMPL_PRETTIER_FILENAME instead of $TEMPL_PRETTIER_FILENAME.\n   ,-[source:1:38]\n 1 | prettier --use-tabs --stdin-filepath $TEMPL_PRETTIER_FILENAME\n   :                                      ^^^^^^^^^^^^|^^^^^^^^^^^\n   :                                                  `-- use $env.TEMPL_PRETTIER_FILENAME instead of $TEMPL_PRETTIER_FILENAME\n   `----\n\n", error: exit status 1 ]
(✓) Format Complete [ count=1 errors=1 changed=0 duration=18.599347ms ]

This happens because DEFAULT_COMMAND uses $TEMPL_PRETTIER_FILENAME, but nushell is not POSIX compliant and uses $env.VAR instead of $VAR. While you can specify prettier command manually or set SHELL variable to POSIX compliant shell

SHELL=sh templ fmt hello.templ
# or
templ fmt -prettier-command "prettier --use-tabs --stdin-filepath $env.TEMPL_PRETTIER_FILENAME" hello.templ

it would be nice to support it by default. I'm new to Go, but I can try to make a PR if maintainers are fine with that change.

shadr avatar Sep 14 '25 11:09 shadr