Created
June 8, 2015 10:34
-
-
Save JoseAlban/a941b5d207a92c2d2f11 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
alias gdiff='git diff -C -l10 --src-prefix="[pre-change] " --dst-prefix="[pos-change] "' | |
alias ggdiff='git difftool --dir-diff' | |
# .gitconfig: | |
# lgs =!git --no-pager log --left-right --graph --abbrev-commit --date=relative -n 20 --pretty='%C(green)%-h%Creset %C(cyan)%><(30,trunc)%an%Creset %C(green)%><(18,trunc)%cd%Creset %C(white)%s%Creset' | |
function glg { | |
fillheight=$(echo $(trows) - 2 |bc) | |
fillwidth=$(echo $(tcolumns) - 36 |bc) | |
if [[ $1 =~ ^[0-9]+$ ]] | |
then | |
typeset lines=$1 | |
shift | |
else | |
typeset lines=$fillheight | |
fi | |
hashes="%C(yellow)%d%Creset %C(green)%-h%Creset" | |
msg="%C(white)%<|($fillwidth,trunc)%s%Creset" | |
date="%C(green)%><(18,trunc)%cd%Creset" | |
author="%C(cyan)%<(14,trunc)%an%Creset" | |
git --no-pager \ | |
log --left-right --graph --abbrev-commit --date=relative -n $lines \ | |
--pretty="$hashes $msg $date $author" "$@" | |
} | |
function gdiffgeneric { | |
typeset specific_log=$1; shift | |
typeset lines=$(echo -e "$gitlog" | wc -l | tr -d ' ') | |
if [ "$lines" -gt 0 ] ;then | |
typeset begin_hash=$(echo -e "$gitlog" | head -n$first_pointer | tail -n1) | |
typeset end_hash=$begin_hash~ | |
# first commit | |
git show $end_hash &>/dev/null | |
if [ $? -eq 128 ] # error finding hash | |
then | |
echo "Initial commit found" | |
typeset initial_commit=true | |
fi | |
# [ "$lines" == 1 ] || typeset end_hash=$(echo -e "$gitlog" | head -n$last_pointer | tail -n1) | |
# eval "$specific_log" ; echo # err. | |
eval "git lgs -n1 -C -l10 --summary --stat $begin_hash $path" | |
# [[ $initial_commit == true ]] || git diff --stat $end_hash $begin_hash | |
read -n 1 -p "[d=CLI diff] ; [enter=GUI diff] ; [any other char=skip] ; [ctrl+c=finish]..." readchar | |
else | |
echo "No commits found" | |
return 1 | |
fi | |
if [[ $readchar == 'd' ]]; then | |
echo -e "\n<<<>>>" | |
if [[ $initial_commit == true ]]; then | |
git show --oneline $begin_hash | |
return 1 | |
fi | |
gdiff --ignore-all-space $end_hash $begin_hash $path | |
elif ! [[ $readchar == '' ]] ; then | |
echo -e "\nSkipped." | |
else | |
if [[ $initial_commit == true ]]; then | |
git show --oneline $begin_hash | |
return 1 | |
fi | |
# ggdiff -y $end_hash $begin_hash $path | |
ggdiff -y $end_hash $begin_hash $path | |
fi | |
} | |
function gdiffprev { | |
typeset first_pointer=$1; shift | |
typeset last_pointer=$(($first_pointer + 1)) | |
typeset path="$@" | |
typeset gitlog=$(git log --pretty=%h $path) | |
gdiffgeneric "glg 20 $path" | |
} | |
function reviewprev { | |
# reviewprev 5 | |
typeset number="$1" | |
[ -z $number ] && number=1 | |
glg "$number" | |
for i in $(seq $number 1); do | |
hr && echo -e "Previous n.$i:" | |
gdiffprev "$i" | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment