2017-04-23 20:08:40 -07:00
|
|
|
# This should be used where you want user names with a description. Such as in an argument
|
|
|
|
# completion. If you just want a list of user names use __fish_print_users.
|
2017-07-10 14:10:02 +02:00
|
|
|
# The string replace command takes into account GECOS-formatted description fields, by retaining
|
|
|
|
# only the first field, the relevant one, from the comma-separated list
|
2007-09-22 06:52:12 +10:00
|
|
|
function __fish_complete_users --description "Print a list of local users, with the real user name as a description"
|
2017-04-25 17:36:22 +02:00
|
|
|
if command -sq getent
|
2020-04-08 22:12:29 +09:00
|
|
|
command getent passwd | while read -l line
|
|
|
|
string split -f 1,5 : -- $line | string join \t | string replace -r ',.*' ''
|
|
|
|
end
|
2017-04-25 17:36:22 +02:00
|
|
|
else if command -sq dscl
|
2017-04-23 20:08:40 -07:00
|
|
|
# This is the "Directory Service command line utility" used on macOS in place of getent.
|
2017-04-25 10:20:48 +02:00
|
|
|
command dscl . -list /Users RealName | string match -r -v '^_' | string replace -r ' {2,}' \t
|
2017-04-23 20:08:40 -07:00
|
|
|
else if test -r /etc/passwd
|
2020-04-08 22:12:29 +09:00
|
|
|
string match -v -r '^\s*#' </etc/passwd | while read -l line
|
|
|
|
string split -f 1,5 : -- $line | string join \t | string replace -r ',.*' ''
|
|
|
|
end
|
2016-11-27 21:27:22 -08:00
|
|
|
end
|
2007-09-22 06:52:12 +10:00
|
|
|
end
|