Skip to content

Instantly share code, notes, and snippets.

@cschindlbeck
Last active July 5, 2024 08:28
Show Gist options
  • Save cschindlbeck/db0ac894a46aac42861e96437d8ed763 to your computer and use it in GitHub Desktop.
Save cschindlbeck/db0ac894a46aac42861e96437d8ed763 to your computer and use it in GitHub Desktop.
#####################################
# Useful commands that leverage fzf #
#####################################
# Fuzzy file open: Type ff and find file via fzf and open in nvim
ff() { nvim "$(find . -type f | fzf)"; }
# Fuzzy cd: Type fcd and select folder via fzf
fcd() { cd "$(find . -type d | fzf)"; }
# Fuzzy git branch checkout: Type fgc and select branch via fzf
fgc() { git switch "$(git branch -v | fzf | awk '{print $1}')"; }
# Fuzzy git add: Type fga and select file via fzf
fga() { git add "$(git status --porcelain | fzf | awk '{print $2}')"; }
# Fuzzy process killer
fpkill() {
local selection
selection=$(ps -e -o pid,comm | fzf)
local pid=$(echo "$selection" | awk '{print $1}')
local pname=$(echo "$selection" | awk '{print $2}')
if [ "$pid" != "" ]; then
kill -9 "$pid" > /dev/null 2>&1 && echo "Process $pname (PID $pid) has been successfully killed."
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment