xontrib-output-search


Namexontrib-output-search JSON
Version 0.6.5 PyPI version JSON
download
home_pagehttps://github.com/anki-code/xontrib-output-search
SummaryGet identifiers, names, paths, URLs and words from the previous command output and use them for the next command in xonsh.
upload_time2024-02-22 19:42:21
maintainer
docs_urlNone
authoranki-code
requires_python>=3.6
licenseBSD
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <p align="center">
Get identifiers, names, paths, URLs and words from the previous command output and use them for the next command in <a href="https://xon.sh">xonsh</a>.
<br><br>
<img src="https://repository-images.githubusercontent.com/257978984/a0eaac80-0424-11eb-85ad-29809d2f792d">
</p>



## Features

💡 **Universal**. Forget about searching autocomplete plugins for every app you use. Just get the identifiers from the previous output.

⏳ **Save time**. Forget about using mouse, touchpad or trackball to get any words from screen to the next command.

🔒 **Secure**. It works the same way as xonsh shell and the security level is the same.


## Install

```shell script
xpip install -U xontrib-output-search
```

## Before usage

There are three ways to use output search:
* Recommended. Use [tmux](https://en.wikipedia.org/wiki/Tmux) to run xonsh and use output search. See instructions below.
* Not recommended. Set [`$XONSH_CAPTURE_ALWAYS=True`](https://xon.sh/envvars.html#xonsh-capture-always) and be ready some tools will freeze because of capturing e.g. `git config --help`. Details: after [xonsh release 0.10.0](https://github.com/xonsh/xonsh/releases/tag/0.10.0) ([4283](https://github.com/xonsh/xonsh/pull/4283)) you should set [`$XONSH_CAPTURE_ALWAYS=True`](https://xon.sh/envvars.html#xonsh-capture-always) in your `~/.xonshrc` to make output capturable. This approach has issues and we decided that the best solution for output search is to use the terminal window managers and we support [tmux](https://en.wikipedia.org/wiki/Tmux). In this case the output will be captured from the screen.
* Alternative. You can [add support](https://github.com/anki-code/xontrib-output-search/blob/85a5eea39bb33377e236e0ba8e22b5e055f6bce5/xontrib/output_search.py#L81) any terminal emulator or terminal window manager like tmux that can capture the content of the terminal. PR is welcome!

## Usage

The recommended way as described above:

```xsh
zsh
alias tx="tmux new-session xonsh ';' set -g status off"  # add alias to run xonsh in tmux without bottom status bar
tx  # run xonsh in tmux
xontrib load output_search  # add this to ~/.xonshrc
```

After loading you can select tokens from latest not empty output:
* Windows/Linux: Press <kbd>Alt</kbd> + <kbd>f</kbd> hotkeys after getting the output of the previous command.
* Mac: Press <kbd>Control</kbd> + <kbd>f</kbd> hotkeys after getting the output of the previous command.
* Any OS: Type `f__` or `f__<beginning of the word you want>` and press <kbd>Tab</kbd>.

If you use this key combination for another function and your muscle memory is strong just change 
the [key combination](https://python-prompt-toolkit.readthedocs.io/en/master/pages/advanced_topics/key_bindings.html) before 
loading the xontrib:
```python
# Alt+i combination. Meaning for prompt-toolkit: @bindings.add('escape', 'i')
$XONTRIB_OUTPUT_SEARCH_KEY='i'
xontrib load output_search
```
```python
# This approach is recommended for Mac users because `c-<key>` is represented 
# the Control key that has less intersections with other Mac hotkeys. 
#
# Control+g combination. Meaning for prompt-toolkit: @bindings.add('c-g')
$XONTRIB_OUTPUT_SEARCH_KEY_BINDING='c-g'
xontrib load output_search
```
```python
# Right+Left combination. Meaning for prompt-toolkit: @bindings.add('right', 'left')
$XONTRIB_OUTPUT_SEARCH_KEY_META='right'
$XONTRIB_OUTPUT_SEARCH_KEY='left'  # the text placeholder will be `left__`
xontrib load output_search
```

In [tmux](https://en.wikipedia.org/wiki/Tmux) there is [the tmux fallback](https://github.com/anki-code/xontrib-output-search/pull/4) in case the output of last cmd is not available.

## Use cases
#### Get URL from output
```shell script
echo "Try https://github.com/xxh/xxh"
# Try https://github.com/xxh/xxh
git clone xx<Alt+F>
git clone https://github.com/xxh/xxh
```

#### Get key or value from JSON, Python dict and JavaScript object
```shell script
echo '{"Try": "xontrib-output-search"}'
# {"Try": "xontrib-output-search"}
echo I should try se<Alt+F>
echo I should try xontrib-output-search
```    

#### Get the path from environment
```shell script
env | grep ^PATH=
# PATH=/one/two:/three/four
ls fo<Alt+F>
ls /three/four  
```    

#### Complete the complex prefix

Get the URL from previous output after typing `git+`:
```shell script
echo "Try https://github.com/anki-code/xontrib-output-search"
# Try https://github.com/anki-code/xontrib-output-search

pip install git+xo<Alt+F>
pip install git+https://github.com/anki-code/xontrib-output-search
```
Get the port number from previous output while typing the URL:
```shell script
echo "The port number is 4242"
# The port number is 4242

curl http://127.0.0.1:4<Alt+F>
curl http://127.0.0.1:4242
```

#### Get arguments from command help
```shell script
lolcat -h
# ...
lolcat --s<Alt+F>
lolcat --seed=SEED
```

#### Use [tokenize-output](https://github.com/anki-code/tokenize-output) as a tool

```xsh
$(echo 'Hello "world"!' | tokenize-output -p).split()
# ['Hello', 'world']
```

## Environement variables

* `$XONTRIB_OUTPUT_SEARCH_WARNING` - show warnings from xontrib. Default `True`.

## Development

The xontrib-output-search is using [tokenize-output](https://github.com/anki-code/tokenize-output) for tokenizing.

Checking that `output_search` xontrib has been loaded:
```shell script
xontrib list output_search
# output_search  installed  loaded

completer list | grep output_search
# xontrib_output_search
```

## Known issues

#### `Alt+F` may not working in PyCharm terminal
Workaround: `f__` + <kbd>Tab</kbd>.

#### `Alt+F` in the readline is to move forward
Workaround: set `$XONTRIB_OUTPUT_SEARCH_KEY='i'` before `xontrib load output_search`.

#### Not working after [xonsh 0.10.0](https://github.com/xonsh/xonsh/releases/tag/0.10.0) ([4283](https://github.com/xonsh/xonsh/pull/4283))

Workaround: Check [`XONSH_CAPTURE_ALWAYS`](https://xon.sh/envvars.html#xonsh-capture-always) environment variable to bring the capturing of the output back i.e. `$XONSH_CAPTURE_ALWAYS=True`.

#### `cat file` is not captured ([xonsh/issues/3744](https://github.com/xonsh/xonsh/issues/3744))
Workaround: `cat file | head` or `cat file | grep text`.

#### The readline shell type was not tested

We're using the xonsh recommended prompt-toolkit shell type to test the output search xontrib. There could be the issues in the readline shell type. PRs are welcome!

## Links 
* This package is the part of [ergopack](https://github.com/anki-code/xontrib-ergopack) - the pack of ergonomic xontribs.
* This package was created with [xontrib cookiecutter template](https://github.com/xonsh/xontrib-cookiecutter).
* I was inspired by [xontrib-histcpy](https://github.com/con-f-use/xontrib-histcpy). Thanks @con-f-use!

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/anki-code/xontrib-output-search",
    "name": "xontrib-output-search",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "",
    "author": "anki-code",
    "author_email": "author@example.com",
    "download_url": "https://files.pythonhosted.org/packages/06/e7/370efdf8aafc8ad2a73e2c705e0a6bb849a607eae21f93489393c50a92b3/xontrib-output-search-0.6.5.tar.gz",
    "platform": "any",
    "description": "<p align=\"center\">\nGet identifiers, names, paths, URLs and words from the previous command output and use them for the next command in <a href=\"https://xon.sh\">xonsh</a>.\n<br><br>\n<img src=\"https://repository-images.githubusercontent.com/257978984/a0eaac80-0424-11eb-85ad-29809d2f792d\">\n</p>\n\n\n\n## Features\n\n\ud83d\udca1 **Universal**. Forget about searching autocomplete plugins for every app you use. Just get the identifiers from the previous output.\n\n\u23f3 **Save time**. Forget about using mouse, touchpad or trackball to get any words from screen to the next command.\n\n\ud83d\udd12 **Secure**. It works the same way as xonsh shell and the security level is the same.\n\n\n## Install\n\n```shell script\nxpip install -U xontrib-output-search\n```\n\n## Before usage\n\nThere are three ways to use output search:\n* Recommended. Use [tmux](https://en.wikipedia.org/wiki/Tmux) to run xonsh and use output search. See instructions below.\n* Not recommended. Set [`$XONSH_CAPTURE_ALWAYS=True`](https://xon.sh/envvars.html#xonsh-capture-always) and be ready some tools will freeze because of capturing e.g. `git config --help`. Details: after [xonsh release 0.10.0](https://github.com/xonsh/xonsh/releases/tag/0.10.0) ([4283](https://github.com/xonsh/xonsh/pull/4283)) you should set [`$XONSH_CAPTURE_ALWAYS=True`](https://xon.sh/envvars.html#xonsh-capture-always) in your `~/.xonshrc` to make output capturable. This approach has issues and we decided that the best solution for output search is to use the terminal window managers and we support [tmux](https://en.wikipedia.org/wiki/Tmux). In this case the output will be captured from the screen.\n* Alternative. You can [add support](https://github.com/anki-code/xontrib-output-search/blob/85a5eea39bb33377e236e0ba8e22b5e055f6bce5/xontrib/output_search.py#L81) any terminal emulator or terminal window manager like tmux that can capture the content of the terminal. PR is welcome!\n\n## Usage\n\nThe recommended way as described above:\n\n```xsh\nzsh\nalias tx=\"tmux new-session xonsh ';' set -g status off\"  # add alias to run xonsh in tmux without bottom status bar\ntx  # run xonsh in tmux\nxontrib load output_search  # add this to ~/.xonshrc\n```\n\nAfter loading you can select tokens from latest not empty output:\n* Windows/Linux: Press <kbd>Alt</kbd> + <kbd>f</kbd> hotkeys after getting the output of the previous command.\n* Mac: Press <kbd>Control</kbd> + <kbd>f</kbd> hotkeys after getting the output of the previous command.\n* Any OS: Type `f__` or `f__<beginning of the word you want>` and press <kbd>Tab</kbd>.\n\nIf you use this key combination for another function and your muscle memory is strong just change \nthe [key combination](https://python-prompt-toolkit.readthedocs.io/en/master/pages/advanced_topics/key_bindings.html) before \nloading the xontrib:\n```python\n# Alt+i combination. Meaning for prompt-toolkit: @bindings.add('escape', 'i')\n$XONTRIB_OUTPUT_SEARCH_KEY='i'\nxontrib load output_search\n```\n```python\n# This approach is recommended for Mac users because `c-<key>` is represented \n# the Control key that has less intersections with other Mac hotkeys. \n#\n# Control+g combination. Meaning for prompt-toolkit: @bindings.add('c-g')\n$XONTRIB_OUTPUT_SEARCH_KEY_BINDING='c-g'\nxontrib load output_search\n```\n```python\n# Right+Left combination. Meaning for prompt-toolkit: @bindings.add('right', 'left')\n$XONTRIB_OUTPUT_SEARCH_KEY_META='right'\n$XONTRIB_OUTPUT_SEARCH_KEY='left'  # the text placeholder will be `left__`\nxontrib load output_search\n```\n\nIn [tmux](https://en.wikipedia.org/wiki/Tmux) there is [the tmux fallback](https://github.com/anki-code/xontrib-output-search/pull/4) in case the output of last cmd is not available.\n\n## Use cases\n#### Get URL from output\n```shell script\necho \"Try https://github.com/xxh/xxh\"\n# Try https://github.com/xxh/xxh\ngit clone xx<Alt+F>\ngit clone https://github.com/xxh/xxh\n```\n\n#### Get key or value from JSON, Python dict and JavaScript object\n```shell script\necho '{\"Try\": \"xontrib-output-search\"}'\n# {\"Try\": \"xontrib-output-search\"}\necho I should try se<Alt+F>\necho I should try xontrib-output-search\n```    \n\n#### Get the path from environment\n```shell script\nenv | grep ^PATH=\n# PATH=/one/two:/three/four\nls fo<Alt+F>\nls /three/four  \n```    \n\n#### Complete the complex prefix\n\nGet the URL from previous output after typing `git+`:\n```shell script\necho \"Try https://github.com/anki-code/xontrib-output-search\"\n# Try https://github.com/anki-code/xontrib-output-search\n\npip install git+xo<Alt+F>\npip install git+https://github.com/anki-code/xontrib-output-search\n```\nGet the port number from previous output while typing the URL:\n```shell script\necho \"The port number is 4242\"\n# The port number is 4242\n\ncurl http://127.0.0.1:4<Alt+F>\ncurl http://127.0.0.1:4242\n```\n\n#### Get arguments from command help\n```shell script\nlolcat -h\n# ...\nlolcat --s<Alt+F>\nlolcat --seed=SEED\n```\n\n#### Use [tokenize-output](https://github.com/anki-code/tokenize-output) as a tool\n\n```xsh\n$(echo 'Hello \"world\"!' | tokenize-output -p).split()\n# ['Hello', 'world']\n```\n\n## Environement variables\n\n* `$XONTRIB_OUTPUT_SEARCH_WARNING` - show warnings from xontrib. Default `True`.\n\n## Development\n\nThe xontrib-output-search is using [tokenize-output](https://github.com/anki-code/tokenize-output) for tokenizing.\n\nChecking that `output_search` xontrib has been loaded:\n```shell script\nxontrib list output_search\n# output_search  installed  loaded\n\ncompleter list | grep output_search\n# xontrib_output_search\n```\n\n## Known issues\n\n#### `Alt+F` may not working in PyCharm terminal\nWorkaround: `f__` + <kbd>Tab</kbd>.\n\n#### `Alt+F` in the readline is to move forward\nWorkaround: set `$XONTRIB_OUTPUT_SEARCH_KEY='i'` before `xontrib load output_search`.\n\n#### Not working after [xonsh 0.10.0](https://github.com/xonsh/xonsh/releases/tag/0.10.0) ([4283](https://github.com/xonsh/xonsh/pull/4283))\n\nWorkaround: Check [`XONSH_CAPTURE_ALWAYS`](https://xon.sh/envvars.html#xonsh-capture-always) environment variable to bring the capturing of the output back i.e. `$XONSH_CAPTURE_ALWAYS=True`.\n\n#### `cat file` is not captured ([xonsh/issues/3744](https://github.com/xonsh/xonsh/issues/3744))\nWorkaround: `cat file | head` or `cat file | grep text`.\n\n#### The readline shell type was not tested\n\nWe're using the xonsh recommended prompt-toolkit shell type to test the output search xontrib. There could be the issues in the readline shell type. PRs are welcome!\n\n## Links \n* This package is the part of [ergopack](https://github.com/anki-code/xontrib-ergopack) - the pack of ergonomic xontribs.\n* This package was created with [xontrib cookiecutter template](https://github.com/xonsh/xontrib-cookiecutter).\n* I was inspired by [xontrib-histcpy](https://github.com/con-f-use/xontrib-histcpy). Thanks @con-f-use!\n",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "Get identifiers, names, paths, URLs and words from the previous command output and use them for the next command in xonsh.",
    "version": "0.6.5",
    "project_urls": {
        "Code": "https://github.com/anki-code/xontrib-output-search",
        "Documentation": "https://github.com/anki-code/xontrib-output-search/blob/master/README.md",
        "Homepage": "https://github.com/anki-code/xontrib-output-search",
        "Issue tracker": "https://github.com/anki-code/xontrib-output-search/issues"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8d02539877e48511f62c6280fc2435b7054d8aa38668ec96fbec37739b8edb1d",
                "md5": "a79bc7bcc2199f6c9b645a20a232f55b",
                "sha256": "7e2d8c1130611d0e49082df068e6ac8752cedf2d86685e40262f35b69c2657e8"
            },
            "downloads": -1,
            "filename": "xontrib_output_search-0.6.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a79bc7bcc2199f6c9b645a20a232f55b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 6662,
            "upload_time": "2024-02-22T19:42:20",
            "upload_time_iso_8601": "2024-02-22T19:42:20.378924Z",
            "url": "https://files.pythonhosted.org/packages/8d/02/539877e48511f62c6280fc2435b7054d8aa38668ec96fbec37739b8edb1d/xontrib_output_search-0.6.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "06e7370efdf8aafc8ad2a73e2c705e0a6bb849a607eae21f93489393c50a92b3",
                "md5": "5caba7e6c4423348996e792bb1553ee1",
                "sha256": "df14663948a55e007172910396b293e9f4c986591ea4fd0a117df95f996923a8"
            },
            "downloads": -1,
            "filename": "xontrib-output-search-0.6.5.tar.gz",
            "has_sig": false,
            "md5_digest": "5caba7e6c4423348996e792bb1553ee1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 6770,
            "upload_time": "2024-02-22T19:42:21",
            "upload_time_iso_8601": "2024-02-22T19:42:21.865396Z",
            "url": "https://files.pythonhosted.org/packages/06/e7/370efdf8aafc8ad2a73e2c705e0a6bb849a607eae21f93489393c50a92b3/xontrib-output-search-0.6.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-22 19:42:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "anki-code",
    "github_project": "xontrib-output-search",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "xontrib-output-search"
}
        
Elapsed time: 0.74606s