Exit git log from bash script

I am trying to write a 'live git log' bash script. here is 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 the git log uses a pager and you have to press q to exit, or it will just sit there forever. is there any way to encode the quit command in bash? I tried echoing q, with no luck. (I saw another entry here suggesting echo "q"> / dev / console, but there is no developer console in my environment)

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

UPDATE

here is 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 

-40 is a personal taste. change it to any number that suits you and the size of your terminal.

+7
source share
3 answers

Try using 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 - 

change

| cat - | cat - does not apply to git, which works in every case when you have a pager and you want to print to STDOUT

+4
source

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

 git --no-pager log 

So the full team will 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" 
+21
source

in script:

 export PAGER= 

will do the trick

+1
source

All Articles