Compare commits
11 commits
c3c3969603
...
a5717bfdfc
Author | SHA1 | Date | |
---|---|---|---|
|
a5717bfdfc | ||
33d9422a59 | |||
dcdfcd7cb4 | |||
873764d369 | |||
cad2c5337f | |||
fb1e4f6ccd | |||
79bea1364a | |||
78bda4fdb2 | |||
2989151380 | |||
5f217de747 | |||
4578a05a00 |
14 changed files with 191 additions and 215 deletions
136
.bash_functions
136
.bash_functions
|
@ -1,42 +1,4 @@
|
|||
#!/bin/bash
|
||||
function rgf {
|
||||
if [[ "$1" == "--help" ]]; then
|
||||
# shellcheck disable=SC2140
|
||||
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
|
||||
rg --ignore-case --files --hidden --glob=!.git/ --*"$1"*
|
||||
else
|
||||
echo "[INFO] ripgrep ist nicht installiert... suche mit 'find'"
|
||||
find . -type f -not -path '*/\.git/*' -name -- *"$1"*
|
||||
fi
|
||||
}
|
||||
function rgi {
|
||||
if [[ "$1" == "--help" ]]; then
|
||||
# shellcheck disable=SC2140
|
||||
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
|
||||
|
@ -48,105 +10,7 @@ function ssh {
|
|||
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)
|
||||
(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 [ -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!")
|
||||
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')
|
||||
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;
|
||||
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 {
|
||||
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
|
||||
}
|
||||
# "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
|
||||
}
|
||||
|
|
1
scripts/gc
Symbolic link
1
scripts/gc
Symbolic link
|
@ -0,0 +1 @@
|
|||
git_checkout
|
1
scripts/gcm
Symbolic link
1
scripts/gcm
Symbolic link
|
@ -0,0 +1 @@
|
|||
git_commit
|
1
scripts/ghist
Symbolic link
1
scripts/ghist
Symbolic link
|
@ -0,0 +1 @@
|
|||
git_history
|
28
scripts/git_checkout
Executable file
28
scripts/git_checkout
Executable file
|
@ -0,0 +1,28 @@
|
|||
#!/bin/bash
|
||||
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)
|
||||
(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 [ -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! ")
|
||||
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')
|
||||
fi
|
||||
esac
|
8
scripts/git_commit
Executable file
8
scripts/git_commit
Executable file
|
@ -0,0 +1,8 @@
|
|||
#!/bin/bash
|
||||
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
|
42
scripts/git_history
Executable file
42
scripts/git_history
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
|
10
scripts/git_logs
Executable file
10
scripts/git_logs
Executable file
|
@ -0,0 +1,10 @@
|
|||
#!/bin/bash
|
||||
# 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;
|
||||
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"
|
1
scripts/glogs
Symbolic link
1
scripts/glogs
Symbolic link
|
@ -0,0 +1 @@
|
|||
git_logs
|
1
scripts/rgi
Symbolic link
1
scripts/rgi
Symbolic link
|
@ -0,0 +1 @@
|
|||
ripgrep_inline
|
18
scripts/ripgrep_inline
Executable file
18
scripts/ripgrep_inline
Executable file
|
@ -0,0 +1,18 @@
|
|||
#!/bin/bash
|
||||
if [[ "$1" == "--help" ]]; then
|
||||
# shellcheck disable=SC2140
|
||||
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
|
79
scripts/search_and_replace
Executable file
79
scripts/search_and_replace
Executable file
|
@ -0,0 +1,79 @@
|
|||
#!/bin/bash
|
||||
|
||||
function rename_directories {
|
||||
find . -type d -not -path '*/\.git/*' -execdir rename "$SEARCH" "$REPLACE" {} \; > /dev/null 2>&1
|
||||
}
|
||||
|
||||
function rename_files {
|
||||
find . -name '*' -type f -not -path '*/\.git/*' -exec rename "$SEARCH" "$REPLACE" {} \;
|
||||
}
|
||||
|
||||
function rename_inline {
|
||||
find . -name '*' -type f -not -path '*/\.git/*' -exec sed -i "s/${SEARCH}/${REPLACE}/g" {} \;
|
||||
}
|
||||
|
||||
# das erste Argument der Funktion ist die Anzahl der Argumente des aufrufenden Scripts
|
||||
# das zweite Argument ist die erwünschte Anzahl an Argumenten
|
||||
function check_argument_count {
|
||||
if [ "$1" -lt "$2" ] ; then
|
||||
echo ">>> Not enough arguments..."
|
||||
exit 1
|
||||
elif [ "$1" -gt "$2" ] ; then
|
||||
echo ">>> Too many arguments..."
|
||||
exit 2
|
||||
fi
|
||||
}
|
||||
|
||||
function print_help {
|
||||
cat <<EOF
|
||||
|
||||
Description:
|
||||
Search and replace recursively.
|
||||
|
||||
Usage:
|
||||
sr [-h|-d|-i|-f] <search> <replace>
|
||||
|
||||
Options:
|
||||
-d Rename only directories.
|
||||
-f Rename only files.
|
||||
-i Rename only in files.
|
||||
-h Print this help.
|
||||
|
||||
Author:
|
||||
michael.grote@posteo.de - git.mgrote.net
|
||||
EOF
|
||||
}
|
||||
|
||||
SEARCH="$2"
|
||||
REPLACE="$3"
|
||||
|
||||
case "$1" in
|
||||
-f)
|
||||
check_argument_count "$#" "3"
|
||||
rename_files
|
||||
;;
|
||||
-i)
|
||||
check_argument_count "$#" "3"
|
||||
rename_inline
|
||||
;;
|
||||
-d)
|
||||
check_argument_count "$#" "3"
|
||||
rename_directories > /dev/null 2>&1
|
||||
;;
|
||||
-h)
|
||||
print_help
|
||||
exit 0
|
||||
;;
|
||||
# ohne Parameter wird alles gemacht
|
||||
*)
|
||||
check_argument_count "$#" "2"
|
||||
SEARCH=$1
|
||||
REPLACE=$2
|
||||
echo ">>> Rename files..."
|
||||
rename_files
|
||||
echo ">>> Rename directories..."
|
||||
rename_directories > /dev/null 2>&1
|
||||
echo ">>> Rename inline..."
|
||||
rename_inline
|
||||
;;
|
||||
esac
|
79
scripts/sr
79
scripts/sr
|
@ -1,79 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
function rename_directories {
|
||||
find . -type d -not -path '*/\.git/*' -execdir rename "$SEARCH" "$REPLACE" {} \; > /dev/null 2>&1
|
||||
}
|
||||
|
||||
function rename_files {
|
||||
find . -name '*' -type f -not -path '*/\.git/*' -exec rename "$SEARCH" "$REPLACE" {} \;
|
||||
}
|
||||
|
||||
function rename_inline {
|
||||
find . -name '*' -type f -not -path '*/\.git/*' -exec sed -i "s/${SEARCH}/${REPLACE}/g" {} \;
|
||||
}
|
||||
|
||||
# das erste Argument der Funktion ist die Anzahl der Argumente des aufrufenden Scripts
|
||||
# das zweite Argument ist die erwünschte Anzahl an Argumenten
|
||||
function check_argument_count {
|
||||
if [ "$1" -lt "$2" ] ; then
|
||||
echo ">>> Not enough arguments..."
|
||||
exit 1
|
||||
elif [ "$1" -gt "$2" ] ; then
|
||||
echo ">>> Too many arguments..."
|
||||
exit 2
|
||||
fi
|
||||
}
|
||||
|
||||
function print_help {
|
||||
cat <<EOF
|
||||
|
||||
Description:
|
||||
Search and replace recursively.
|
||||
|
||||
Usage:
|
||||
sr [-h|-d|-i|-f] <search> <replace>
|
||||
|
||||
Options:
|
||||
-d Rename only directories.
|
||||
-f Rename only files.
|
||||
-i Rename only in files.
|
||||
-h Print this help.
|
||||
|
||||
Author:
|
||||
michael.grote@posteo.de - git.mgrote.net
|
||||
EOF
|
||||
}
|
||||
|
||||
SEARCH="$2"
|
||||
REPLACE="$3"
|
||||
|
||||
case "$1" in
|
||||
-f)
|
||||
check_argument_count "$#" "3"
|
||||
rename_files
|
||||
;;
|
||||
-i)
|
||||
check_argument_count "$#" "3"
|
||||
rename_inline
|
||||
;;
|
||||
-d)
|
||||
check_argument_count "$#" "3"
|
||||
rename_directories > /dev/null 2>&1
|
||||
;;
|
||||
-h)
|
||||
print_help
|
||||
exit 0
|
||||
;;
|
||||
# ohne Parameter wird alles gemacht
|
||||
*)
|
||||
check_argument_count "$#" "2"
|
||||
SEARCH=$1
|
||||
REPLACE=$2
|
||||
echo ">>> Rename files..."
|
||||
rename_files
|
||||
echo ">>> Rename directories..."
|
||||
rename_directories > /dev/null 2>&1
|
||||
echo ">>> Rename inline..."
|
||||
rename_inline
|
||||
;;
|
||||
esac
|
1
scripts/sr
Symbolic link
1
scripts/sr
Symbolic link
|
@ -0,0 +1 @@
|
|||
search_and_replace
|
Loading…
Reference in a new issue