about summary refs log tree commit diff
path: root/pkgs/profpatsch/execline/e.nix
blob: 90b235a49ac1ea0455172c8b4f1155b5daa18693 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
{ writeExecline, getBins, pkgs }:
let

  bins = getBins pkgs.rlwrap [ "rlwrap" ]
    // getBins pkgs.s6-portable-utils [ { use = "s6-cat"; as = "cat"; } "s6-test" ]
    // getBins pkgs.execline [ "execlineb" ];

  # minimal execline shell
  shell =
    let
      prompt = [ "if" [ "printf" ''\e[0;33me>\e[0m '' ] ];
    in
      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);

  e = pkgs.writers.writeDash "e" ''
    set -e
    # if there is no argument, we start the shell, else we call execlineb directly
    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; }