I have been trying to create an automatically updating git log --graph --no-pager. I made some strides using fswatch but I ran into the issue of my git history being actually bigger than my screen can display. I tried adding | head -n $((`tput lines` - 1)) but the output is still overflowing because of line wrapping. I then tried using tput rmam in order to disable wrapping, but now I can't usually see where HEAD points to.
Anyone could help me? Ideally, I'd like to remove --no-pager, but I don't know how to make that work with fswatch. Here is what I have so far:
function gwatch() {
tput rmam
location=$(git rev-parse --show-toplevel)
clear;
git --no-pager graph --color | head -n $((`tput lines` - 1));
tput smam
fswatch -or $location/.git | while read MODFILE
do
tput rmam
clear;
git --no-pager graph --color | head -n $((`tput lines` - 1));
tput smam
done
}
I have a less elegant solution than yours but simple: using watch.
watch will do the paging for you but you won't be able to browse the log.
But if you want that, you can use the following code:
I put a sleep because we have multiple creations of files in one modification in git. This code needs a better solution to catch a modification in git than watching all git objects!
Instead of
-xand thengrepwith Created, you can use-o --event=Created. However, this approach is less responsive and seems not to work all the time.