diff --git a/lib/prompt.py b/lib/prompt.py index 4cb3f97..79b9c03 100755 --- a/lib/prompt.py +++ b/lib/prompt.py @@ -220,16 +220,20 @@ class LoginPart(Part): self.fragments.append(style_reset()) def list_homes(): - already_listed = set() + usernames = [] + home_dirs = [] - with open("/etc/passwd") as f: - for line in f: - tokens = line.split(":") - - if tokens[5] != "/dev/null": - if tokens[5] not in already_listed: - already_listed.add(tokens[5]) - yield (tokens[5], tokens[0]) + if os.path.exists("/etc/passwd"): + with open("/etc/passwd") as f: + for line in f: + tokens = line.split(":") + + if tokens[5] != "/dev/null": + if tokens[5] not in home_dirs: + usernames.append(tokens[0]) + home_dirs.append(tokens[5]) + + return list(zip(home_dirs, usernames)) class Dir: def __init__(self, path, name=None, slash="/"):