@@ -824,56 +824,8 @@ def tokens_for_completion(self, line: str, begidx: int, endidx: int) -> Tuple[Li
824
824
# Return empty lists since this means the line is malformed.
825
825
return [], []
826
826
827
- # We need to treat redirection characters (|, <, >) as word breaks when they are in unquoted strings.
828
- # Go through each token and further split them on these characters. Each run of redirect characters
829
- # is treated as a single token.
830
- raw_tokens = []
831
-
832
- for cur_initial_token in initial_tokens :
833
-
834
- # Save tokens up to 1 character in length or quoted tokens. No need to parse these.
835
- if len (cur_initial_token ) <= 1 or cur_initial_token [0 ] in constants .QUOTES :
836
- raw_tokens .append (cur_initial_token )
837
- continue
838
-
839
- # Iterate over each character in this token
840
- cur_index = 0
841
- cur_char = cur_initial_token [cur_index ]
842
-
843
- # Keep track of the token we are building
844
- cur_raw_token = ''
845
-
846
- while True :
847
- if cur_char not in constants .REDIRECTION_CHARS :
848
-
849
- # Keep appending to cur_raw_token until we hit a redirect char
850
- while cur_char not in constants .REDIRECTION_CHARS :
851
- cur_raw_token += cur_char
852
- cur_index += 1
853
- if cur_index < len (cur_initial_token ):
854
- cur_char = cur_initial_token [cur_index ]
855
- else :
856
- break
857
-
858
- else :
859
- redirect_char = cur_char
860
-
861
- # Keep appending to cur_raw_token until we hit something other than redirect_char
862
- while cur_char == redirect_char :
863
- cur_raw_token += cur_char
864
- cur_index += 1
865
- if cur_index < len (cur_initial_token ):
866
- cur_char = cur_initial_token [cur_index ]
867
- else :
868
- break
869
-
870
- # Save the current token
871
- raw_tokens .append (cur_raw_token )
872
- cur_raw_token = ''
873
-
874
- # Check if we've viewed all characters
875
- if cur_index >= len (cur_initial_token ):
876
- break
827
+ # Further split tokens on punctuation characters
828
+ raw_tokens = self .statement_parser .split_on_punctuation (initial_tokens )
877
829
878
830
# Save the unquoted tokens
879
831
tokens = [utils .strip_quotes (cur_token ) for cur_token in raw_tokens ]
@@ -2299,10 +2251,11 @@ def _set_up_cmd2_readline(self) -> _SavedReadlineSettings:
2299
2251
readline_settings .completer = readline .get_completer ()
2300
2252
readline .set_completer (self .complete )
2301
2253
2302
- # Break words on whitespace, quotes, and redirectors when tab completing
2254
+ # Set the readline word delimiters for completion
2303
2255
completer_delims = " \t \n "
2304
2256
completer_delims += '' .join (constants .QUOTES )
2305
2257
completer_delims += '' .join (constants .REDIRECTION_CHARS )
2258
+ completer_delims += '' .join (self .statement_parser .terminators )
2306
2259
2307
2260
readline_settings .delims = readline .get_completer_delims ()
2308
2261
readline .set_completer_delims (completer_delims )
0 commit comments