From 1153aaf6f8df744facbee441d083ab18f1dcc64f Mon Sep 17 00:00:00 2001 From: anki-code Date: Thu, 23 Apr 2020 17:24:44 +0300 Subject: [PATCH] 0.1.1 --- README.md | 22 +++++++++---------- setup.py | 16 +++++++------- xontrib/{fishout.py => output_search.py} | 28 ++++++++++++------------ xontrib/test_tokenizer.py | 2 +- 4 files changed, 34 insertions(+), 34 deletions(-) rename xontrib/{fishout.py => output_search.py} (70%) diff --git a/README.md b/README.md index 1bbfcf4..afd7172 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@

-Fish out tokens from the previous command output and use them for the next command. +Get tokens (identifiers/names/paths/URLs) from the previous command output and use them for the next command in xonsh.

Forget about using mouse to select identifiers, names, paths or URLs.
@@ -7,34 +7,34 @@ Forget about searching autocomplete plugins for every app you use.

-If you like the idea of xontrib-fishout click ⭐ on the repo and stay tuned. +If you like the idea of xontrib-output-search click ⭐ on the repo and stay tuned.

## Install ```shell script -xpip install -U git+https://github.com/anki-code/xontrib-fishout -echo 'xontrib load fishout' >> ~/.xonshrc +xpip install -U git+https://github.com/anki-code/xontrib-output-search +echo 'xontrib load output_search' >> ~/.xonshrc ``` ## Usage -After `xontrib load fishout` you can select tokens from latest output: +After `xontrib load output_search` you can select tokens from latest output: * Press Alt + F hotkey * Or type `f__` and press Tab key For example to get the tokens which contains `xon`: ```shell script -$ echo "Fish out from any output with https://github.com/anki-code/xontrib-fishout" -Fish out from any output with https://github.com/anki-code/xontrib-fishout +$ echo "Fish out from any output with https://github.com/anki-code/xontrib-output-search" +Fish out from any output with https://github.com/anki-code/xontrib-output-search $ git clone xon -$ git clone https://github.com/anki-code/xontrib-fishout +$ git clone https://github.com/anki-code/xontrib-output-search ``` Another example: ```shell script -$ echo '{"Try": "xontrib-fishout"}' # JSON data -{"Try": "xontrib-fishout"} +$ echo '{"Try": "xontrib-output-search"}' # JSON data +{"Try": "xontrib-output-search"} $ echo I should try x -$ echo I should try xontrib-fishout +$ echo I should try xontrib-output-search ``` ## Development diff --git a/setup.py b/setup.py index 1678f55..5ea5c05 100644 --- a/setup.py +++ b/setup.py @@ -8,23 +8,23 @@ long_description = '' setup( - name='xontrib-fishout', - version='0.1.0', + name='xontrib-output-search', + version='0.1.1', license='BSD', author='anki', author_email='author@example.com', - description="Fish out new arguments from previous command output in xonsh", + description="Get tokens (identifiers/names/paths/URLs) from the previous command output and use them for the next command in xonsh.", long_description=long_description, long_description_content_type='text/markdown', packages=['xontrib'], package_dir={'xontrib': 'xontrib'}, - package_data={'xontrib': ['fishout.py']}, + package_data={'xontrib': ['output_search.py']}, platforms='any', - url='https://github.com/anki-code/xontrib-fishout', + url='https://github.com/anki-code/xontrib-output-search', project_urls={ - "Documentation": "https://github.com/anki-code/xontrib-fishout/blob/master/README.md", - "Code": "https://github.com/anki-code/xontrib-fishout", - "Issue tracker": "https://github.com/anki-code/xontrib-fishout/issues", + "Documentation": "https://github.com/anki-code/xontrib-output-search/blob/master/README.md", + "Code": "https://github.com/anki-code/xontrib-output-search", + "Issue tracker": "https://github.com/anki-code/xontrib-output-search/issues", }, classifiers=[ 'Environment :: Console', diff --git a/xontrib/fishout.py b/xontrib/output_search.py similarity index 70% rename from xontrib/fishout.py rename to xontrib/output_search.py index 6f2384e..b4c7d99 100644 --- a/xontrib/fishout.py +++ b/xontrib/output_search.py @@ -2,14 +2,14 @@ import re -fishout_prefix = 'f__' +output_search_prefix = 'f__' clean_regexp = re.compile(r'[\n\r\t]') color_regexp = re.compile(r'(\x9B|\x1B\[)[0-?]*[ -/]*[@-~]') framed_regexp = re.compile(r'^["\'{,:]*(.+?)[,}"\':]*$') def _generator(token): """ - Create alternatives for token. Example: token '"Value"' has unquoted 'Value' alternative. + Create alternatives for token. """ token_variation = [] if len(token) > 2: @@ -31,13 +31,13 @@ def _tokenizer(text, substring=''): return set(selected_tokens) -def _xontrib_fishout_completer(prefix, line, begidx, endidx, ctx): +def _xontrib_output_search_completer(prefix, line, begidx, endidx, ctx): """ - To get suggestion of latest output tokens use Alt+F hotkey or f__ prefix before tab key. + Get new arguments from previous command output use Alt+F hotkey or f__ prefix before tab key. """ - if prefix.startswith(fishout_prefix): - prefix_text = prefix[len(fishout_prefix):] - text = __xonsh__.xontrib_fishout_previous_output + if prefix.startswith(output_search_prefix): + prefix_text = prefix[len(output_search_prefix):] + text = __xonsh__.xontrib_output_search_previous_output tokens = _tokenizer(text, substring=prefix_text) if text else [] if tokens: return (tokens, len(prefix)) @@ -45,14 +45,14 @@ def _xontrib_fishout_completer(prefix, line, begidx, endidx, ctx): return (set([prefix_text]), len(prefix)) -__xonsh__.completers['xontrib_fishout'] = _xontrib_fishout_completer -__xonsh__.completers.move_to_end('xontrib_fishout', last=False) +__xonsh__.completers['xontrib_output_search'] = _xontrib_output_search_completer +__xonsh__.completers.move_to_end('xontrib_output_search', last=False) -__xonsh__.xontrib_fishout_previous_output = None +__xonsh__.xontrib_output_search_previous_output = None @events.on_postcommand def _save_output(cmd: str, rtn: int, out: str or None, ts: list): if out is not None and str(out).strip() != '': - __xonsh__.xontrib_fishout_previous_output = out + __xonsh__.xontrib_output_search_previous_output = out try: @@ -65,16 +65,16 @@ def outout_keybindings(prompter, history, completer, bindings, **kw): @bindings.add('escape', 'f') def _(event): - if __xonsh__.xontrib_fishout_previous_output is not None: + if __xonsh__.xontrib_output_search_previous_output is not None: text = event.current_buffer.text splitted = str(text).split(' ') space = '' if text == '' or len(splitted) == 1 else ' ' prefix = splitted[-1] - text_with_completer = ' '.join(splitted[:-1]) + f'{space}{fishout_prefix}{prefix}' + text_with_completer = ' '.join(splitted[:-1]) + f'{space}{output_search_prefix}{prefix}' event.current_buffer.reset() event.current_buffer.insert_text(text_with_completer) event.current_buffer.start_completion(select_first=True) except Exception as e: - print('xontrib-fishout: Cannot set shortcuts') + print('xontrib-output-search: Cannot set shortcuts') raise diff --git a/xontrib/test_tokenizer.py b/xontrib/test_tokenizer.py index 8686c77..9a32a24 100644 --- a/xontrib/test_tokenizer.py +++ b/xontrib/test_tokenizer.py @@ -1,4 +1,4 @@ -from fishout import _tokenizer +from output_search import _tokenizer def test_tokenizer_empty(): assert _tokenizer('') == set()