Skip to content
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

Complete stdin "-" in file locations, add more options that allow it #1237

Merged
merged 2 commits into from
Aug 23, 2024

Conversation

yedayak
Copy link
Collaborator

@yedayak yedayak commented Aug 4, 2024

Every option that reads files using @ allow also - for stdin

All of the --data* and --*header options allow specifying "@-" to
signify reading from stdin
@yedayak yedayak changed the title feat(curl): Complete stdin "-" in file locations Complete stdin "-" in file locations, add more options that allow it Aug 4, 2024
if [[ $cur == \@* ]]; then
_comp_compgen -c "${cur:1}" filedir
_comp_compgen -a -c "${cur:1}" -- -W '-'
Copy link
Owner

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?

Suggested change
_comp_compgen -a -c "${cur:1}" -- -W '-'
[[ $cur == @?(-) ]] && COMPREPLY+=(-)

Copy link
Collaborator

@akinomyoga akinomyoga Aug 11, 2024

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.

Copy link
Collaborator

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+=(-)

Copy link
Owner

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

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

@akinomyoga akinomyoga merged commit 6f03827 into scop:main Aug 23, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants