Get identifiers, names, paths, URLs and words from the previous command output and use them for the next command in xonsh.
Project description
Get identifiers, names, paths, URLs and words from the previous command output and use them for the next command in xonsh.
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
xpip install -U xontrib-output-search
Before usage
There are three ways to use output search:
- Recommended. Use tmux to run xonsh and use output search. See instructions below.
- Not recommended. Set
$XONSH_CAPTURE_ALWAYS=True
and be ready some tools will freeze because of capturing e.g.git config --help
. Details: after xonsh release 0.10.0 (4283) you should set$XONSH_CAPTURE_ALWAYS=True
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. In this case the output will be captured from the screen. - Alternative. You can add support 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:
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 Alt + f hotkeys after getting the output of the previous command.
- Mac: Press Control + f hotkeys after getting the output of the previous command.
- Any OS: Type
f__
orf__<beginning of the word you want>
and press Tab.
If you use this key combination for another function and your muscle memory is strong just change the key combination before loading the xontrib:
# Alt+i combination. Meaning for prompt-toolkit: @bindings.add('escape', 'i')
$XONTRIB_OUTPUT_SEARCH_KEY='i'
xontrib load output_search
# 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
# 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 there is the tmux fallback in case the output of last cmd is not available.
Use cases
Get URL from output
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
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
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+
:
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:
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
lolcat -h
# ...
lolcat --s<Alt+F>
lolcat --seed=SEED
Use tokenize-output as a tool
$(echo 'Hello "world"!' | tokenize-output -p).split()
# ['Hello', 'world']
Environement variables
$XONTRIB_OUTPUT_SEARCH_WARNING
- show warnings from xontrib. DefaultTrue
.
Development
The xontrib-output-search is using tokenize-output for tokenizing.
Checking that output_search
xontrib has been loaded:
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__
+ Tab.
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 (4283)
Workaround: Check 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)
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 - the pack of ergonomic xontribs.
- This package was created with xontrib cookiecutter template.
- I was inspired by xontrib-histcpy. Thanks @con-f-use!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file xontrib-output-search-0.6.5.tar.gz
.
File metadata
- Download URL: xontrib-output-search-0.6.5.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | df14663948a55e007172910396b293e9f4c986591ea4fd0a117df95f996923a8 |
|
MD5 | 5caba7e6c4423348996e792bb1553ee1 |
|
BLAKE2b-256 | 06e7370efdf8aafc8ad2a73e2c705e0a6bb849a607eae21f93489393c50a92b3 |
File details
Details for the file xontrib_output_search-0.6.5-py3-none-any.whl
.
File metadata
- Download URL: xontrib_output_search-0.6.5-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e2d8c1130611d0e49082df068e6ac8752cedf2d86685e40262f35b69c2657e8 |
|
MD5 | a79bc7bcc2199f6c9b645a20a232f55b |
|
BLAKE2b-256 | 8d02539877e48511f62c6280fc2435b7054d8aa38668ec96fbec37739b8edb1d |