about summary refs log tree commit diff
path: root/pkgs/profpatsch/execline
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2020-12-28 10:46:58 +0100
committerProfpatsch <mail@profpatsch.de>2020-12-28 10:54:42 +0100
commita8f1f449657225795af87e0045ec442ce3c82a26 (patch)
treeed34d0037686a3fcb903dcd227455edf8b99bb62 /pkgs/profpatsch/execline
parentdad57ac125432a4f699fd258dd5bf2a00e997b55 (diff)
pkgs/profpatsch/e: allow passing a block-style argument as argv
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.
Diffstat (limited to 'pkgs/profpatsch/execline')
-rw-r--r--pkgs/profpatsch/execline/e.nix18
1 files changed, 15 insertions, 3 deletions
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; }