Skip to content

Commit

Permalink
0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
anki-code committed Apr 23, 2020
1 parent 3a8e50f commit 1153aaf
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
<p align="center">
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 <a href="https://xon.sh">xonsh</a>.
</p>
<p align="center">
Forget about using mouse to select identifiers, names, paths or URLs.<br>
Forget about searching autocomplete plugins for every app you use.<br>
</p>

<p align="center">
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.
</p>

## 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 <kbd>Alt</kbd> + <kbd>F</kbd> hotkey
* Or type `f__` and press <kbd>Tab</kbd> 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<Alt+F>
$ 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<Alt+F>
$ echo I should try xontrib-fishout
$ echo I should try xontrib-output-search
```

## Development
Expand Down
16 changes: 8 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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='[email protected]',
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',
Expand Down
28 changes: 14 additions & 14 deletions xontrib/fishout.py → xontrib/output_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -31,28 +31,28 @@ 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))
else:
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:
Expand All @@ -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
2 changes: 1 addition & 1 deletion xontrib/test_tokenizer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fishout import _tokenizer
from output_search import _tokenizer

def test_tokenizer_empty():
assert _tokenizer('') == set()
Expand Down

0 comments on commit 1153aaf

Please sign in to comment.