fish: Add functions for git operations using fzf

This commit is contained in:
Sanchayan Maity 2021-01-28 12:10:02 +05:30
parent 8f8cf8c71d
commit b6279fe0cc

View file

@ -241,11 +241,11 @@ alias vdua="git add (git diff --name-only --diff-filter=U)"
# Git fzf helper functions
# https://github.com/junegunn/fzf/wiki/Examples-(fish)
function fco -d "Fuzzy-find and checkout a branch"
function fco -d "Checkout a branch using fzf"
git branch --all | grep -v HEAD | string trim | fzf | read -l result; and git checkout "$result"
end
function fcoc -d "Fuzzy-find and checkout a commit"
function fcoc -d "Checkout a commit using fzf"
git log --pretty=oneline --abbrev-commit --reverse | fzf --tac +s -e | awk '{print $1;}' | read -l result; and git checkout "$result"
end
@ -274,4 +274,36 @@ function fbr --description "Git browse commits"
--bind "ctrl-o:execute:$github_open"
end
function fcf --description "Git commit fixup using fzf"
git commit --fixup (git log --pretty=oneline --abbrev-commit --color=always | fzf --ansi | cut -d ' ' -f1)
end
function fcr --description "Git reset to a selected commit using fzf"
git reset $argv (git log --pretty=oneline --abbrev-commit --color=always | fzf --ansi +s | awk '{print $1}')
end
function fcR --description "Git revert a selected commit using fzf"
git revert (git log --pretty=oneline --abbrev-commit --color=always | fzf --ansi +s | awk '{print $1}')
end
function frbi --description "Git interactive rebase using fzf"
git rebase -i (git log --pretty=oneline --abbrev-commit --color=always | fzf --ansi | cut -d ' ' -f1)
end
function ffa --description "Git add files using fzf"
git add -- (git ls-files --modified --others --exclude-standard | fzf -m --preview 'bat --color=always {}')
end
function ffco --description "Git checkout a file using fzf"
git checkout $argv -- (git ls-files --modified --exclude-standard | fzf -m)
end
function ffrs --description "Git restore a staged file using fzf"
git restore --staged $argv -- (git diff --name-only --staged | fzf -m)
end
function ffr --description "Git restore a file using fzf"
git restore $argv -- (git ls-files --modified --exclude-standard | fzf -m)
end
fzf_key_bindings