2020-11-24 03:34:14 +00:00
|
|
|
#!/usr/local/bin/fish
|
|
|
|
|
|
|
|
function gittools
|
|
|
|
|
|
|
|
function git-fuzzy-branch -a header
|
|
|
|
set -l current (git rev-parse --abbrev-ref HEAD | tr -d '\n')
|
|
|
|
set -l branch (git branch --format "%(refname:short)" | eval "fzf $FZF_DEFAULT_OPTS --header='On $current, $header'")
|
|
|
|
and echo $branch
|
|
|
|
end
|
|
|
|
|
|
|
|
function git-checkout-fuzzy
|
|
|
|
set branch (git-fuzzy-branch "checkout branch...")
|
|
|
|
and git checkout $branch
|
|
|
|
end
|
|
|
|
|
2020-11-25 22:56:17 +00:00
|
|
|
function git-show-fuzzy
|
|
|
|
set commit (git log --pretty=oneline | fzf | cut -d' ' -f1)
|
|
|
|
and git show $commit
|
|
|
|
end
|
|
|
|
|
2020-11-24 03:34:14 +00:00
|
|
|
function git-merge-fuzzy
|
2020-11-25 14:59:43 +00:00
|
|
|
set branch (git-fuzzy-branch "merge from...")
|
2020-11-25 17:14:44 +00:00
|
|
|
and git merge $branch
|
2020-11-24 03:34:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function git-delete-fuzzy
|
2020-11-25 14:59:43 +00:00
|
|
|
set branch (git-fuzzy-branch "delete branch...")
|
2020-11-25 17:14:44 +00:00
|
|
|
and git branch -d $branch
|
2020-11-25 14:59:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function git-force-delete-fuzzy
|
|
|
|
set branch (git-fuzzy-branch "force delete branch...")
|
2020-11-25 17:14:44 +00:00
|
|
|
and git branch -D $branch
|
2020-11-25 14:59:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function git
|
|
|
|
if contains f $argv
|
|
|
|
switch $argv[1]
|
|
|
|
case "checkout"
|
|
|
|
git-checkout-fuzzy
|
2020-11-25 22:56:17 +00:00
|
|
|
case "show"
|
|
|
|
git-show-fuzzy
|
2020-11-25 14:59:43 +00:00
|
|
|
case "merge"
|
|
|
|
git-merge-fuzzy
|
|
|
|
case "branch"
|
|
|
|
if test "$argv[2]" = "-d"
|
|
|
|
git-delete-fuzzy
|
|
|
|
else if test "$argv[2]" = "-D"
|
|
|
|
git-force-delete-fuzzy
|
|
|
|
else
|
|
|
|
echo "Not a fuzzy option."
|
|
|
|
return 1
|
|
|
|
end
|
|
|
|
case "*"
|
|
|
|
echo "No fuzzy option."
|
|
|
|
return 1
|
|
|
|
end
|
|
|
|
else
|
2020-11-25 17:14:44 +00:00
|
|
|
if count $argv > /dev/null
|
|
|
|
command git $argv
|
|
|
|
else
|
|
|
|
command git status -sb
|
|
|
|
end
|
2020-11-25 14:59:43 +00:00
|
|
|
end
|
2020-11-24 03:34:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|