Re: execline, s6-portable-utils: print a file to stdout

2018-07-24 Thread Laurent Bercot

I haven’t found a way to print a file to stdout with either
execline nor s6-portable-utils. The `s6-cat` utility only
echoes stuff that is already coming from stdin,
and unlike the shell, execline doesn’t have `<`.


 https://skarnet.org/software/execline/redirfd.html

 "redirfd -r 0 $file s6-cat" will print $file to stdout.

--
 Laurent



Re: execline: returning something from ifthenelse blocks

2018-07-24 Thread Laurent Bercot

So I’d like to have an ifthenelse and return the
same envvar from both branches.


 https://www.mail-archive.com/skaware@list.skarnet.org/msg00311.html

--
 Laurent



execline, s6-portable-utils: print a file to stdout

2018-07-24 Thread Profpatsch
Sorry for my spam of mails, I want to separate my questions
by topic so they will be searchable.

I haven’t found a way to print a file to stdout with either
execline nor s6-portable-utils. The `s6-cat` utility only
echoes stuff that is already coming from stdin,
and unlike the shell, execline doesn’t have `<`.

Maybe some kind of output utility might be nice?
The Lisp dialect Clojure has `slurp` and `spit`:
https://clojuredocs.org/clojure.core/slurp
https://clojuredocs.org/clojure.core/spit

-- 
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.


execline: returning something from ifthenelse blocks

2018-07-24 Thread Profpatsch
I have the following logic:
If file in variable f is a symlink, resolve it
and use the result as link target.
Otherwise, use the result as link target directly.

So I’d like to have an ifthenelse and return the
same envvar from both branches. But this is the
best I can do:

ifte {
  backtick res { s6-linkname -f $f }
  importas -ui res res
  s6-ln $res $origin
} {
  s6-ln $f $origin
}
{ s6-test -L $f } 

My hope would be something like:

ifthenelse { s6-test -L $f } {
  return $res somehow
} {}
s6-ln $res $origin


-- 
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 globbing

2018-07-24 Thread Laurent Bercot

That brings me to another question: is there a collection of
more execline utilities somewhere? I suspect the standard
GNU coreutils are not quite to your liking in a lot of cases.


 The execline package has all the execline-specific utilities you
need to perform execline scripting (although if you have a bright
idea about something that's obviously missing, please share it).
GNU coreutils provide a completely different functionality, i.e.
basic Unix utilities - and if you don't like them, there are a ton
of other implementations of the same utilities: busybox, toybox,
sbase+ubase, etc.



Would you be open to switch the default behavior?
Maybe with a warning message on `-0` that it is the default
and will be removed after a few releases.
I suggest something like `-k` for “keep”.


 I don't think the benefits of changing the default are worth the
drawbacks and the effort. Again, the current default is how shell
globbing works, and I think there's value in aligning with that
behaviour. As long as the user has control, there's not much
incentive to change.

--
 Laurent



Re: execline globbing

2018-07-24 Thread Profpatsch


Laurent Bercot  writes:

>  Your next door "echo" command will do just that (or s6-echo
> if you risk having dashes and want reliable behaviour in all cases).

That brings me to another question: is there a collection of
more execline utilities somewhere? I suspect the standard
GNU coreutils are not quite to your liking in a lot of cases.

>  The shell has the exact same default behaviour. I didn't want to
> gratuitously diverge from the shell. But I agree "elglob -0" is the
> behaviour you want most of the time.

Would you be open to switch the default behavior?
Maybe with a warning message on `-0` that it is the default
and will be removed after a few releases.
I suggest something like `-k` for “keep”.


>  It's not a "zero string". It's zero word. Which means the "${f}"
> argument is replaced with nothing at all, not even an empty string.
> So the tests resolve to:
> test -z
> and
> test -n
> which both return true.

Aha!

-- 
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 globbing

2018-07-24 Thread Laurent Bercot

elglob -0 fs somedir/*
if { test -n $fs }
ln -t otherdir $fs

the test will fail if there’s more than one file in `somedir`.
Is there a way to put a split variable into one variable again?


 Your next door "echo" command will do just that (or s6-echo
if you risk having dashes and want reliable behaviour in all cases).

elglob -0 splitfs somedir/*
backtick -n fs { echo $splitfs }
importas -u fs fs
if { test -n $fs } ...



It feels kind of clumsy to use elglob, especially because of
the default verbatim input of the pattern if no expansion is
found. I can’t imagine any use case where I’d want that,
especially not as default behaviour.


 The shell has the exact same default behaviour. I didn't want to
gratuitously diverge from the shell. But I agree "elglob -0" is the
behaviour you want most of the time.



Another fun effect:

execlineb -c 'elglob -0 f doesnotexist/* if { test -z "${f}" } echo 
foo'

foo
execlineb -c 'elglob -0 f doesnotexist/* if { test -n "${f}" } echo 
foo'

foo

So for `test`, the ominous “zero string” of execline is both
empty and non-empty!
Is there some elaboration somewhere what this zero string is?
And how do work with it?


 It's not a "zero string". It's zero word. Which means the "${f}"
argument is replaced with nothing at all, not even an empty string.
So the tests resolve to:
test -z
and
test -n
which both return true.

--
 Laurent



execline globbing

2018-07-24 Thread Profpatsch
When I have a glob like:

elglob -0 fs somedir/*
if { test -n $fs }
ln -t otherdir $fs

the test will fail if there’s more than one file in `somedir`.
Is there a way to put a split variable into one variable again?

It feels kind of clumsy to use elglob, especially because of
the default verbatim input of the pattern if no expansion is
found. I can’t imagine any use case where I’d want that,
especially not as default behaviour.

Another fun effect:

> execlineb -c 'elglob -0 f doesnotexist/* if { test -z "${f}" } echo foo'
foo
> execlineb -c 'elglob -0 f doesnotexist/* if { test -n "${f}" } echo foo'
foo

So for `test`, the ominous “zero string” of execline is both
empty and non-empty!
Is there some elaboration somewhere what this zero string is?
And how do work with it?

--
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=E2=80=99s urgent, call me.