Last active
August 16, 2023 10:57
-
-
Save cartok/8e967a18e5912c1a1676760a905ce078 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# !/usr/bin/env/zsh | |
# (outdated) | |
# Packages: | |
# - wl-clipboard | |
# - fzf | |
# - fd | |
# - ripgrep | |
# | |
# Plugins: | |
# - mollifier/cd-gitroot | |
# | |
git-local-branch-names() { | |
git branch | rg "$1" | sed -re 's/\*? *(.+)/\1/' | xargs -I {} echo "{}" | |
} | |
git-remote-branch-names() { | |
git remote update origin --prune &> /dev/null | |
git branch --remote | rg "$1" | sed -re 's/ *\w+\/(.+)/\1/' | xargs -I {} echo "{}" | |
} | |
git-remote-head-branch() { | |
git remote update origin --prune &> /dev/null | |
git branch --remote --list | rg "HEAD" | sed -re 's/.* -> .*\/(.*)/\1/' | |
} | |
alias glog='git log --format="%Cred%h%Creset - %as (%ar) %Cblue%aN: %Cgreen%s"' | |
alias gl='git log --format="%Cred%h%Creset - %as (%ar) %Cblue%aN: %Cgreen%s" \ | |
| fzf \ | |
| sd "(\w+) .*" "\$1" \ | |
| xargs -I {} zsh -c "wl-copy {} && echo Copied {} to the clipboard" \ | |
' | |
alias gbm='git branch -m' | |
alias gbn='git branch --show-current' | |
alias gm='git merge' | |
gb() { | |
local BRANCH_NAME=$(git-local-branch-names $@ | fzf) | |
echo $BRANCH_NAME | wl-copy | |
echo "Copied \"$BRANCH_NAME\" to clipboard" | |
} | |
gbd() { | |
local BRANCH_NAME=$(git-local-branch-names $@ | fzf) | |
git checkout $(git-remote-head-branch) | |
git branch -D $BRANCH_NAME | |
echo $BRANCH_NAME | wl-copy | |
echo "Copied \"$BRANCH_NAME\" to clipboard" | |
} | |
gbc() { | |
git branch --show-current | |
} | |
gc() { | |
local BRANCH_NAME=$(git-local-branch-names $@ | fzf) | |
git checkout $BRANCH_NAME | |
} | |
gf() { | |
local BRANCH_NAME=$(git-remote-branch-names $@ | fzf) | |
git fetch origin $BRANCH_NAME | |
} | |
gcr() { | |
local BRANCH_NAME=$(git-remote-branch-names $@ | fzf) | |
git checkout $(git-remote-head-branch) | |
git branch -D $BRANCH_NAME | |
git fetch origin $BRANCH_NAME | |
git checkout $BRANCH_NAME | |
} | |
alias gcb='git checkout -b' | |
gcleanb() { | |
local BRANCH_NAME=$(git branch --show-current) | |
git reset --hard HEAD && git clean -fd | |
git checkout $(git-remote-head-branch) | |
git branch -D $BRANCH_NAME | |
git fetch origin $BRANCH_NAME | |
git checkout $BRANCH_NAME | |
} | |
alias gcom='git commit -m' | |
alias gcoma='git commit --amend' | |
alias gcomam='git commit --amend -m' | |
alias gamen='git commit --amend -C HEAD -n' | |
alias amen='git add . && git commit --amend -C HEAD' | |
alias gcomaa='git shortlog --summary --numbered --email --all --no-merges \ | |
| fzf \ | |
| sd "^[^A-Za-z]+" "" \ | |
| xargs -I {} git commit --amend -C HEAD -n --author {} \ | |
' | |
alias gchp='git cherry-pick' | |
alias gchc='git cherry-pick --continue' | |
alias gcha='git cherry-pick --abort' | |
alias ga='git add .' | |
alias gs='git status' | |
alias gpus='git push origin HEAD' | |
alias gpush='git push origin HEAD' | |
alias gpusf='git push origin HEAD -f' | |
alias gpushf='git push origin HEAD -f' | |
alias groot='cd-gitroot' | |
alias gpul='git pull' | |
alias gpull='git pull' | |
alias gpulr='git pull --rebase origin' | |
alias gpullr='git pull --rebase origin' | |
alias grebc='git rebase --continue' | |
alias greba='git rebase --abort' | |
alias greb='git rebase' | |
grebi() { | |
local COMMIT=$(git log --decorate=no --pretty=oneline --abbrev-commit | fzf | sd "(\w+) .*" "\$1") | |
git rebase -i $COMMIT~ | |
} | |
alias grb='grebi' | |
alias gres='git reset HEAD' | |
alias gres1='git reset HEAD~' | |
alias gresh='git reset --hard HEAD' | |
alias gresh1='git reset --hard HEAD~' | |
alias gclean='git reset --hard HEAD && git clean -fd' | |
alias gss='git stash save -u' | |
alias gsl='git stash list' | |
alias gsp='git stash pop' | |
gsd() { | |
local index=${1:-0} | |
git stash drop stash@{$index} | |
echo "\n" | |
git stash list | head -n 5 | |
} | |
gsa() { | |
local stash=$(git stash list | fzf | cut -d ':' -f 1) | |
git stash apply $stash | |
} | |
alias gd='git diff' | |
alias gdo='git diff origin' | |
alias gdh='git diff origin HEAD~' | |
gmergeof () { | |
git log $1..$(git-remote-head-branch) --ancestry-path --merges --reverse | |
} | |
gfiles() { | |
local HEAD_BRANCH=$(git-remote-head-branch) | |
local LATEST_COMMIT_ID=$(git cherry -v ${1:-"$HEAD_BRANCH"} HEAD | head -n 1 | awk '{ print $2 }') | |
local FIRST_COMMIT_ID=$(git cherry -v ${1:-"$HEAD_BRANCH"} HEAD | tail -n 1 | awk '{ print $2 }') | |
git diff ${LATEST_COMMIT_ID} ${FIRST_COMMIT_ID}~1 --name-only | cat | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment