bash: move ghist to scripts
Signed-off-by: Michael Grote <michael.grote@posteo.de>
This commit is contained in:
parent
4578a05a00
commit
5f217de747
3 changed files with 43 additions and 46 deletions
|
@ -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
|
||||
}
|
||||
|
|
42
scripts/ghist
Executable file
42
scripts/ghist
Executable file
|
@ -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
|
1
scripts/git_history
Symbolic link
1
scripts/git_history
Symbolic link
|
@ -0,0 +1 @@
|
|||
ghist
|
Loading…
Reference in a new issue