From 8253df7c3d99d47f6822fec0e0ef68c4f6b35796 Mon Sep 17 00:00:00 2001 From: "David Adam (zanchey)" Date: Thu, 22 Nov 2012 17:07:19 +0800 Subject: [PATCH] use getent for passwd and group if available --- share/functions/__fish_complete_groups.fish | 6 +++++- share/functions/__fish_complete_users.fish | 6 +++++- share/functions/__fish_print_users.fish | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/share/functions/__fish_complete_groups.fish b/share/functions/__fish_complete_groups.fish index b3da864b6..3eb782921 100644 --- a/share/functions/__fish_complete_groups.fish +++ b/share/functions/__fish_complete_groups.fish @@ -1,4 +1,8 @@ function __fish_complete_groups --description "Print a list of local groups, with group members as the description" - cat /etc/group | sed -e "s/^\([^:]*\):[^:]*:[^:]*:\(.*\)/\1\tMembers: \2/" + if test -x /usr/bin/getent + getent group | cut -d ':' -f 1,4 | sed 's/:/\t/' + else + cut -d ':' -f 1,4 /etc/group | sed 's/:/\t/' + end end diff --git a/share/functions/__fish_complete_users.fish b/share/functions/__fish_complete_users.fish index e3ca35f40..82fa85772 100644 --- a/share/functions/__fish_complete_users.fish +++ b/share/functions/__fish_complete_users.fish @@ -1,4 +1,8 @@ function __fish_complete_users --description "Print a list of local users, with the real user name as a description" - cat /etc/passwd | grep -ve '^#' | sed -e 's/^\([^:]*\):[^:]*:[^:]*:[^:]*:\([^:]*\):.*$/\1'\t'\2/' ^/dev/null + if test -x /usr/bin/getent + getent passwd | cut -d : -f 1,5 | sed 's/:/\t/' + else + sgrep -ve '^#' /etc/passwd | cut -d : -f 1,5 | sed 's/:/\t/' + end end diff --git a/share/functions/__fish_print_users.fish b/share/functions/__fish_print_users.fish index fa8e0d174..0a67ab55f 100644 --- a/share/functions/__fish_print_users.fish +++ b/share/functions/__fish_print_users.fish @@ -1,5 +1,9 @@ function __fish_print_users --description "Print a list of local users" - cat /etc/passwd | cut -d : -f 1 + if test -x /usr/bin/getent + getent passwd | cut -d : -f 1 + else + sgrep -ve '^#' /etc/passwd | cut -d : -f 1 + end end