pkgs.writeShellApplication {
name = "display-custom-keybindings";
text = ''
#!/usr/bin/env fish
# snipped
'';
As a part of this, I usually write the script for testing and then embed it in Nix.
now, if the script uses ' in it. for example, sometimes I need to use something like tr -d "'" the ' combined with the '' spawns a number of errors. (But I need to match on the '.)
SUre I can have the script separate and put the raw file in place, but I like to follow my established patterns. Is there a way to still use text = '' before I return to that?
Give a specific example and a specific error, and do not paraphrase. tr -d "'" would not cause any errors.
Also your “shebang” isn’t doing anything, writeShellApplication produces a bash script, not a fish one. (Besides, even if it worked, expecting /usr/bin/env and fish to exist on the system is unreliable.)
Your error is very likely related to shellcheck checking your script as if it was bash while you use fish syntax.
The only way around this is to use actual bash, as thats the only supported language for writeShellApplication.
writers.writeFishBin is probably more what you need:
nix-repl> :doc writers.writeFishBin
Function writeFishBin
… defined at
/nix/store/hjb1rqv2mfs5ny47amj2gsc8xk05x5g6-source/pkgs/build-support/writers/scripts.nix:523:18
Like writeScriptBin but the first line is a shebang to fish
Can be called with or without extra arguments.
Examples
:::{.example}
## pkgs.writers.writeFishBin without arguments
| writeFishBin "example" ''
| echo hello world
| ''
:::
:::{.example}
## pkgs.writers.writeFishBin with arguments
| writeFishBin "example"
| {
| makeWrapperArgs = [
| "--prefix" "PATH" ":" "${lib.makeBinPath [ pkgs.hello ]}"
| ];
| }
| ''
| hello
| ''
:::