Skip to content

Commit 94156f8

Browse files
committed
Figured out how to detect the second tab press. Writing parameter hinting to stderr to bypass bash completion handling.
1 parent c051c84 commit 94156f8

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

cmd2/argcomplete_bridge.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,14 @@ def __call__(self, argument_parser, completer=None, always_complete_options=True
228228
output_stream.write(ifs.join(completions).encode(argcomplete.sys_encoding))
229229
elif outstr:
230230
# if there are no completions, but we got something from stdout, try to print help
231-
232231
# trick the bash completion into thinking there are 2 completions that are unlikely
233232
# to ever match.
234-
outstr = outstr.replace('\n', ' ').replace('\t', ' ').replace(' ', ' ').strip()
235-
# generate a filler entry that should always sort first
236-
filler = ' {0:><{width}}'.format('', width=len(outstr)/2)
237-
outstr = ifs.join([filler, outstr])
238233

239-
output_stream.write(outstr.encode(argcomplete.sys_encoding))
234+
comp_type = int(os.environ["COMP_TYPE"])
235+
if comp_type == 63: # type is 63 for second tab press
236+
print(outstr.rstrip(), file=argcomplete.debug_stream, end='')
237+
238+
output_stream.write(ifs.join([ifs, ' ']).encode(argcomplete.sys_encoding))
240239
else:
241240
# if completions is None we assume we don't know how to handle it so let bash
242241
# go forward with normal filesystem completion

cmd2/argparse_completer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,9 @@ def _match_argument(self, action, arg_strings_pattern):
877877

878878
return super(ACArgumentParser, self)._match_argument(action, arg_strings_pattern)
879879

880-
def _parse_known_args(self, arg_strings, namespace):
880+
# This is the official python implementation with a 5 year old patch applied
881+
# See the comment below describing the patch
882+
def _parse_known_args(self, arg_strings, namespace): # pragma: no cover
881883
# replace arg strings that are file references
882884
if self.fromfile_prefix_chars is not None:
883885
arg_strings = self._read_args_from_files(arg_strings)

0 commit comments

Comments
 (0)