Coder Social home page Coder Social logo

mcfly-fzf's Introduction

McFly fzf integration

Integrate McFly with fzf to combine a solid command history database with a widely-loved fuzzy search UI

Features:

  • Advanced history tracking and prioritization courtesy of McFly
  • Rebinds ctrl-r to use an fzf-based interface
  • Toggle options in fzf interface:
    • F1: Sort by time / neural network score
    • F2: Limit to commands run from current directory / any directory
    • F3: Filter by exit status: [Okay (zero) / Fail (non-zero) / Any]

Screenshot

Installation

  1. Install mcfly: Included with the mcfly-fzf binaries. Alternatively download mcfly release binary, or view other installation options

  2. Install fzf: Download binary, or view other installation options

  3. Install mcfly-fzf: Download binary
    Alternatively, install from source:

    cargo install --git https://github.com/bnprks/mcfly-fzf
    
  4. Make sure that mcfly, fzf, and mcfly-fzf are all added to your $PATH. Following instructions from McFly:

    For example, you could create a directory at ~/bin, copy mcfly to this location, and add export PATH="$PATH:$HOME/bin" to your .bashrc / .zshrc, or run set -Ua fish_user_paths "$HOME/bin" for fish.

  5. Add the following to the end of your ~/.bashrc, ~/.zshrc, or ~/.config/fish/config.fish file:

    Bash:

    eval "$(mcfly init bash)"
    eval "$(mcfly-fzf init bash)"

    Zsh:

    eval "$(mcfly init zsh)"
    eval "$(mcfly-fzf init zsh)"

    Fish:

    mcfly init fish | source
    mcfly-fzf init fish | source

Usage

  • Press ctrl-r to open search:
    • Type to search
    • Arrow keys to navigate up/down
    • Enter to select
    • F1/F2/F3 to adjust view settings
  • Respects the following environment variables
    • MCFLY_HISTORY_LIMIT
    • MCFLY_RESULTS_SORT
    • FZF_DEFAULT_OPTS, FZF_CTRL_R_OPTS (can include multiple options from man fzf)
    • MCFLY_FZF_NO_STRICT_ORDERING: if set, this variable causes mcfly-fzf to default to strict ordering off rather than on for new terminal sessions.
  • To delete history entries, run mcfly search manually

How it works

Overall:

  • mcfly-fzf imports the mcfly crate to access the database.
  • A per-session temporary json file stores the search setting toggles within and between searches.

What happens during ctrl-r:

  1. mcfly-fzf dump reads the mcfly sqlite database and prints the entry to stdout, where it is piped to fzf
  2. Toggling F1/F2/F3 in fzf runs mcfly-fzf toggle, which updates a temporary json file stored at $MCFLY_FZF_OPTS. Then mcfly-fzf dump runs again to re-populate the filtered results for fzf.
  3. After selecting a history item, mcfly-fzf select marks the item in the selected_commands table so that the McFly neural network can prioritize frequently-selected items.

mcfly-fzf's People

Contributors

bnprks avatar kothavade avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

mcfly-fzf's Issues

Bind entry deletion

Hey there, thank you for the very nice tool, awesome work. :)

The README says that "To delete history entries, run mcfly search manually". Is there anything fundamentally blocking us to use mcfly entry deletion directly from fzf?

If not, is it something that you would see into mcfly-fzf? How hard would that be?

Customize time format

Is there a way to customize the time format of the commands in history, e.g. iso, iso-long, or some sort of custom time format? Or alternatively, is there a way to colorize times or something along those lines to improve readability?

How to enable strict ordering by default ?

How to default to strict ordering ?
image

I always end up enabling strict ordering but I couldn't find a MCFLY_ variable that does it.
sry if that's the wrong repo, was not sure wether to report here or mcfly

Make use of fzf-tmux

Please make use of the __fzfcmd function as used in junegunn/fzf/shell/key-bindings.fish

function __fzfcmd
  test -n "$FZF_TMUX"; or set FZF_TMUX 0
  test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
  if [ -n "$FZF_TMUX_OPTS" ]
    echo "fzf-tmux $FZF_TMUX_OPTS -- "
  else if [ $FZF_TMUX -eq 1 ]
    echo "fzf-tmux -d$FZF_TMUX_HEIGHT -- "
  else
    echo "fzf"
  end
end

I'm not very familiar with fish scripting, but it seems to me that we need to make some modifications to this line:

eval $MCFLY_FZF_PATH --history-format fish dump --header -0 --options-json $MCFLY_FZF_OPTS | eval fzf -q '(commandline)' | 

where eval fzf needs to be eval (__fzfcmd).

This is for fish, and similar changes would need to be made for bash and zsh as well.

Consider "unbundling" mcfly?

Hello,

is bundling a specific version of mcfly required?

v0.8.6 has neat features I would like to use (e.g. filtering history dumps), and 0.7.1 is bundled with mcfly-fzf.

Not overriding fzf's Ctrl+R binding

If fzf's key-bindings.fish is enabled as described in the Arch Wiki, and mcfly-fzf is also enabled, mcfly-fzf is not overriding fzf's Ctrl+R binding. Here are the relevant config files:

~/.config/fish/config.fish:

if status is-interactive
    command -q mcfly && mcfly init fish | source
    command -q mcfly-fzf && mcfly-fzf init fish | source
end

~/.config/fish/functions/fish_user_key_bindings.fish:

function fish_user_key_bindings
    fzf_key_bindings
end

I should mention that it's not desirable to turn off fzf's key-bindings.fish because it also contains other key bindings apart from Ctrl+R, such as Ctrl+T and Alt+C.

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.