From 5f217de747fab247e9a7531ee2ca4b6fdbb5e7c4 Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Wed, 5 Jun 2024 20:11:16 +0200 Subject: [PATCH] bash: move ghist to scripts Signed-off-by: Michael Grote --- .bash_functions | 46 --------------------------------------------- scripts/ghist | 42 +++++++++++++++++++++++++++++++++++++++++ scripts/git_history | 1 + 3 files changed, 43 insertions(+), 46 deletions(-) create mode 100755 scripts/ghist create mode 120000 scripts/git_history diff --git a/.bash_functions b/.bash_functions index be8f00e..211a70c 100644 --- a/.bash_functions +++ b/.bash_functions @@ -104,49 +104,3 @@ 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() { - # shellcheck disable=2155 - 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 - # shellcheck disable=2155 - 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 -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 -} diff --git a/scripts/ghist b/scripts/ghist new file mode 100755 index 0000000..bf88f54 --- /dev/null +++ b/scripts/ghist @@ -0,0 +1,42 @@ +#!/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 diff --git a/scripts/git_history b/scripts/git_history new file mode 120000 index 0000000..4182fc7 --- /dev/null +++ b/scripts/git_history @@ -0,0 +1 @@ +ghist \ No newline at end of file