dhall-nix-lib/Text/shell-escape.dhall

16 lines
479 B
Text

{-|
Escape a Text value such that it can be used safely in shells.
The escaping is done by replacing all `'` with `'"'"'` and wraps that string in
single quotes.
This works for all POSIX-compliant shells and some other shells like csh.
-}
let shell-escape
: Text -> Text
= \(xs : Text) -> "'${Text/replace "'" "'\"'\"'" xs}'"
let example0 = assert : shell-escape "foo" === "'foo'"
let example1 = assert : shell-escape "foo'bar" === "'foo'\"'\"'bar'"
in shell-escape