Skip to content

Instantly share code, notes, and snippets.

@adefirmanf
Last active April 5, 2019 18:16
Show Gist options
  • Save adefirmanf/1e4f234b0a9b0046276b210196a6fb09 to your computer and use it in GitHub Desktop.
Save adefirmanf/1e4f234b0a9b0046276b210196a6fb09 to your computer and use it in GitHub Desktop.
Fish for managing git
function gitpc
set -lx current_branch (git branch | grep \* | cut -d ' ' -f2)
set -lx total_commit (git cherry -v origin/$current_branch | grep -c +)
set -lx need_stashed (git status | grep -c -E "modified|new|deleted")
set -lx file_changed (git status -s | grep -c M | cut -d ' ' -f2)
set -lx deleted_file (git status -s | grep -c D | cut -d ' ' -f2)
set -lx untracked_file (git status -s | grep -c U | cut -d ' ' -f2)
if test $need_stashed -ne 0 -o $total_commit -ne 0
set_color 198CFF
echo "Stash..."
git stash
set_color blue
echo "Pull..."
git pull --rebase origin $current_branch
set_color yellow
git stash apply
else
echo "Pull..."
git pull --rebase origin $current_branch
end
set_color 84DE02
echo "✔ Done"\n
set_color normal
if test $total_commit -ne 0
set_color blue
echo "$total_commit commit need pushed to remote"
set_color 198CFF
git cherry -v origin/$current_branch
set_color yellow
read -l -s -P "Do you want push $total_commit commit to remote branch ($current_branch) [y/N] > " opt
switch $opt
case Y y
echo "Push..."
git push origin $current_branch
set_color 84DE02
echo "✔ Done"
return 1
case '*'
echo "✔ Done"
return 1
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment