bash: add ghist

This commit is contained in:
Michael Grote 2023-09-21 11:17:32 +02:00
parent 2ad3619bdb
commit 5bc3af7aad

View file

@ -174,6 +174,49 @@ function gp {
function mdtoc {
grep --recursive --include="*.md" ^# | sort --version-sort --field-separator=":" | awk 'BEGIN {FS=":"}{print $2 "&&" $1}' | column --table --separator "&&" --table-truncate 1,2
}
# "scrolle" durch die commit-history
ghist() {
local total_commits=$(git rev-list HEAD --count)
local current_commit=$total_commits
show_commit_diff() {
if [ $current_commit -le $total_commits ] && [ $current_commit -ge 1 ]; then
local 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 -n1 -s option
case $option in
p|P)
if [ $current_commit -gt 1 ]; then
((current_commit--))
fi
;;
n|N)
if [ $current_commit -lt $total_commits ]; then
((current_commit++))
fi
;;
q|Q)
break
;;
*)
echo "Invalid option"
;;
esac
done
}
### Aliase
# tmux
alias tmuxa="tmux a -t "