@@ -1602,29 +1602,35 @@ def path_complete(self, text, line, begidx, endidx, dir_exe_only=False, dir_only
16021602
16031603 # Used to complete ~ and ~user strings with a list of users that have existing home dirs
16041604 def complete_users ():
1605- # Only works on Unix systems
1606- try :
1607- import pwd
1608- except ImportError :
1609- return []
16101605
1611- # Get a list of users from password database
1606+ # We are returning ~user strings that resolve to directories, so don't append a space or quote
1607+ self .allow_appended_space = False
1608+ self .allow_closing_quote = False
1609+
16121610 users = []
1613- for cur_pw in pwd .getpwall ():
16141611
1615- # Check if the user has an existing home dir
1616- if os .path .isdir (cur_pw .pw_dir ):
1612+ # Windows lacks the pwd module so we can't get a list of users.
1613+ # Instead we will add a slash once the user enters text that
1614+ # resolves to an existing home directory.
1615+ if sys .platform .startswith ('win' ):
1616+ expanded_path = os .path .expanduser (text )
1617+ if os .path .isdir (expanded_path ):
1618+ users .append (text + os .path .sep )
1619+ else :
1620+ import pwd
16171621
1618- # Add a ~ to the user to match against text
1619- cur_user = '~' + cur_pw .pw_name
1620- if cur_user .startswith (text ):
1621- if add_trailing_sep_if_dir :
1622- cur_user += os .path .sep
1623- users .append (cur_user )
1622+ # Iterate through a list of users from the password database
1623+ for cur_pw in pwd .getpwall ():
16241624
1625- # These are directories, so don't add a space or quote
1626- self .allow_appended_space = False
1627- self .allow_closing_quote = False
1625+ # Check if the user has an existing home dir
1626+ if os .path .isdir (cur_pw .pw_dir ):
1627+
1628+ # Add a ~ to the user to match against text
1629+ cur_user = '~' + cur_pw .pw_name
1630+ if cur_user .startswith (text ):
1631+ if add_trailing_sep_if_dir :
1632+ cur_user += os .path .sep
1633+ users .append (cur_user )
16281634
16291635 return users
16301636
0 commit comments