Use the new string split --fields feature

This commit is contained in:
Jason Nader 2020-04-08 22:12:29 +09:00 committed by ridiculousfish
parent 07fb55d342
commit d278ff4e45

View File

@ -4,11 +4,15 @@
# only the first field, the relevant one, from the comma-separated list # only the first field, the relevant one, from the comma-separated list
function __fish_complete_users --description "Print a list of local users, with the real user name as a description" function __fish_complete_users --description "Print a list of local users, with the real user name as a description"
if command -sq getent if command -sq getent
command getent passwd | cut -d : -f 1,5 | string replace -r ':' \t | string replace -r ',.*' '' command getent passwd | while read -l line
string split -f 1,5 : -- $line | string join \t | string replace -r ',.*' ''
end
else if command -sq dscl else if command -sq dscl
# This is the "Directory Service command line utility" used on macOS in place of getent. # This is the "Directory Service command line utility" used on macOS in place of getent.
command dscl . -list /Users RealName | string match -r -v '^_' | string replace -r ' {2,}' \t command dscl . -list /Users RealName | string match -r -v '^_' | string replace -r ' {2,}' \t
else if test -r /etc/passwd else if test -r /etc/passwd
string match -v -r '^\s*#' </etc/passwd | cut -d : -f 1,5 | string replace ':' \t | string replace -r ',.*' '' string match -v -r '^\s*#' </etc/passwd | while read -l line
string split -f 1,5 : -- $line | string join \t | string replace -r ',.*' ''
end
end end
end end