Last active
May 20, 2021 23:12
-
-
Save paulresdat/72b506c981c215e9baac694907772650 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
## README | |
# This is the only file needed if you are working off of zsh | |
# and have Oh-my-zsh installed. | |
git-diff() { | |
correct=$(git diff 2>&1) | |
if [[ $correct = *"Not a git repository"* ]]; then | |
echo $correct | |
return | |
fi | |
if [ $# -eq 0 ]; then | |
read loginput < <(git log) | |
echo "$loginput" | |
IFS=' ' read -r -a array <<< "$loginput" | |
git diff "${array[1]}" | |
else | |
fileName=$1 | |
shift; | |
find ./ -name "$fileName" -print | while read f; do | |
git diff "$@" $f | |
done | |
fi | |
} | |
git-blame() { | |
# this finds my file in my working directory and git blames it for me WITHOUT | |
# having to get the full directory path! | |
find ./ -name "$1" -print | while read f; do | |
echo "" | |
echo "=====BLAMING $f" | |
if [ $# -eq 2 ]; then | |
git blame "$f" $2 | |
elif [ $# -eq 3 ]; then | |
git blame "$f" -L"$2",+"$3" | |
else | |
shift; | |
git blame "$f" "$@" | |
fi | |
done | |
} | |
git-blamer() { | |
# same git blame except you pass in a regular expression | |
find ./ -regextype posix-extended -regex "$1" -print | while read f; do | |
echo "" | |
echo "=====BLAMING $f" | |
if [ $# -eq 2 ]; then | |
git blame "$f" $2 | |
elif [ $# -eq 3 ]; then | |
git blame "$f" -L"$2",+"$3" | |
else | |
shift; | |
git blame "$f" "$@" | |
fi | |
done | |
} | |
git-tree() { | |
if [ $# -ne 0 ]; then | |
git diff-tree --no-commit-id --name-only -r "$@" | |
else | |
# first check in valid git directory | |
correct=$(git diff 2>&1) | |
if [[ $correct = *"Not a git repository"* ]]; then | |
echo $correct | |
return | |
fi | |
read loginput < <(git log) | |
echo "$loginput" | |
IFS=' ' read -r -a array <<< "$loginput" | |
if [ $# -eq 0 ]; then | |
git diff-tree --no-commit-id --name-only -r "${array[1]}" | |
else | |
if [ $1 -eq "-c" ]; then | |
shift | |
git diff-tree --no-commit-id --name-only -r "$@" | |
else | |
git diff-tree "$@" "${array[1]}" | |
fi | |
fi | |
fi | |
} | |
git-shorthands() { | |
# shorthands so handy that I want to keep them | |
alias gpf='git push --force-with-lease' | |
alias gs='git status' | |
alias gb='git branch' | |
alias g='git' | |
alias printmerge='echo $(git-test-branch)' | |
alias merge-into-test='git-intranet-merge-test-branch' | |
alias gdiverge='git rev-list origin..HEAD' | |
} | |
git-aliases() { | |
type git > /dev/null 2>&1 | |
if [ $? -eq 0 ] | |
then | |
declare -A git_confs | |
git_confs=( | |
rebase.autosquash true | |
color.status always | |
rerere.enabled true | |
alias.coo '!f() { | |
echo $(git branch -l | grep -i $1 | wc -l) branches found; | |
git checkout $(git branch -l --sort=-committerdate | grep $1 | head -1 | sed "s|^\\*||"); | |
}; f' | |
alias.gp "grep --break --heading" | |
alias.co checkout | |
alias.cr "checkout --" | |
alias.newbranch "checkout -b" | |
alias.newb "checkout -b" | |
alias.l "log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold red)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%an - %s%C(reset)%C(bold yellow)%d%C(reset)'" | |
alias.ll "log --stat" | |
alias.m "merge" | |
alias.b "branch" | |
alias.mb '!git branch --merged | egrep -v "(^\*|master|release|test.*)"' | |
alias.mbd '!git branch --merged | egrep -v "(^\*|master|release|test.*)" | xargs git branch -d' | |
alias.checkoutpull '!gop() { | |
git coo "$@" | |
git pull -p | |
}; gop' | |
alias.r "reset" | |
alias.rb "rebase -i" | |
alias.cp "checkoutpull" | |
alias.pl '!gpl() { | |
if [ $# -eq 0 ]; then | |
git pull -p | |
else | |
git pull "$@" | |
fi | |
}; gpl' | |
alias.f "fetch -p" | |
alias.p "push" | |
alias.pf "push --force-with-lease" | |
alias.c "commit" | |
alias.cm "commit -m" | |
alias.ca "commit --amend" | |
alias.filereset '!greset() { | |
if [ $# -ne 0 ]; then | |
for var in "$@" | |
do | |
git checkout -- "$var" | |
done | |
fi | |
}; greset' | |
alias.fr "filereset" | |
alias.a '!ga() { | |
if [ $# -eq 0 ]; then | |
git add . | |
else | |
git add "$@" | |
fi | |
}; ga' | |
alias.d 'diff' | |
alias.pu '!gpu() { | |
currentbranch=$(git rev-parse --abbrev-ref HEAD 2>&1) | |
git push --set-upstream origin "$currentbranch" | |
}; gpu' | |
alias.go '!go() { | |
if [ $# -ne 0 ]; then | |
if [ $1 = "test" ]; then | |
TEST=$(git-test-branch) | |
git checkout "$TEST" | |
else | |
git checkout "$@" | |
fi | |
fi | |
}; go' | |
alias.s "status" | |
alias.ss "stash" | |
alias.sb '!gsb() { | |
git branch | grep -i "$@" | |
}; gsb' | |
alias.wow '!echo " | |
wow | |
such program | |
▄ ▄ many data | |
▌▒█ ▄▀▒▌ | |
▌▒▒█ ▄▀▒▒▒▐ | |
▐▄▀▒▒▀▀▀▀▄▄▄▀▒▒▒▒▒▐ very much like linux | |
▄▄▀▒░▒▒▒▒▒▒▒▒▒█▒▒▄█▒▐ so program | |
▄▀▒▒▒░░░▒▒▒░░░▒▒▒▀██▀▒▌ | |
▐▒▒▒▄▄▒▒▒▒░░░▒▒▒▒▒▒▒▀▄▒▒▌ | |
▌░░▌█▀▒▒▒▒▒▄▀█▄▒▒▒▒▒▒▒█▒▐ | |
▐░░░▒▒▒▒▒▒▒▒▌██▀▒▒░░░▒▒▒▀▄▌ Wow so git | |
▌░▒▄██▄▒▒▒▒▒▒▒▒▒░░░░░░▒▒▒▒▌ | |
▌▒▀▐▄█▄█▌▄░▀▒▒░░░░░░░░░░▒▒▒▐ | |
▐▒▒▐▀▐▀▒░▄▄▒▄▒▒▒▒▒▒░▒░▒░▒▒▒▒▌ | |
▐▒▒▒▀▀▄▄▒▒▒▄▒▒▒▒▒▒▒▒░▒░▒░▒▒▐ so much lockd | |
▌▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒░▒░▒░▒░▒▒▒▌ | |
▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▒░▒░▒▒▄▒▒▐ | |
▀▄▒▒▒▒▒▒▒▒▒▒▒░▒░▒░▒▄▒▒▒▒▌ all the KLOC | |
▀▄▒▒▒▒▒▒▒▒▒▒▄▄▄▀▒▒▒▒▄▀ wow | |
▀▄▄▄▄▄▄▀▀▀▒▒▒▒▒▄▄▀ | |
▒▒▒▒▒▒▒▒▒▒▀▀"' | |
) | |
for key value in ${(kv)git_confs}; do | |
git_config ${key} ${value} | |
done | |
fi | |
} | |
git_config() { | |
git config --global "$@" | |
} | |
git-aliases | |
git-shorthands |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment