Skip to content

Commit

Permalink
Fix f__ support
Browse files Browse the repository at this point in the history
  • Loading branch information
anki-code committed Apr 25, 2020
1 parent d318bd8 commit f98bf72
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name='xontrib-output-search',
version='0.3.0',
version='0.3.1',
license='BSD',
author='anki',
author_email='[email protected]',
Expand Down
19 changes: 11 additions & 8 deletions xontrib/output_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,26 +153,29 @@ def _xontrib_output_search_completer(prefix, line, begidx, endidx, ctx):
"""
Get new arguments from previous command output use Alt+F hotkey or f__ prefix before tab key.
"""
if __xonsh__.xontrib_output_search_completion or prefix.startswith(output_search_prefix):
is_output_search_prefix = prefix.startswith(output_search_prefix)
if __xonsh__.xontrib_output_search_completion or is_output_search_prefix:
__xonsh__.xontrib_output_search_completion = False
current_cmd = {'prefix': prefix, 'line': line, 'begidx': begidx, 'endidx': endidx}
prev = __xonsh__.xontrib_output_search_previous_output
if 'output' in prev:
cmd = prev['cmd']
output = prev['output']
tokens = _parse(text=output, text_cmd=cmd, substring=prefix, current_cmd=current_cmd)
substring = prefix[len(output_search_prefix):] if is_output_search_prefix else prefix
tokens = _parse(text=output, text_cmd=cmd, substring=substring, current_cmd=current_cmd)
if add_previous_cmd_to_output:
tokens = set.union(tokens, _parse(text=cmd, text_cmd=cmd, substring=prefix, current_cmd=current_cmd))
tokens = set.union(tokens, _parse(text=cmd, text_cmd=cmd, substring=substring, current_cmd=current_cmd))

if support_special_chars_in_prefix and tokens == set():
if support_special_chars_in_prefix and tokens == set() and not is_output_search_prefix:
sc_pos = prev_special_char_pos(prefix)
if sc_pos is not None:
prefix_after_char = prefix[sc_pos + 1:]
prefix_before_char = prefix[:sc_pos + 1]
tokens = _parse(text=output, text_cmd=cmd, substring=prefix_after_char, current_cmd=current_cmd)
if add_previous_cmd_to_output:
tokens = set.union(tokens, _parse(text=cmd, text_cmd=cmd, substring=prefix, current_cmd=current_cmd))
tokens = set([prefix_before_char + t for t in tokens])
if prefix_before_char != output_search_prefix:
tokens = _parse(text=output, text_cmd=cmd, substring=prefix_after_char, current_cmd=current_cmd)
if add_previous_cmd_to_output:
tokens = set.union(tokens, _parse(text=cmd, text_cmd=cmd, substring=prefix, current_cmd=current_cmd))
tokens = set([prefix_before_char + t for t in tokens])

tokens = tokens if tokens else set([prefix])
return (tokens, len(prefix))
Expand Down

0 comments on commit f98bf72

Please sign in to comment.