summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcmd2.py6
-rw-r--r--tests/test_completion.py4
2 files changed, 5 insertions, 5 deletions
diff --git a/cmd2.py b/cmd2.py
index f0252f48..02a6493e 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -1576,15 +1576,15 @@ class Cmd(cmd.Cmd):
self.allow_closing_quote = False
# Build display_matches and add a slash to directories
- for cur_match in completion_matches:
+ for index, cur_match in enumerate(completion_matches):
# Display only the basename of this path in the tab-completion suggestions
self.display_matches.append(os.path.basename(cur_match))
# Add a separator after directories if the next character isn't already a separator
if os.path.isdir(cur_match) and add_trailing_sep_if_dir:
- completion_matches[-1] += os.path.sep
- self.display_matches[-1] += os.path.sep
+ completion_matches[index] += os.path.sep
+ self.display_matches[index] += os.path.sep
# Remove cwd if it was added
if cwd_added:
diff --git a/tests/test_completion.py b/tests/test_completion.py
index 31f218bf..a68bea43 100644
--- a/tests/test_completion.py
+++ b/tests/test_completion.py
@@ -222,9 +222,9 @@ def test_shell_command_completion_nomatch(cmd2_app):
def test_shell_command_completion_doesnt_complete_when_just_shell(cmd2_app):
text = ''
- line = 'shell'
+ line = 'shell {}'.format(text)
endidx = len(line)
- begidx = 0
+ begidx = endidx - len(text)
assert cmd2_app.complete_shell(text, line, begidx, endidx) == []
def test_shell_command_completion_does_path_completion_when_after_command(cmd2_app, request):