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

Re: [PATCH] Increase $COLUMNS when generating long option completions



On Wed, Aug 4, 2021 at 4:12 AM Lawrence Velázquez <larryv@xxxxxxx> wrote:
>
> On Tue, Aug 3, 2021, at 10:05 AM, Marlon Richert wrote:
> > On Mon, Aug 2, 2021 at 2:07 AM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> > >
> > > I'm puzzled, doesn't this imply that the value of $COLUMNS is
> > > incorrect on entry to the function?
> >
> > No, the problem results from _call_program being connected to a pipe:
> >
> >    _call_program $lflag options ${~words[1]} --help 2>&1 |
> >      while IFS= read -r opt; do
> >
> > When ${~words[1]} is an external command, it will then not see
> > $COLUMNS, unless $COLUMNS has been exported.
>
> Isn't that the case in general?  External commands *never* see
> COLUMNS if it isn't in the environment.  The pipe is a red herring.
>
> > For example, compare the output of the following:
> >
> > % pip3 --help
> > % _call_program tst pip3 --help
> > % _call_program tst pip3 --help | cat
> > % print -r -- "$( pip3 --help )"
>
> Seems like pip is behaving differently depending on whether it's
> outputting to a tty or not.

I feel that cannot be the whole story, because if I do any of the
following, I get terminal-width output, instead of 80 columns:

% COLUMNS=$COLUMNS pip3 --help | cat
% print -r -- "$( COLUMNS=$COLUMNS pip3 --help )"
% _call_program tst COLUMNS=$COLUMNS pip3 --help | cat

And pip isn't the only command that works that way. For example:

% ls -x /
Applications Library System Users Volumes bin cores dev etc home
opt private sbin tmp usr var
% ls -x / | cat
Applications Library System Users Volumes
bin cores dev etc home
opt private sbin tmp usr
var
% COLUMNS=$COLUMNS ls -x / | cat
Applications Library System Users Volumes bin cores dev etc home
opt private sbin tmp usr var
%




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