Skip to content

Instantly share code, notes, and snippets.

@igemnace
Last active April 11, 2023 23:29
Show Gist options
  • Save igemnace/9b6fb8c2885c3e35299b3a122e1009e5 to your computer and use it in GitHub Desktop.
Save igemnace/9b6fb8c2885c3e35299b3a122e1009e5 to your computer and use it in GitHub Desktop.
Some fzf snippets
fzf_argfiles() {
fzf --multi | tr '\n' ' '
}
# for unstaged changes and untracked files
fzf_dirty_files() {
git status --porcelain | cut -c 1,2,3 --complement | fzf --multi --preview-window=up:50% --preview='git diff --color=always {}'
}
fzf_modified_files() {
git status --porcelain --untracked-files=no | cut -c 1,2,3 --complement | fzf --multi --preview-window=up:50% --preview='git diff --color=always {}'
}
# for commits
fzf_commits() {
git log --pretty=oneline --abbrev-commit | fzf --preview-window=up:50% --preview 'echo {} | cut -f 1 -d " " | xargs git show --color=always' | cut -f 1 -d " "
}
# for music files in ~/Music
fzf_music() {
rg --files $HOME/Music | fzf
}
# for existing man pages
fzf_apropos() {
apropos '' | fzf --preview-window=up:50% --preview 'echo {} | cut -f 1 -d " " | xargs man' | cut -f 1 -d " "
}
# for existing aliases
fzf_alias() {
alias | tr = "\t" | fzf | cut -f 1
}
# for lines in all files in this directory, recursively
fzf_grep() {
# I use ripgrep here for speed
# but the same thing can be done by grep -R .
rg -n '' | sed -e 's/:/+/' -e 's/:/\t/' -e 's/+/:/' | fzf | cut -f 1
}
alias gaz='git add $(fzf_dirty_files)'
alias gpz='git add --patch $(fzf_dirty_files)'
alias gdz='git diff $(fzf_modified_files)'
alias gcz='git show $(fzf_commits)'
alias vz='vim $(fzf_argfiles)'
alias vgz='vim $(fzf_grep | sed -e "s/:/ +/")'
alias ez='emacs -nw "$(fzf --multi)"'
alias cpz='cmus-remote -p $(fzf_music)'
alias manz='man $(fzf_apropos)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment