-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkgs/profpatsch/runExecline: move to list
We can auto-escape execlines correctly if we model them as nix-style lists, so we shoud certainly do so. It also helps abstraction.
- Loading branch information
1 parent
e8738a0
commit 61dda87
Showing
5 changed files
with
83 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ lib }: | ||
let | ||
# replaces " and \ to \" and \\ respectively and quote with " | ||
# e.g. | ||
# a"b\c -> "a\"b\\c" | ||
# a\"bc -> "a\\\"bc" | ||
# TODO upsteam into nixpkgs | ||
escapeExeclineArg = arg: | ||
''"${builtins.replaceStrings [ ''"'' ''\'' ] [ ''\"'' ''\\'' ] (toString arg)}"''; | ||
|
||
# Escapes an execline (list of execline strings) to be passed to execlineb | ||
# Give it a nested list of strings. Nested lists are interpolated as execline | ||
# blocks ({}). | ||
# Everything is quoted correctly. | ||
# | ||
# Example: | ||
# escapeExecline [ "if" [ "somecommand" ] "true" ] | ||
# == ''"if" { "somecommand" } "true"'' | ||
escapeExecline = execlineList: lib.concatStringsSep " " | ||
(let | ||
go = arg: | ||
if builtins.isString arg then [(escapeExeclineArg arg)] | ||
else if lib.isDerivation arg then [(escapeExeclineArg arg)] | ||
else if builtins.isList arg then [ "{" ] ++ builtins.concatMap go arg ++ [ "}" ] | ||
else abort "escapeExecline can only hande nested lists of strings, was ${lib.generators.toPretty {} arg}"; | ||
in builtins.concatMap go execlineList); | ||
|
||
in { | ||
inherit escapeExecline; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters