node-fzf
fzf inspired fuzzy CLI list selection 🎀
Easy to use
#### CLI usage
npm install -g node-fzf
# by default (TTY mode) will glob list of current dir files
nfzf
# using pipes
find . | nfzf | xargs cat | less
mpv "`find ~/Dropbox/music | nfzf --exact --keep-right`" --no-audio-display
alias merge="git branch | nfzf | xargs git merge"
alias checkout="git branch | nfzf | xargs git checkout"#### API usage
##### promises
const nfzf = require( 'node-fzf' )
// if you only care about r.query
// nfzf.getInput( label )
const opts = {
/* required */
list: [ 'whale', 'giraffe', 'monkey' ],
/* (optional) */
// filtering mode (user can change modes by pressing ctrl-s)
mode: 'fuzzy' || 'normal',/ (optional) / // prefill user input query: '',
/ (optional) / // If there is only one match for the initial query (--query), do not // start interactive finder and automatically select the only match selectOne: false,
/ (optional) / // % of screen to use to display results (minimum/defaults to 6 rows) height: 0, // ex: 40 for 40%, 100 for 100%
/ (optional) / // text before each displayed line, list index supplied as arg prelinehook: function ( index ) { return '' },
/ (optional) / // text after each displayed line, list index supplied as arg postlinehook: function ( index ) { return '' } }
;( async function () { // opens interactive selection CLI // note! this messes with stdout so if you are // writing to stdout at the same time it will look a bit messy.. const result = await nfzf( opts )
const { selected, query } = result
if( !selected ) { console.log( 'No matches for:', query ) } else { console.log( selected.value ) // 'giraffe' console.log( selected.index ) // 1 console.log( selected.value === opts.list[ selected.index ] ) // true } } )()
// can also add more items later.. setInterval( function () { opts.list.push( 'foobar' )
// an .update method has been attached to the object/array // that you gave to nfzf( ... ) opts.update( list ) }, 1000 )