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.
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"
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With