fzf (Fuzzy Finder)

back

custom functions

fzf is a powerful fuzzy finder that can significantly enhance your command-line workflow. Here are three custom functions that leverage fzf to streamline common tasks. 1

# interactive process killing
function pkill() {
  ps aux | fzf --height 40% --layout=reverse --prompt="Select process to kill: " | awk '{print $2}' | xargs -r sudo kill
}
# git log navigation and browsing
function logg() {
  git lg | fzf --ansi --no-sort \
    --preview 'echo {} | grep -o "[a-f0-9]\{7\}" | head -1 | xargs -I % git show % --color=always' \
    --preview-window=right:50%:wrap --height 100% \
    --bind 'enter:execute(echo {} | grep -o "[a-f0-9]\{7\}" | head -1 | xargs -I % sh -c "git show % | nim -c \"setlocal buftype=nofile bufhidden=wipe noswapfile nowrap\" -c \"nnoremap <buffer> q :q!<CR>\" -")' \
    --bind 'ctrl-e:execute(echo {} | grep -o "[a-f0-9]\{7\}" | head -1 | xargs -I % sh -c "gh browse %")'
}