fnd

command module
v0.0.0-...-07cce8e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2022 License: MIT Imports: 1 Imported by: 0

README

FND

fnd is heavily inspired by fzf but it parses lines as json documents. This allows to search entries by field, output the value of a given field and many other field specific manipulations.

Basic usage

Quickly search through a list of entries parsed from stdin.

  1. Get a list of things.
  2. Search through them, filter them, pick one.
  3. Do something with it

See Full Example

Features

  • Contains parsers to convert your input into documents. line_format.

    • JSON
    curl https://api.exchangerate-api.com/v4/latest/EUR | \
        jq -c '.rates | to_entries[] | {"Currency": .key, "Rate": .value }' | \
            fnd --line_format json
    

    Search currency rate

     

    • Tabular
    ps aux | fnd --line_format tabular
    

    Choose a process with fnd

     

    • Plain
  • Customized command output:

    • Choose wich column to output: --output_column
    # Kill the selected process
    kill -9 $(ps aux | fnd --line_format tabular --output_column 'PID')
    # fnd will output the PID column
    
    • Choose output format with golang templates: --output_template
    echo $(ps aux | fnd --line_format tabular --output_template '{{.PID}}-{{.USER}}')
    # fnd will output PID-USER values
    
  • Sort by column (column value is considered as a string):

    ps aux | fnd --line_format tabular --output_column 'PID' --sorter bycolumn --sortby_column PID
    

Examples

Examples:

  • Open file with vi:

    vi $(fnd-fdfind)
    
  • Pass tabular format (pass a table with a header and separated by spaces )

    ps | fnd --line_format tabular
    
  • You can choose which column will be the output of the command. E.g this is how to kill the process that is chosen in fnd.

    ps | kill -9 $(fnd --line_format tabular --output_column PID)
    

See other examples at commands/:

Troubleshooting

  • My command fails, how can I figure out what's happening ?

    Error logs are by default logged to stderr. To get the detailed error message you can redirect stderr to a log file or pass --log_file. E.g:

    $ fnd 2> out.log
    

Full Example

  1. Get a list of running processes.
ps aux
  1. Pass them to fnd to allow searching through them.
ps aux | fnd
  1. Parse input to obtain processes' fields
ps aux | fnd --line_format tabular
  1. Do something with the output (E.g print the PID)
echo $(ps aux | fnd --line_format tabular --output_column)

License

The MIT License (MIT)

Copyright (c) 2019 Íñigo Mediavilla Saiz

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL