这是什么?近距离投票?也许有人认为这是不可能的。;)
我向您展示了完整的解决方案(您可以在github上找到最新版本):
~/util/git-diff-puppet:
#!/bin/sh
# This script runs git diff through tmux at the current directory, so that you can
# interactively scroll it. Listens for changes to the filesystem at this directory
# and tmux is used to issue commands to reload the diff.
set -e
[[ -f .tmp_git_diff ]] && echo "found .tmp_git_diff, exiting" && exit -1
# save the current git diff string to use for comparison
git diff > .tmp_git_diff
function cleanup {
kill $FSWATCHPID
rm .tmp_git_diff
tmux kill-session -t git-diff-puppet
}
trap cleanup EXIT
tmux new-session -d -s git-diff-puppet sh
tmux send-keys -t git-diff-puppet "git diff" enter
fswatch . ~/util/git-diff-puppet-onchange &
FSWATCHPID=$!
tmux attach -t git-diff-puppet
echo "tmux finished: puppet script exiting"
~/util/git-diff-puppet-onchange:
#!/bin/sh
# This script is not for invoking directly. It is for use in conjunction (as a "callback") with
# git-diff-puppet: this script will be looking for the .tmp_git_diff file
set -e
[[ ! -f .tmp_git_diff ]] && echo ".tmp_git_diff not found; i was probably invoked in error, aborting" && exit 1
# diffing the current diff with the saved diff to see if we should re-show the git diff in tmux
if ! git diff | diff - .tmp_git_diff > /dev/null; then
tmux send-keys -t git-diff-puppet q "git diff" enter
git diff > .tmp_git_diff
fi
这是光荣的。由于超快的fswatch
程序,即时更新。
还不错的是,我解释了fswatch
虚假射击(不幸的是)。如果 mygit diff
未更改,则不会通过 tmux 重新运行,因此会保留滚动偏移量。