Vim universe: fzf – command line fuzzy finder (2019) [video]
youtube.com
youtube.com
flog () {
branch="$(
git branch --sort=-committerdate --format="%(committerdate:relative)%09%(refname:short)%09%(subject)" \
| column -ts $'\t' \
| fzf \
| sed 's/.*ago \+\([^ ]*\) .*/\1/'
)"
git co $branch || (
echo -n "git co $branch" | pbcopy
)
}
I have a much longer one for switching between PRs requesting my review and previewing them while I do it.edit: funny story, I went to add 4 spaces to the start of each line and it turns out I did the same thing last time and my autocomplete got it for me which flog | sed 's/^/ /' | pbcopy
gbb() {
eval $(echo git checkout "$(git branch --all \
| fzf --height 10 \
| tr -d '[:space:]' \
| tr -d '*' \
| sed 's/remotes\//\-\-track /g')")
}I use FZF for my command line history search and save 10000 lines of shell history, and now I can find every weird jq, kubectl, awk, etc. command I've ever ran to get me going on some of the syntax quickly.
fuzzy search is the best UI for navigating lists ever
Because it's also a tool that you can pipe an array of things into, select an element from it, and run a command on that element.
Just the other day I needed to scour the git history of a huge project, so I wrote a function that first selects a file by running fzf, and then lets me see the git history of any single line of that file by running fzf again.
gblame2 () {
local file=$(fzf)
cat "$file" | awk '{printf("%5d %s\n", NR, $0)}' | fzf --layout reverse --preview-window up --preview "echo {} | awk '{print \$1}' | xargs -I _ sh -c \"git log --color -L_,'+1:${file}'\""
}chatgpt cooked that up for me in 5 minutes, saved me many many hours.
Better use some long rare string as place holder for xargs
gblame2 () {
local file=$(fzf)
cat "$file" | awk '{printf("%5d %s\n", NR, $0)}' | fzf --layout reverse --preview-window up --preview "echo {} | awk '{print \$1}' | xargs -I __XZY__ sh -c \"git log --color -L__XZY__,'+1:${file}'\""
}310 lines long
Sure go ahead execute this thing and cross your fingers..
I use powerline-shell and git auto completion for branches and such and I was sweating this thing was going to shoot me.
They added a Docker file for the scared cats like me so I can see it in action without messing my environment. I verified that it left my .bashrc alone and does not encroached <so far> with tmux and bash key bindings. So I installed and I can tell it projects my brain birds-eye view into the screen. The *<TAB> keybinding is the best.
Great find.
Thanks!