Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

quitting git log from a bash script

i'm trying to write a 'live git log' bash script. here's the code so far:

#!/bin/sh
while true;
do
    clear
    git log --graph -10 --all --color --date=short --pretty=format:"%Cred%x09%h %Creset%ad%Cblue%d %Creset %s %C(bold)(%an)%Creset"
    sleep 3
done

my problem is that git log uses a pager and you have to press q to quit or it will just sit there forever. is there a way to code the quit command in bash? i tried echoing q, with no luck. (i saw another post here that suggested echo "q" > /dev/console -- but there is no dev console in my environment)

system: win7 box - emulating bash with mingw (1.7.6.msysget.0)

UPDATE

here's the finished script

#!/bin/sh
while true;
do
    clear
    git log \
    --graph \
    --all \
    --color \
    --date=short \
    -40 \
    --pretty=format:"%C(yellow)%h%x20%C(white)%cd%C(green)%d%C(reset)%x20%s%x20%C(bold)(%an)%Creset" |
    cat -
    sleep 15
done

the -40 is a personal taste. change it to whatever number suits you and your terminal screen size.

like image 719
xero Avatar asked Oct 01 '12 16:10

xero


2 Answers

Adding --no-pager is the way to go.:

git --no-pager log

So the full command would be

git --no-pager log --graph -10 --all --color --date=short --pretty=format:"%Cred%x09%h %Creset%ad%Cblue%d %Creset %s %C(bold)(%an)%Creset"
like image 147
eis Avatar answered Oct 10 '22 17:10

eis


Try the following code :

git log \
    --graph -10 \
    --all \
    --color \
    --date=short \
    --pretty=format:"%Cred%x09%h %Creset%ad%Cblue%d %Creset %s %C(bold)(%an)%Creset" |
    cat -

edit

| cat - is not specific to git, that works in each use cases when you have a pager and you'd want to print to STDOUT

like image 38
Gilles Quenot Avatar answered Oct 10 '22 18:10

Gilles Quenot