@@ -1498,11 +1498,6 @@ def path_complete(
1498
1498
# Used to complete ~ and ~user strings
1499
1499
def complete_users () -> List [str ]:
1500
1500
1501
- # We are returning ~user strings that resolve to directories,
1502
- # so don't append a space or quote in the case of a single result.
1503
- self .allow_appended_space = False
1504
- self .allow_closing_quote = False
1505
-
1506
1501
users = []
1507
1502
1508
1503
# Windows lacks the pwd module so we can't get a list of users.
@@ -1531,6 +1526,12 @@ def complete_users() -> List[str]:
1531
1526
cur_user += os .path .sep
1532
1527
users .append (cur_user )
1533
1528
1529
+ if users :
1530
+ # We are returning ~user strings that resolve to directories,
1531
+ # so don't append a space or quote in the case of a single result.
1532
+ self .allow_appended_space = False
1533
+ self .allow_closing_quote = False
1534
+
1534
1535
return users
1535
1536
1536
1537
# Determine if a trailing separator should be appended to directory completions
@@ -1581,47 +1582,48 @@ def complete_users() -> List[str]:
1581
1582
search_str = os .path .join (os .getcwd (), search_str )
1582
1583
cwd_added = True
1583
1584
1584
- # Set this to True for proper quoting of paths with spaces
1585
- self .matches_delimited = True
1586
-
1587
1585
# Find all matching path completions
1588
1586
matches = glob .glob (search_str )
1589
1587
1590
1588
# Filter out results that don't belong
1591
1589
if path_filter is not None :
1592
1590
matches = [c for c in matches if path_filter (c )]
1593
1591
1594
- # Don't append a space or closing quote to directory
1595
- if len (matches ) == 1 and os .path .isdir (matches [0 ]):
1596
- self .allow_appended_space = False
1597
- self .allow_closing_quote = False
1592
+ if matches :
1593
+ # Set this to True for proper quoting of paths with spaces
1594
+ self .matches_delimited = True
1595
+
1596
+ # Don't append a space or closing quote to directory
1597
+ if len (matches ) == 1 and os .path .isdir (matches [0 ]):
1598
+ self .allow_appended_space = False
1599
+ self .allow_closing_quote = False
1598
1600
1599
- # Sort the matches before any trailing slashes are added
1600
- matches .sort (key = self .default_sort_key )
1601
- self .matches_sorted = True
1601
+ # Sort the matches before any trailing slashes are added
1602
+ matches .sort (key = self .default_sort_key )
1603
+ self .matches_sorted = True
1602
1604
1603
- # Build display_matches and add a slash to directories
1604
- for index , cur_match in enumerate (matches ):
1605
+ # Build display_matches and add a slash to directories
1606
+ for index , cur_match in enumerate (matches ):
1605
1607
1606
- # Display only the basename of this path in the tab completion suggestions
1607
- self .display_matches .append (os .path .basename (cur_match ))
1608
+ # Display only the basename of this path in the tab completion suggestions
1609
+ self .display_matches .append (os .path .basename (cur_match ))
1608
1610
1609
- # Add a separator after directories if the next character isn't already a separator
1610
- if os .path .isdir (cur_match ) and add_trailing_sep_if_dir :
1611
- matches [index ] += os .path .sep
1612
- self .display_matches [index ] += os .path .sep
1611
+ # Add a separator after directories if the next character isn't already a separator
1612
+ if os .path .isdir (cur_match ) and add_trailing_sep_if_dir :
1613
+ matches [index ] += os .path .sep
1614
+ self .display_matches [index ] += os .path .sep
1613
1615
1614
- # Remove cwd if it was added to match the text readline expects
1615
- if cwd_added :
1616
- if cwd == os .path .sep :
1617
- to_replace = cwd
1618
- else :
1619
- to_replace = cwd + os .path .sep
1620
- matches = [cur_path .replace (to_replace , '' , 1 ) for cur_path in matches ]
1616
+ # Remove cwd if it was added to match the text readline expects
1617
+ if cwd_added :
1618
+ if cwd == os .path .sep :
1619
+ to_replace = cwd
1620
+ else :
1621
+ to_replace = cwd + os .path .sep
1622
+ matches = [cur_path .replace (to_replace , '' , 1 ) for cur_path in matches ]
1621
1623
1622
- # Restore the tilde string if we expanded one to match the text readline expects
1623
- if expanded_tilde_path :
1624
- matches = [cur_path .replace (expanded_tilde_path , orig_tilde_path , 1 ) for cur_path in matches ]
1624
+ # Restore the tilde string if we expanded one to match the text readline expects
1625
+ if expanded_tilde_path :
1626
+ matches = [cur_path .replace (expanded_tilde_path , orig_tilde_path , 1 ) for cur_path in matches ]
1625
1627
1626
1628
return matches
1627
1629
0 commit comments