2024-06-05 20:04:49 +02:00
|
|
|
#!/bin/bash
|
2024-05-06 22:55:03 +02:00
|
|
|
function rgf {
|
|
|
|
if [[ "$1" == "--help" ]]; then
|
2024-06-05 20:04:49 +02:00
|
|
|
# shellcheck disable=SC2140
|
2024-05-06 22:55:03 +02:00
|
|
|
echo "Finde alle Dateien die "\$1" im Namen haben."
|
|
|
|
echo ""
|
|
|
|
echo " Usage: rgf <string>"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
echo "[ERROR] Suchbegriff fehlt..."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
if command -v rg >/dev/null ; then
|
2024-06-05 20:04:49 +02:00
|
|
|
rg --ignore-case --files --hidden --glob=!.git/ --*"$1"*
|
2024-05-06 22:55:03 +02:00
|
|
|
else
|
|
|
|
echo "[INFO] ripgrep ist nicht installiert... suche mit 'find'"
|
2024-06-05 20:04:49 +02:00
|
|
|
find . -type f -not -path '*/\.git/*' -name -- *"$1"*
|
2024-05-06 22:55:03 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
function rgi {
|
|
|
|
if [[ "$1" == "--help" ]]; then
|
2024-06-05 20:04:49 +02:00
|
|
|
# shellcheck disable=SC2140
|
2024-05-06 22:55:03 +02:00
|
|
|
echo "Finde alle Dateien die "\$1" im Inhalt haben."
|
|
|
|
echo ""
|
|
|
|
echo " Usage: rgi <string>"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
echo "[ERROR] Suchbegriff fehlt..."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
if command -v rg >/dev/null ; then
|
|
|
|
rg --ignore-case --hidden --glob=!.git/ "$1"
|
|
|
|
else
|
|
|
|
echo "[INFO] ripgrep ist nicht installiert... suche mit 'grep'"
|
|
|
|
grep --recursive --line-number --ignore-case --exclude-dir=".git" "$1" .
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
function ssh {
|
|
|
|
# benennt das aktuelle tmux-windows nach dem ssh-ziel
|
|
|
|
# baut ssh-verbindung auf
|
|
|
|
if [ -n "${TMUX}" ]; then
|
|
|
|
tmux rename-window "${@: -1}"
|
|
|
|
fi
|
|
|
|
command ssh "$@"
|
|
|
|
if [ -n "${TMUX}" ]; then
|
|
|
|
tmux rename-window "$(hostname -f)"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
function gcm {
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
echo "Commit-Message fehlt, setze Default-Message..."
|
|
|
|
git commit -s -m "changed Files: $(git diff --name-only --staged)"
|
|
|
|
else
|
|
|
|
# übergibt alle argumente an git commit -m als commit nachricht
|
|
|
|
git commit -s -m "$*"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
function gc {
|
|
|
|
case "$1" in
|
|
|
|
--help | -h)
|
|
|
|
cat <<EOF
|
|
|
|
|
|
|
|
Description:
|
|
|
|
"git checkout" on steroids
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
gc [--help|--new-branch] [branch]
|
|
|
|
|
|
|
|
Options:
|
|
|
|
-h, --help Print this help.
|
|
|
|
-b, --new-branch Create a new Branch instead changing to an existing branch.
|
|
|
|
|
|
|
|
Author:
|
|
|
|
michael.grote@posteo.de - git.mgrote.net
|
|
|
|
EOF
|
|
|
|
;;
|
|
|
|
--new-branch | -b)
|
2024-05-28 20:21:00 +02:00
|
|
|
(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... ')
|
2024-05-06 22:55:03 +02:00
|
|
|
;;
|
|
|
|
*)
|
2024-06-05 20:04:49 +02:00
|
|
|
if [ -n "$1" ] ; then
|
2024-05-28 20:21:00 +02:00
|
|
|
(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!")
|
2024-05-06 22:55:03 +02:00
|
|
|
else
|
2024-05-28 20:21:00 +02:00
|
|
|
(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')
|
2024-05-06 22:55:03 +02:00
|
|
|
fi
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
function glogs {
|
|
|
|
# https://git-scm.com/docs/pretty-formats
|
|
|
|
# https://stackoverflow.com/questions/3631005/git-log-tabular-formatting
|
|
|
|
# https://stackoverflow.com/questions/7736781/how-to-make-git-log-not-prompt-to-continue
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
ncommits=30;
|
|
|
|
else
|
|
|
|
ncommits="$1";
|
|
|
|
fi;
|
2024-06-05 20:04:49 +02:00
|
|
|
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"
|
2024-05-06 22:55:03 +02:00
|
|
|
}
|
|
|
|
function gp {
|
|
|
|
git pull "$@"
|
|
|
|
}
|
|
|
|
function mdtoc {
|
|
|
|
grep --recursive --include="*.md" ^# | sort --version-sort --field-separator=":" | awk 'BEGIN {FS=":"}{print $2 "&&" $1}' | column --table --separator "&&" --table-truncate 1,2
|
|
|
|
}
|