Re: execline-in-execline

2018-06-07 Thread Guillaume Perréal
As a matter of example : this scripts "rewrites" its final command 
depending on optional arguments. Its purpose is to restore select parts 
of the environment variables, uid/gid and working directory, that were 
saved in a directory at some point in the past.


https://github.com/Adirelle/s6rc-overlay/blob/master/src/sbin/with-contenv

Maybe it is pushing execline a bit too far but I didn't fell like coding 
it in C (which I do no master).


Le 07/06/2018 à 17:59, Profpatsch a écrit :

Laurent Bercot writes:


  Remember that once an execlineb script has been parsed, it's just a
command line, no more, no less. So your example script can just be
written as:

#!execline
define url example.com
s6-tcpclient $url 80
foreground { fdmove 1 7 echo -en "..." }
fdmove 0 6 cat

  No second execlineb invocation necessary at all. No quoting
  nightmares.

Ooh, you are right!
It’s even more elegant than I thought!
Nice.





Re: execline-in-execline

2018-06-07 Thread Profpatsch


Laurent Bercot writes:

>  Remember that once an execlineb script has been parsed, it's just a
> command line, no more, no less. So your example script can just be
> written as:
>
> #!execline
> define url example.com
> s6-tcpclient $url 80
> foreground { fdmove 1 7 echo -en "..." }
> fdmove 0 6 cat
>
>  No second execlineb invocation necessary at all. No quoting
>  nightmares.

Ooh, you are right!
It’s even more elegant than I thought!
Nice.

-- 
Written with Emacs (mu4e) on NixOS.
Q: Why is this email five sentences or less?
A: http://five.sentenc.es/
May take up to five days to read your message. If it’s urgent, call me.


Re: execline-in-execline

2018-06-06 Thread Laurent Bercot

```
#!execline
define url example.com
s6-tcpclient $url 80
execlineb "
foreground {
 fdmove 1 7 echo -en \"…\"
 fdmove 0 6 cat
}
"
```


 I have trouble understanding what you want to do in the general case,
because in this example, s6-tcpclient takes a whole command line, so
you do not have to call execlineb again.
 Remember that once an execlineb script has been parsed, it's just a
command line, no more, no less. So your example script can just be
written as:

#!execline
define url example.com
s6-tcpclient $url 80
foreground { fdmove 1 7 echo -en "..." }
fdmove 0 6 cat

 No second execlineb invocation necessary at all. No quoting nightmares.

--
 Laurent



execline-in-execline

2018-06-06 Thread Profpatsch
I wonder if I can write nested execline scripts.

For example: I have a chaining program like `s6-tcpclient`:

```
#!execline
s6-tcpclient example.com 80
sh -c 'echo -en "GET / HTTP/1.0\nHost: example.com\n\n" 1>&7; cat <&6'
```

which I can run inside my execline script, obviously.
What I can also do is:

```
#!execline
define url example.com
s6-tcpclient $url 80
execlineb "
foreground {
  fdmove 1 7 echo -en \"…\"
  fdmove 0 6 cat
}
"
```

which uses an execline script as `prog` for `s6-tcpclient`.
Note the escaping I have to add to the echo string.

What I’m wondering is: since I am already inside the `execlineb`
script reader, why should I have to call it recursively?

I played with `runblock` a bit, since it seemed the most promising,
but couldn’t bring it do do something except throwing a “usage” or
“wrong number of arguments” error.

My idea is to have kind of “magic token” that causes the `execline`
parser to see rest of the file as an execline script, stopping the
tokenizer:

```
#!execline
define url example.com
s6-tcpclient $url 80
execline foreground {
  fdmove 1 7 echo -en "…"
  fdmove 0 6 cat
}
```

Which would be parsed to the standard:

```
define url example.com s6-tcpclient '$url' 80
execlineb -l foreground { fdmove 1 7 echo -en "…" } fdmove 0 6 cat
```

(newline for clarity)
The `-l` (for “line”, maybe `-v` for “verbatim”) instructs `execlineb`
to take the rest of its arguments as execline script (no `args`).

Execline can be used multiple times, since `execlineb` would stop
parsing at the first `execline` it encounters:

```
execline execline echo foo
=>
execlineb -l execline echo foo
=>
execlineb -l echo foo
=>
echo foo
```

Actually, stopping the parse at the first encounted `execline`
is a lie, since blocks have to be handled correctly:

```
foreground {
  execline echo foo
}
echo bar
=>
foreground " execlineb" " -l" " echo" " foo" "" echo bar
```

If I think about it, maybe there doesn’t have to be any
standard token, and just adding `-l` to `execlineb` gives us
all needed functionality already.


  Profpatsch

-- 
Written with Emacs (mu4e) on NixOS.
Q: Why is this email five sentences or less?
A: http://five.sentenc.es/
May take up to five days to read your message. If it’s urgent, call me.