summaryrefslogtreecommitdiff
path: root/cmd2.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2018-03-18 16:04:55 -0400
committerGitHub <noreply@github.com>2018-03-18 16:04:55 -0400
commit627360cfc71995af939569b2aee9dbc8141544d0 (patch)
tree8943d62abcc30d325061041788541fba577e0692 /cmd2.py
parent4f63fdfdc9bf52e99220cd4b1a7a09ea5d78b239 (diff)
parent083080b5ae00a2a01b009bea85cd03a34cacf133 (diff)
downloadcmd2-git-627360cfc71995af939569b2aee9dbc8141544d0.tar.gz
Merge pull request #322 from python-cmd2/tilde
Fixed how we complete ~
Diffstat (limited to 'cmd2.py')
-rwxr-xr-xcmd2.py17
1 files changed, 8 insertions, 9 deletions
diff --git a/cmd2.py b/cmd2.py
index fe55cd93..9b13ff92 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -323,8 +323,6 @@ def path_complete(text, line, begidx, endidx, dir_exe_only=False, dir_only=False
if endidx == len(line) or (endidx < len(line) and line[endidx] != os.path.sep):
add_trailing_sep_if_dir = True
- add_sep_after_tilde = False
-
# Readline places begidx after ~ and path separators (/) so we need to extract any directory
# path that appears before the search text
dirname = line[prev_space_index + 1:begidx]
@@ -342,14 +340,18 @@ def path_complete(text, line, begidx, endidx, dir_exe_only=False, dir_only=False
if not dirname:
dirname = os.getcwd()
elif dirname == '~':
- # If tilde was used without separator, add a separator after the tilde in the completions
- add_sep_after_tilde = True
+ # If a ~ was used without a separator between text, then this is invalid
+ if text:
+ return []
+ # If only a ~ was entered, then complete it with a slash
+ else:
+ return [os.path.sep]
# Build the search string
search_str = os.path.join(dirname, text + '*')
- # Expand "~" to the real user directory
- search_str = os.path.expanduser(search_str)
+ # Expand "~" to the real user directory
+ search_str = os.path.expanduser(search_str)
# Find all matching path completions
path_completions = glob.glob(search_str)
@@ -376,9 +378,6 @@ def path_complete(text, line, begidx, endidx, dir_exe_only=False, dir_only=False
# If it is a file and we are at the end of the line, then add a space
if os.path.isfile(path_completions[0]) and endidx == len(line):
completions[0] += ' '
- # If tilde was expanded without a separator, prepend one
- elif os.path.isdir(path_completions[0]) and add_sep_after_tilde:
- completions[0] = os.path.sep + completions[0]
completions.sort()
return completions