First version of the script.
This commit is contained in:
commit
18dac8819e
77
git-hist.sh
Executable file
77
git-hist.sh
Executable file
|
@ -0,0 +1,77 @@
|
|||
#!/bin/bash
|
||||
|
||||
# TODO :
|
||||
# * use cursor keys
|
||||
# * show also current (uncommited) version
|
||||
# * syntax highlighting
|
||||
# * process through nano (problem : nano's output is limited to one single screen, and puts some termcaps at the begining and end of output.)
|
||||
# * use vim : http://machine-cycle.blogspot.com/2007/10/syntax-highlighting-pager.html
|
||||
# * use highlight --ansi --force, or pygmentize -g : http://machine-cycle.blogspot.com/2008/02/syntax-highlighting-pager-reloaded.html
|
||||
# * use emacs
|
||||
# * choose from one of the above by guessing from $EDITOR and what's installed on the system.
|
||||
# * doesn't seem to include pre-rename versions of a file that was renamed.
|
||||
# * git log --follow --name-only --oneline galerie-index.php
|
||||
# * git whatchanged --follow galerie-index.php | grep '^\(:\|commit \)'
|
||||
|
||||
file="$1"
|
||||
if [ -z $file ]; then
|
||||
echo "Usage : $0 filename"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
statusbar() {
|
||||
echo -e "\e[47m\e[K[$i / $max] : ${rev[i]}\e[1000G\e[46D\e[1mh\e[47m : help \e[1mp\e[47m,\e[1m-\e[47m : previous \e[1mn\e[47m,\e[1m+\e[47m : next \e[1mq\e[47m : quit \e[m"
|
||||
}
|
||||
|
||||
page=0
|
||||
pager() {
|
||||
termlines="$(tput lines)"
|
||||
tail -n +$(($termlines*$page/2)) | head -n $(($termlines-2))
|
||||
}
|
||||
|
||||
show() {
|
||||
clear
|
||||
statusbar
|
||||
git show "${rev[i]}:$fullpath" | nl | pager
|
||||
}
|
||||
|
||||
help() {
|
||||
clear
|
||||
statusbar
|
||||
echo -e "status line : [version i / of total] : sha1"
|
||||
echo -e "\e[1mh\e[m : help"
|
||||
echo -e "\e[1mp\e[m,\e[1m-\e[m : previous version"
|
||||
echo -e "\e[1mn\e[m,\e[1m+\e[m : next version"
|
||||
echo -e "\e[1mf\e[m : first version"
|
||||
echo -e "\e[1ml\e[m : last version"
|
||||
echo -e "\e[1md\e[m : scroll down"
|
||||
echo -e "\e[1mu\e[m : scroll up"
|
||||
echo -e "\e[1mt\e[m : scroll to top"
|
||||
echo -e "\e[1mq\e[m : quit"
|
||||
}
|
||||
|
||||
fullpath="$(git ls-files --full-name "$file")"
|
||||
i=0
|
||||
for ab in $(git log --oneline "$file" | cut -d ' ' -f 1 | tac); do
|
||||
rev[i]="$ab"
|
||||
i=$((i+1))
|
||||
done
|
||||
max="$((i-1))"
|
||||
|
||||
i="$max"
|
||||
show
|
||||
while read -n 1 ab; do
|
||||
case "$ab" in
|
||||
"") continue ;;
|
||||
"p"|"+") i=$((i-1)); [ "$i" -lt 0 ] && i=0 ;;
|
||||
"n"|"-") i=$((i+1)); [ "$i" -gt "$max" ] && i="$max" ;;
|
||||
"f") i=0 ;;
|
||||
"l") i="$max" ;;
|
||||
"d") page=$((page+1)) ;;
|
||||
"u") page=$((page-1)); [ "$i" -lt 0 ] && i=0 ;;
|
||||
"t") page=0 ;;
|
||||
"h") help; continue ;;
|
||||
"q") break ;;
|
||||
esac
|
||||
show
|
||||
done
|
Loading…
Reference in New Issue
Block a user