dotfiles/scripts/git_history

43 lines
1.1 KiB
Text
Raw Normal View History

#!/bin/bash
total_commits=$(git rev-list HEAD --count)
current_commit=$total_commits
show_commit_diff() {
if [ "$current_commit" -le "$total_commits" ] && [ "$current_commit" -ge 1 ]; then
commit_hash=$(git rev-list --reverse HEAD | sed -n "${current_commit}p")
git --no-pager show "$commit_hash"
fi
}
while true; do
clear # Clear the terminal
show_commit_diff
# Display navigation options
echo "-----------------------------------------------------------"
echo "Navigation: N - Next Commit, P - Previous Commit, Q - Quit"
echo "-----------------------------------------------------------"
read -r -n1 -s option
case $option in
p|P)
# shellcheck disable=2086
if [ $current_commit -gt 1 ]; then
((current_commit--))
fi
;;
n|N)
# shellcheck disable=2086
if [ $current_commit -lt $total_commits ]; then
((current_commit++))
fi
;;
q|Q)
break
;;
*)
echo "Invalid option"
;;
esac
done