xero
xero

Reputation: 4319

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.

Upvotes: 7

Views: 4281

Answers (3)

Gilles Quénot
Gilles Quénot

Reputation: 185530

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

Upvotes: 5

Diego Torres Milano
Diego Torres Milano

Reputation: 69318

setting, in your script:

export PAGER=

would do the trick

Upvotes: 2

eis
eis

Reputation: 53502

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"

Upvotes: 23

Related Questions