mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-22 06:10:57 +08:00
Use the new string split --fields
feature
This commit is contained in:
parent
07fb55d342
commit
d278ff4e45
|
@ -4,11 +4,15 @@
|
|||
# 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"
|
||||
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
|
||||
# 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
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue
Block a user