Giter Club home page Giter Club logo

jff's Introduction

Janet Fuzzy Finder - get through some stdout almost omnisciently and friendly

Alpha Quality SW ahead

My exercise in command-line programming. Think of it as fzf, but without all the fancy stuff, but with one crucial addition: it prints what user has typed if there is no remaining choice, which is excellent in combination with the Tab key.

Even with its simplicity, it has replaced wofi/dmenu utility for me.

Implementation

I am using simple matching and scoring. Best score if choice starts or end with the user input. Second best score if the user input is anywhere in the string. Then fuzzy search with every intermittent char not in user input lower score by -1. All scores start as 0.

Program is stable and responsive until around 1000 (depends on the machine) when the delay starts to be perceivable. I guess it is Janet GC kicking in, as I am not optimizing for memory consumption at all.

Installation:

You need the latest development version of Janet programming language installed. Then you can install jff with the jpm package manager:

[sudo] jpm install https://github.com/pepe/jff.

Usage:

Command line arguments:

 Optional:
 -c, --code VALUE                            Janet function definition to transform result with. The selected choice or the PEG match if grammar provided. Default is print
 -f, --file VALUE                            Read a file rather than stdin for choices.
 -g, --grammar VALUE                         PEG grammar to match with the result. Default nil which means  no matching.
 -h, --help                                  Show this help message.
 -e, --prepare VALUE                         Janet function defition to transform each line with. Default identity.
 -p, --program VALUE                         File with code which must have three function preparer, matcher and transformer.
 -r, --prompt VALUE=>                        Change the prompt. Default: '> '.

jff < $choides will show the choices, and you can start fuzzy finding. List of choices starts to narrow on every char. There are some special, yet standard key combos for navigation:

  • Down/Ctrl-n/Ctrl-j moves the selection down one item
  • Up/Ctrl-p/Ctrl-k moves the selection up one item
  • Tab replaces typed chars with the text of the selection. To narrow the search.
  • Ctrl-c/Escape exits with error without printing anything
  • Enter confirms the current selection and matches/transforms/prints it to stdout

Common

Under the ns jff is common module with some functionality, that can be used in in other programs for jff. Well, for now it is only work with prefix. You can use them easily in your programs:

(import jff/common)

(def prefix (string ((os/environ) "HOME") "/Code/"))

(def prepare (common/remove-prefix prefix))

(def transform (common/prepend-prefix prefix))

This script will strip the prefix from all choices and prepend it back to the result. If you save it in /home/user/bin/jff/code.janet file, you can use it with:

#!/bin/sh

lr -1 -o A -A -t type=d  ~/Code/* ~/Code/*/* ~/Code/*/* ~/Code/*/*/* | \
  jff -r 'sess:> ' -p ~/bin/jff/code.janet | \
  xe swaymsg exec -- alacritty --working-directory {}

to open the new terminal window on selected dir.

Examples

Run the function on the result:

lr -1 | janet jff.janet -c '|(print (string/ascii-upper $))'

Match the result with the grammar and then runs the function:

lr -1 | janet jff.janet -g '(<- (to "."))'
                        -c '|(print (string/ascii-upper (first $)))'

jff's People

Contributors

pepe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

jgarte

jff's Issues

Black boxes?

On an Ubuntu-derivative system, the following leads to some "black boxes":

cd /usr
less $(rg FLT_MIN | jff)

black-box-in-jff

My installation is of commit: a0024d8

Terminal not resetting.

Works well when I actually select something, but when I press escape or ctrl-c out of the selection, my terminal is left in a strange state. Likely a problem with the underlying termbox lib, but I found the issue here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.