diff options
author | Profpatsch <mail@profpatsch.de> | 2020-12-28 12:33:46 +0100 |
---|---|---|
committer | Profpatsch <mail@profpatsch.de> | 2020-12-28 12:33:46 +0100 |
commit | 4f91df5db28a67fda6eca81ae9be7e580e637f98 (patch) | |
tree | f4c3a53d5f37b4aa161f63a4db433bd0ed2d7925 /pkgs/profpatsch/execline/e.nix | |
parent | a8f1f449657225795af87e0045ec442ce3c82a26 (diff) |
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.
Diffstat (limited to 'pkgs/profpatsch/execline/e.nix')
-rw-r--r-- | pkgs/profpatsch/execline/e.nix | 29 |
1 files changed, 20 insertions, 9 deletions
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; } |