Skip to content

Instantly share code, notes, and snippets.

@ngzax
Created March 27, 2026 13:57
Show Gist options
  • Select an option

  • Save ngzax/f00a32ae0f1c3523532fcd0d67ed7085 to your computer and use it in GitHub Desktop.

Select an option

Save ngzax/f00a32ae0f1c3523532fcd0d67ed7085 to your computer and use it in GitHub Desktop.
A simple TUI for viewing your decorated git log
#!/usr/bin/env bash
last_hash=""
while true; do
clear
if [[ -n "$TMUX" ]]; then
cols=$(tmux display-message -p '#{pane_width}')
lines=$(( $(tmux display-message -p '#{pane_height}') - 2 ))
else
lines=$(( $(tput lines) - 2 ))
cols=$(tput cols)
fi
git --no-pager log --graph --oneline --all --decorate --date-order --color=always \
| perl -pe 'BEGIN{$c='"$cols"'} my $v=0; s/(\x1b\[[0-9;]*[mK])|(.)/defined $2 ? ($v++ < $c ? $2 : "") : $1/ge; s/$/\x1b[0m/' \
| head -n "$lines"
echo ""
printf "[r]efresh [q]uit (auto-refreshes)"
last_hash=$(git rev-parse HEAD 2>/dev/null)
while true; do
key=""
if read -rsn1 -t 1 key; then
# Key was pressed
case "$key" in
q|Q) exit 0 ;;
*) break ;;
esac
else
# Timeout - check for new commits
current_hash=$(git rev-parse HEAD 2>/dev/null)
if [[ "$current_hash" != "$last_hash" ]]; then
break
fi
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment