-
Notifications
You must be signed in to change notification settings - Fork 392
Complete stdin "-" in file locations, add more options that allow it #1237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
All of the --data* and --*header options allow specifying "@-" to signify reading from stdin
if [[ $cur == \@* ]]; then | ||
_comp_compgen -c "${cur:1}" filedir | ||
_comp_compgen -a -c "${cur:1}" -- -W '-' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No strong opinions, but I suppose we could simplify/optimize this to the following unless we see downsides to doing that? WDYT, and @akinomyoga too?
_comp_compgen -a -c "${cur:1}" -- -W '-' | |
[[ $cur == @?(-) ]] && COMPREPLY+=(-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, although it is functionally equivalent, I prefer using _comp_compgen
which is more idiomatic.
It takes time for me to understand that [[ $cur == @?(-) ]] && COMPREPLY+=(-)
is functionally equivalent to _comp_compgen -ac "${cur:1}" -- -W '-'
and doesn't have a bug nor an extra intentional effect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There seem to be both types of existing cases:
./completions/7z:59: _comp_compgen -c "${cur:4}" -- -P"${cur:0:4}" -W '-'
./completions/curl:144: _comp_compgen -- -W '-'
./completions/gpgv:35: _comp_compgen -- -W '-'
./completions/iperf:55: _comp_compgen -- -W 'C'
./completions/pack200:35: _comp_compgen -- -W '-'
./completions/pdftotext:32: _comp_compgen -- -W '-'
./completions/puppet:160: _comp_compgen -- -W '-'
./completions/tshark:97: _comp_compgen -- -W 'n'
./completions/unpack200:19: _comp_compgen -- -W '-'
./completions/cppcheck:38: [[ ! $cur || $cur == - ]] && COMPREPLY+=(-)
./completions/mr:46: COMPREPLY+=(-)
./completions/nslookup:59: [[ $REPLY -eq 1 && $cur == @(|-) ]] && COMPREPLY+=(-)
./completions/patch:24: [[ ! $cur || $cur == - ]] && COMPREPLY=(-)
./completions/tshark:67: [[ $cur == @(|-) ]] && COMPREPLY+=(-)
./completions/wget:78: _comp_compgen_filedir && [[ $cur == - || ! $cur ]] && COMPREPLY+=(-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me it's the opposite, I'm far from being "natural" with the stuff we've added over the few last releases and have to look up stuff a lot, almost certainly because I haven't been writing all that much code in this project lately, whereas straight bash is much easier for me. But I'm fine with those who are doing most of the actual work these days getting to decide the flavor. Would not hurt to be consistent with it though through the whole tree.
Pre-approved either way you guys decide.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really mind either, I think the second option is easier to read without context, but the first one makes more sense here since it follows the same pattern as the line before it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I again thought about it, but I think it is still better to generate completions through _comp_compgen
even in simple cases because it would be easier to apply changes later in a consistent way (by modifying the behavior of _comp_compgen
or by grep'ping the calls of _comp_compgen
).
Every option that reads files using
@
allow also-
for stdin