From 4f91df5db28a67fda6eca81ae9be7e580e637f98 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Mon, 28 Dec 2020 12:33:46 +0100 Subject: pkgs/profpatsch/e: translate [ and ] to block boundaries Since the goal of using `e` with argv is interactive execution of block-style commands from the command line, the use of { and } for blocks is sub-optimal, since bash (and ostensibly also fish) interpret them as metacharacters and assign some semantics. [ and ] on the other hand are not taken (apart from the `[` executable, which is only relevant in command position and can always be replaced by the `test` command). So we translate a stand-alone "[" argument to "{" and the same for "]"/"}", giving us a transparent block syntax. --- pkgs/profpatsch/execline/e.nix | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'pkgs/profpatsch/execline/e.nix') diff --git a/pkgs/profpatsch/execline/e.nix b/pkgs/profpatsch/execline/e.nix index 96a8d401..90b235a4 100644 --- a/pkgs/profpatsch/execline/e.nix +++ b/pkgs/profpatsch/execline/e.nix @@ -22,15 +22,26 @@ let "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"; } [ + e = pkgs.writers.writeDash "e" '' + set -e # 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" - ]; + if [ $# -eq 0 ]; then + ${shell} + else + cmd= + # substitute "[" and "]" to execline’s "{" and "}" + for arg in "$@"; do + if [ "$arg" = "[" ]; then + cmd="$cmd {" + else if [ "$arg" = "]" ]; then + cmd="$cmd }" + else + cmd="$cmd $arg" + fi; fi + done + # call execlineb with the arguments as script + ${bins.execlineb} -Pc "$cmd" + fi + ''; in { inherit e; } -- cgit 1.4.1