Hacker News new | past | comments | ask | show | jobs | submit login
Fzf – the basics part 1 – layout (qmacro.org)
136 points by todsacerdoti on Feb 4, 2021 | hide | past | favorite | 38 comments



My favorite ~/.gitconfig [alias] that uses fzf:

  # Allows you to easily pick what to rebase
  frbi = "!f() { git rebase -i $(git log --pretty=oneline --color=always | fzf --ansi | cut -d ' ' -f1)^ ; }; f"
Then just do:

  git frbi


Same! I use it for switching between branches:

    sw = !git checkout $(git branch -a --format '%(refname:short)' | sed 's~origin/~~' | sort | uniq | fzf)
Just type `git sw` and fzfuzzy type the branch name you want to go to.


Here's some additional FZF Git love posted by junegunn a while back. https://junegunn.kr/2016/07/fzf-git/


love this, shows how simple fzf is to use as well. just gives us a nice way to pick out a line from git log. Beautiful.


This is a gem, thanks!


I love fzf as well. I use it with the npm package manager to select the script to run (we have an app with 20+ scripts):

    npmrf () {
        local script
        script=$(cat package.json | jq -r '.scripts | keys[] ' | sort | fzf)  && npm run $script
    }
Another usecase is tracking hours with Clockify. I was frustrated opening up the web everytime, so I wrote a script using fzf, httpie and jq. Love it now. [1]

[1]: https://marcel.is/tracking-hours/


That's a great idea, thanks. Do you know how to get it to show the preview window with the script value? Sometimes I need to explore which script task I need based on what it does


You could do something like this (not super thoroughly tested):

  npmrf () {
    local script
    script=$(jq -r '.scripts | to_entries[] | "\(.key) => \(.value)"' < package.json | sort | fzf | cut -d' ' -f1) && npm run "$script"
  }

It uses jq's to_entries to pull out the script/command key pairs and then just cuts out the script name after you choose the command (assumes the command name doesn't have spaces).


Yeah, that would be nice. I don't know though from the top of my head.


plocate is a very fast mlocate alternative that uses indexes over trigrams and io_uring for reading the database. With fzf you can have a pretty fast fuzzy search over your entire indexed disk.

    FZF_DEFAULT_COMMAND="plocate ''" \
    fzf --bind "change:reload:plocate {q} || true" \
        --ansi --phony --query "" --preview 'file {}' --bind '?:preview:cat {}'

https://plocate.sesse.net/

I don't actually use it. It's more a fun hack.


thanks for this, I just replaced my mlocate. absolutely unreal. seems io_uring makes all the difference.


Hi,

I'm the author of plocate. io_uring is not the primary part of the difference; it makes for a pretty good win if you have rotating disks (especially when you have many matches to test), but on SSD, it's pretty much inconsequential. The biggest difference really comes from the use of an index, as opposed to matching every single candidate against the pattern.


Fzf might be my most used command line utility. That and autojump (alias to j).


I use z[0] in place of autojump. That way I don't need to install Python solely for autojump. This is especially true, when sshing to servers.

[0]:https://github.com/rupa/z


Theres also fasd. It has z emulation.

https://github.com/clvv/fasd


I've moved to https://github.com/ajeetdsouza/zoxide/ from z, as it can also show you a list of matching directories using fzf


    # https://github.com/junegunn/fzf/wiki/Examples#integration-with-z
    # like normal z when used with arguments but displays an fzf prompt when used without.

    unalias z 2> /dev/null

    z() {
      [ $# -gt 0 ] && _z "$*" && return
      cd "$(_z -l 2>&1 | fzf --height 40% --nth 2.. --reverse --inline-info +s --tac --query "${*##-* }" | sed 's/^[0-9,.]* *//')"
    }


or its zsh native port https://github.com/agkozak/zsh-z


I use it everywhere because it basically gives you a list-based UI layer over shell functions. It's endlessly useful and admirably unix-y.


I'm a big fan of autojump but switch to the Rust port recently.

https://github.com/ajeetdsouza/zoxide


Damn, there seems to be so many Rust cmd tools recently that it's hard to keep up with what's new ;)

Thanks, I was using https://github.com/badmotorfinger/z for powershell before. I will check it out.


PsFzf + ZLocation for Powershell :)


This thing is magical! I use it as a quick scientific paper finder. Basically have a folder with, probably thousands by now, papers (each file's name contains paper title, authors, year, journal) and by typing a couple words can fuzzy search for stuff by whatever fields. It also works incredibly nicely with vim as a fuzzy search for either files or phrases within files.


A nice, I do the same but I convert all books, papers and powerpoints to pdf files with a rondom name or i use a hash of the content as name. Then in use ripgrepall with fzf to search for the information i'm looking for.


I haven't had the chance to test this, but this add-on promises to be able to pipe _any_ tab-completion suggestions from your shell into fzf, which to me sounds like the pinnacle of fzf awesomeness.

https://github.com/lincheney/fzf-tab-completion


FZF is the one tool I evangelize to all new hires. Just that with infinite history saves hours of development time per year.


Personally, I'm a fan of using fzf with tmux 3.2+ so I get popup windows instead. They're great.


Can you elaborate on that? I use fzf with tmux as well, but I'm not sure what you mean by popup windows. Similar to vim splits?



fzy[1] is a less bloated alternative, written in C. fzf is neat, but it does too much.

[1]: https://github.com/jhawthorn/fzy


There's also skim[1], which would be a Rust fzy alternative.

But neither fzy nor skim quite do what fzf does, which is offer an simple feature-filled experience out of the box. The big draw is fzf Just Works™. I don't mind that it feels bloated and slow sometimes, because I don't want to spend a week figuring out how to make the other two do what fzf does without configuration or drama, and all the speed improvements in the world doesn't really matter when the bottleneck is the meatball behind the keyboard.

[1]https://github.com/lotabout/skim


I really wish skim ran on Windows :(


There's always WSL ¯\_(ツ)_/¯


But does it really? Can one not simply not use the features one doesn't need?

Also, I fully appreciate not rewriting things that are C and already working just because -- but surely if something is already written in a safer language then C isn't really a step forward either.


fzf never struck me as the slightest bit slow. What am I doing wrong? You can configure it with an external previewer that can of cause be arbitrarily slow or bloated but you can hardly fault fzf for that.


In my experience fzf actually feels faster simply because it’s able to begin populating the output list before it finishes reading the input list. This means you get selection options immediately, whereas with fzy there can be a delay. This is particularly noticeable when working with large inputs (e.g. anything in the Linux kernel)


The real advantage of fzy over fzf is that fzy is actually better at guessing what you want (the documentation claims it's also faster but I never noticed a difference).

That fzy also forces you to think about good input providers (like fd instead of find) is just following the Unix philosophy of one tool doing what it's best at.


Yeah, well, that's just, like, your opinion...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: