From a8f1f449657225795af87e0045ec442ce3c82a26 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Mon, 28 Dec 2020 10:46:58 +0100 Subject: pkgs/profpatsch/e: allow passing a block-style argument as argv MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Often times I want to execute “block-style” programs directly, but it is rather inconvenient to type out `execlineb -c "…"` every time, plus -c wants the argv as a single string instead of an argv. The alternative, using the block representation with leading spaces, is even less ergonomic. So instead of execlineb -c "nix-run { -A pkgs.profpatsch.e ~/vuizvui } echo hello" or even nix-run ' -A' ' pkgs.profpatsch.e' ' /home/me/vuizvui' '' echo hello I can now write e nix-run { -A pkgs.profpatsch.e ~/vuizvui } echo hello and it will work as expected (provided your shell expands inside {} blocks, which bash does but fish doesn’t for some reason). If no argument is passed, e falls back to opening a shell prompt. --- pkgs/profpatsch/execline/e.nix | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'pkgs/profpatsch/execline') diff --git a/pkgs/profpatsch/execline/e.nix b/pkgs/profpatsch/execline/e.nix index ca72c6f0..96a8d401 100644 --- a/pkgs/profpatsch/execline/e.nix +++ b/pkgs/profpatsch/execline/e.nix @@ -2,23 +2,35 @@ let bins = getBins pkgs.rlwrap [ "rlwrap" ] - // getBins pkgs.s6-portable-utils [ { use = "s6-cat"; as = "cat"; } ] + // getBins pkgs.s6-portable-utils [ { use = "s6-cat"; as = "cat"; } "s6-test" ] // getBins pkgs.execline [ "execlineb" ]; # minimal execline shell - e = + shell = let prompt = [ "if" [ "printf" ''\e[0;33me>\e[0m '' ] ]; in - writeExecline "e" {} ([ + writeExecline "execline-shell" {} ([ bins.rlwrap "--remember" "--quote-characters" "\"" "--complete-filenames" + "--ansi-colour-aware" ] ++ prompt ++ [ "forstdin" "-d\n" "cmd" "importas" "cmd" "cmd" "foreground" [ bins.execlineb "-Pc" "$cmd" ] ] ++ prompt); + # TODO: should definitely still pass a command line to rlwrap, because then it keeps the history! + e = writeExecline "e" { argMode = "env"; } [ + # if there is no argument, we start the shell, else we call execlineb directly + "ifelse" [ "importas" "#" "#" bins.s6-test "$#" "=" "0" ] + [ shell ] + # call execlineb with the arguments as script + "backtick" "-i" "cmd" [ "dollarat" "-d" " " ] + "importas" "-ui" "cmd" "cmd" + bins.execlineb "-Pc" "$cmd" + ]; + in { inherit e; } -- cgit 1.4.1