Skip to main content

An interactive alternative to grep and awk

Project description

ohk, an interactive replacement to tools like grep and awk

asciicast

Features:

  • Normal / fuzzy / regex search for lines
  • Case sensitive / insensitive search
  • Keyboard shortcuts

Installation

 pip install git+https://github.com/kbairak/ohk

or

 git clone https://github.com/kbairak/ohk
→ cd ohk
→ pip install .

Add sudo or --user to your pip install command depending on your setup

Usage

 [previous command | ] ohk [-f / -r / -i] [ | next command]

The previous command's output will be piped into ohk which will start an interactive session to help you filter its lines and columns. Once you press enter inside the interactive session, the filtered output will piped into the next command.

If the previous command is missing (ie if ohk's standard input is the keyboard), you will be asked to provide a command before the interactive session starts:

  ohk | xargs docker stop
Enter command:

If the next command is missing (ie if ohk's standard output is the terminal screen), you will be asked to provide one after you make your selection.

You can even use pipes in the output command and even re-invoke ohk:

  docker ps -a | ohk
Tips:
  - use 'cat' (or leave empty) to print to terminal
  - use 'xargs' to pass output as argument
  - use '{}' placeholder to pass output as argument
  - use 'ohk' to re-run ohk on the results
  - append ' | ohk' to run ohk on the command's output
Pipe output to: sort | uniq | ohk

Note: You should not use ohk twice in the chain of processes because they will launch in parallel and both try to take over the screen and keyboard

Keyboard shortcuts

Esc Quit ohk
Enter Finalize selection
Alt-E Change search mode
Alt-I Change case sensitivity
←↓↑→ / Alt-hjkl / (shift) tab Focus rows/columns
Space Select row/column
Alt-123456789 Select numbered column
Left click Select column
Alt-A/C Select all/none rows/columns
Alt-R Rerun ohk with currently selected output

Command line options

usage: ohk [-h] [-f] [-r] [-i]

optional arguments:
  -h, --help            show this help message and exit
  -f, --fuzzy
  -r, --regex
  -i, --case-insensitive

TODOs

  • Use Ctrl- shortcuts
  • Set output as environment variable on the outer shell (will probably need the user to set an alias)
  • Scroll
  • Search for column title
  • Decorate
  • Organize code better

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ohk-0.0.1.tar.gz (21.0 kB view hashes)

Uploaded Source

Built Distribution

ohk-0.0.1-py3-none-any.whl (20.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page