Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: less with subprocess



On Mon, Sep 27, 2021 at 4:33 PM Dominik Vogt <dominik.vogt@xxxxxx> wrote:
>
>      alias -g LF="> $HOME/tmp/less-input.$$ & less $HOME/tmp/less-input.$$; kill %; rm $HOME/tmp/less-input.$$"

Nice, but how about:

alias -g LF='| () { cat >$1 &! less $1 ; kill $! } =(:)'

The use of &! silently backgrounds and disassociates cat so that it
can't be terminal-interrupted, and the anonymous function re-uses the
automatically created (and automatically removed) file name from =(:).
When less exits, "kill $!" terminates cat.

>    (You really want to use a private path for the tempfiles
>    because the alias would be vulnerable to symlink attacks when used
>    in a publicly writeable directory.)

Not unreasonable advice, but using the =(...) substitution removes
much of the danger (and most people aren't on shared servers any
more).  If paranoid, TMPPREFIX can be set to a private path to assure
you're always using it with process substitutions.




Messages sorted by: Reverse Date, Date, Thread, Author