summaryrefslogtreecommitdiff
path: root/cmd2.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2018-04-14 22:39:43 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2018-04-14 22:39:43 -0400
commit9393380ed3068c8dc790d1dbcaa55f10e40eb4b5 (patch)
treef5cfd8de9c8e9ad582c93b0cfcced8ce314ed2b4 /cmd2.py
parent5786a961c9c86f060c296fd4db385a9c01585319 (diff)
downloadcmd2-git-9393380ed3068c8dc790d1dbcaa55f10e40eb4b5.tar.gz
Still hammering out adding an opening quote
Diffstat (limited to 'cmd2.py')
-rwxr-xr-xcmd2.py24
1 files changed, 13 insertions, 11 deletions
diff --git a/cmd2.py b/cmd2.py
index eb122575..996a628c 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -2078,26 +2078,28 @@ class Cmd(cmd.Cmd):
# If self.display_matches is empty, then set it to self.completion_matches
# before we alter them. That way the suggestions will reflect how we parsed
# the token being completed and not how readline did.
+ display_matches_delimited = True
if not self.display_matches:
+ display_matches_delimited = False
self.display_matches = copy.copy(self.completion_matches)
# Check if we need to add an opening quote
if not unclosed_quote:
- # Get the common prefix of the matches. This is the actual tab completion.
- # Use display_matches instead of completion_matches to support cases of delimited
- # match strings since only the final part of those matches matter in these checks.
- common_prefix = os.path.commonprefix(self.display_matches)
+ common_prefix = os.path.commonprefix(self.completion_matches)
- # Join all matches into 1 string for ease of searching
- all_matches_str = ''.join(self.display_matches)
-
- # If there is a tab completion and any of the matches have a space,
- # then we will add an opening quote to the completion matches.
- if common_prefix and ' ' in all_matches_str:
+ add_quote = False
+ if display_matches_delimited:
+ display_prefix = os.path.commonprefix(self.display_matches)
+ if (' ' in common_prefix) or (display_prefix and ' ' in ''.join(self.display_matches)):
+ add_quote = True
+ else:
+ if common_prefix and ' ' in ''.join(self.completion_matches):
+ add_quote = True
+ if add_quote:
# Figure out what kind of quote to add and save it as the unclosed_quote
- if '"' in all_matches_str:
+ if '"' in ''.join(self.completion_matches):
unclosed_quote = "'"
else:
unclosed_quote = '"'