bash: fix shellcheck errors in .bash_functions
All checks were successful
ci/woodpecker/push/lint Pipeline was successful

Signed-off-by: Michael Grote <michael.grote@posteo.de>
This commit is contained in:
Michael Grote 2024-06-05 20:04:49 +02:00
parent 5e88bf3f74
commit ef9e2a036f
2 changed files with 16 additions and 12 deletions

View file

@ -1,6 +1,7 @@
### Funktionen #!/bin/bash
function rgf { function rgf {
if [[ "$1" == "--help" ]]; then if [[ "$1" == "--help" ]]; then
# shellcheck disable=SC2140
echo "Finde alle Dateien die "\$1" im Namen haben." echo "Finde alle Dateien die "\$1" im Namen haben."
echo "" echo ""
echo " Usage: rgf <string>" echo " Usage: rgf <string>"
@ -11,14 +12,15 @@ function rgf {
return 1 return 1
fi fi
if command -v rg >/dev/null ; then if command -v rg >/dev/null ; then
rg --ignore-case --files --hidden --glob=!.git/ *"$1"* rg --ignore-case --files --hidden --glob=!.git/ --*"$1"*
else else
echo "[INFO] ripgrep ist nicht installiert... suche mit 'find'" echo "[INFO] ripgrep ist nicht installiert... suche mit 'find'"
find . -type f -not -path '*/\.git/*' -name *"$1"* find . -type f -not -path '*/\.git/*' -name -- *"$1"*
fi fi
} }
function rgi { function rgi {
if [[ "$1" == "--help" ]]; then if [[ "$1" == "--help" ]]; then
# shellcheck disable=SC2140
echo "Finde alle Dateien die "\$1" im Inhalt haben." echo "Finde alle Dateien die "\$1" im Inhalt haben."
echo "" echo ""
echo " Usage: rgi <string>" echo " Usage: rgi <string>"
@ -78,7 +80,7 @@ EOF
(git checkout --quiet -b "$2" && git push --set-upstream "$(git remote | head -n 1)" "$2" && echo '>>> Create new branch "'"$2"'"') || (git checkout --quiet "$2" > /dev/null 2>&1 && echo '>>> Branch already exists, checking out... ') (git checkout --quiet -b "$2" && git push --set-upstream "$(git remote | head -n 1)" "$2" && echo '>>> Create new branch "'"$2"'"') || (git checkout --quiet "$2" > /dev/null 2>&1 && echo '>>> Branch already exists, checking out... ')
;; ;;
*) *)
if [ ! -z $1 ] ; then if [ -n "$1" ] ; then
(echo ">>> Try local checkout" && git checkout --quiet "$1" > /dev/null 2>&1) || (echo ">>> Try remote checkout" && git checkout --quiet -b "$1" origin/"$1" > /dev/null 2>&1 || echo ">>> Unkown branch!") (echo ">>> Try local checkout" && git checkout --quiet "$1" > /dev/null 2>&1) || (echo ">>> Try remote checkout" && git checkout --quiet -b "$1" origin/"$1" > /dev/null 2>&1 || echo ">>> Unkown branch!")
else else
(git checkout --quiet master > /dev/null 2>&1 && echo '>>> Try checking out master') || (git checkout --quiet main > /dev/null 2>&1 && echo '>>> Try checking out main') || (git checkout --quiet release > /dev/null 2>&1 && echo '>>> Try checking out release') (git checkout --quiet master > /dev/null 2>&1 && echo '>>> Try checking out master') || (git checkout --quiet main > /dev/null 2>&1 && echo '>>> Try checking out main') || (git checkout --quiet release > /dev/null 2>&1 && echo '>>> Try checking out release')
@ -94,7 +96,7 @@ function glogs {
else else
ncommits="$1"; ncommits="$1";
fi; fi;
git log --pretty=format:'%C(auto) %<|(16,trunc)%h %Cred %G?%Creset %<|(60,trunc)%s %<(20,trunc)%Cgreen%cr%Creset %<(15,trunc)%Cblue%an%Creset %Cred%D' --graph --all -$ncommits git log --pretty=format:'%C(auto) %<|(16,trunc)%h %Cred %G?%Creset %<|(60,trunc)%s %<(20,trunc)%Cgreen%cr%Creset %<(15,trunc)%Cblue%an%Creset %Cred%D' --graph --all -"$ncommits"
} }
function gp { function gp {
git pull "$@" git pull "$@"
@ -104,13 +106,15 @@ function mdtoc {
} }
# "scrolle" durch die commit-history # "scrolle" durch die commit-history
ghist() { ghist() {
# shellcheck disable=2155
local total_commits=$(git rev-list HEAD --count) local total_commits=$(git rev-list HEAD --count)
local current_commit=$total_commits local current_commit=$total_commits
show_commit_diff() { show_commit_diff() {
if [ $current_commit -le $total_commits ] && [ $current_commit -ge 1 ]; then 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") local commit_hash=$(git rev-list --reverse HEAD | sed -n "${current_commit}p")
git --no-pager show $commit_hash git --no-pager show "$commit_hash"
fi fi
} }
@ -122,15 +126,17 @@ ghist() {
echo "-----------------------------------------------------------" echo "-----------------------------------------------------------"
echo "Navigation: N - Next Commit, P - Previous Commit, Q - Quit" echo "Navigation: N - Next Commit, P - Previous Commit, Q - Quit"
echo "-----------------------------------------------------------" echo "-----------------------------------------------------------"
read -n1 -s option read -r -n1 -s option
case $option in case $option in
p|P) p|P)
# shellcheck disable=2086
if [ $current_commit -gt 1 ]; then if [ $current_commit -gt 1 ]; then
((current_commit--)) ((current_commit--))
fi fi
;; ;;
n|N) n|N)
# shellcheck disable=2086
if [ $current_commit -lt $total_commits ]; then if [ $current_commit -lt $total_commits ]; then
((current_commit++)) ((current_commit++))
fi fi

View file

@ -20,8 +20,7 @@ function update {
git stash git stash
git pull git pull
else else
# shellcheck disable=SC2035 scan -- *
scan *
fi fi
cd .. > /dev/null cd .. > /dev/null
fi fi
@ -39,5 +38,4 @@ function scan {
if [ "$1" != "" ]; then cd "$1" || exit > /dev/null; fi if [ "$1" != "" ]; then cd "$1" || exit > /dev/null; fi
echo -e "${HIGHLIGHT}Scanning ${PWD}${NORMAL}" echo -e "${HIGHLIGHT}Scanning ${PWD}${NORMAL}"
# shellcheck disable=SC2035 scan -- *
scan *