In this question I am exploring how to go about monitoring my project directory for changes so that I can keep a terminal that shows an always up-to-date git diff so that I can skip typing git diff
over and over into the shell and further streamline my workflow.
Supposing that I have a sufficiently intelligent tool that knows exactly when the filesystem has changed, how can I go about disrupting the display of git diff? The ultimate solution would be able to figure out where the current display is scrolled to, and re-scroll to the same position (where reasonable, as everything could potentially have been changed, of course). I'm sure there's a way to find out how far down in the buffer you are with less
and then pass that along with the new instance of it.
But the question here is how do I programmatically control an interface that is also interactive? Is this something that is possible to do? Could I make use of certain heavy-duty tools like tmux, to send input into the program? In my experience of customizing tmux to do many things it does have the ability to receive commands from the shell and also to execute shell commands, and it does have a command which sends keys.
What's this? a close vote? Maybe somebody thought this couldn't be done. ;)
I present to you the full solution (you can find the most up to date versions on github):
~/util/git-diff-puppet:
~/util/git-diff-puppet-onchange:
It is glorious. Instantaneous update thanks to the super fast
fswatch
program.What is also nice, is that I account for
fswatch
firing spuriously (which it unfortunately does). If mygit diff
is unchanged, no re-running via tmux is done, so the scroll offset is preserved.