Fzf – the basics part 1 – layout
qmacro.org
qmacro.org
# 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 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. 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] 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). 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.
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.
# 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,.]* *//')"
}Thanks, I was using https://github.com/badmotorfinger/z for powershell before. I will check it out.
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.
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.
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.