-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
use __fish_complete_groups to complete group names for chown #3380
Conversation
@@ -9,4 +9,4 @@ complete -c chown -s v -l verbose --description "Output diagnostic for every fil | |||
complete -c chown -s h -l help --description "Display help and exit" | |||
complete -c chown -l version --description "Display version and exit" | |||
complete -c chown --description "Username" -a "(__fish_print_users):" | |||
complete -c chown --description "Username" -a "(echo (commandline -ct)| __fish_sgrep -o '.*:')(cat /etc/group |cut -d : -f 1)" | |||
complete -c chown --description "Username" -a "(echo (commandline -ct)| __fish_sgrep -o '.*:')(if test -x /usr/bin/getent; getent group; else; cat /etc/group; end |cut -d : -f 1)" |
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.
This might also be in /bin or /sbin or /usr/local/bin or /I'm/weird/so/this/is/my/bin - use command -s getent >/dev/null
.
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.
Wait.... why doesn't this just use __fish_complete_groups
?
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.
__fish_complete_groups
uses slightly different logic to pull two fields from /etc/group (cut -d : -f 1,4
), and adds a tab at the end. Different enough to not be useful for chown completion.
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.
The part after the tab is the description. You could just remove it again with string replace -r '\t.*$' ''
.
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.
Though that description might be helpful here as well.
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.
Got it. First time I've dug into completions. Yes, __fish_complete_groups
works fine here, I'll revise.
Merged, thanks! |
Description
chown completion chown currently uses
cat /etc/group
to fetch the list of group names. In Cygwin there's no /etc/group file any more (user and group names are fetched directly from the OS), so when a user tries to tab-complete the group name they get an error message:ASchulma@LZ77E1AASCHULMA ~/d/fish> chown ASchulma:cat: /etc/group: No such file or directory
This change fixes that by using
getent group
by preference to get the group names, and falling back to /etc/group. This is more portable, and it also agrees with the logic used for chgrp completion in __fish_complete_groups.TODOs: