From 4578a05a00cd62586af298718a69ccba2e6c9f71 Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Wed, 5 Jun 2024 20:07:18 +0200 Subject: [PATCH 01/10] ci: remove ci Signed-off-by: Michael Grote --- .woodpecker/lint.yml | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 .woodpecker/lint.yml diff --git a/.woodpecker/lint.yml b/.woodpecker/lint.yml deleted file mode 100644 index f8a46cc..0000000 --- a/.woodpecker/lint.yml +++ /dev/null @@ -1,24 +0,0 @@ ---- -steps: - gitleaks: - image: zricethezav/gitleaks:v8.18.2 - commands: - - gitleaks detect --no-git --verbose --source $CI_WORKSPACE - when: - - event: [push, pull_request] - evaluate: 'CI_COMMIT_AUTHOR_EMAIL != "renovate@mgrote.net"' - - shellcheck: - image: "koalaman/shellcheck-alpine:v0.10.0" - commands: - - | - find . -type f -not -path './.git/*' -exec file {} \; | while IFS= read -r line; do - if echo "$line" | grep -q "shell script"; then - file_path=$(echo "$line" | awk -F':' '{print $1}') - shellcheck "$file_path" - fi - done - when: - - event: [push, pull_request] - evaluate: 'CI_COMMIT_AUTHOR_EMAIL != "renovate@mgrote.net"' -... From 5f217de747fab247e9a7531ee2ca4b6fdbb5e7c4 Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Wed, 5 Jun 2024 20:11:16 +0200 Subject: [PATCH 02/10] 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 From 2989151380879860b1727e152735fbc08793d007 Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Wed, 5 Jun 2024 20:14:04 +0200 Subject: [PATCH 03/10] bash: move glogs to scripts Signed-off-by: Michael Grote --- .bash_functions | 14 -------------- scripts/git_logs | 1 + scripts/glogs | 10 ++++++++++ 3 files changed, 11 insertions(+), 14 deletions(-) create mode 120000 scripts/git_logs create mode 100755 scripts/glogs diff --git a/.bash_functions b/.bash_functions index 211a70c..bcf660d 100644 --- a/.bash_functions +++ b/.bash_functions @@ -87,20 +87,6 @@ EOF 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 -} diff --git a/scripts/git_logs b/scripts/git_logs new file mode 120000 index 0000000..0290127 --- /dev/null +++ b/scripts/git_logs @@ -0,0 +1 @@ +glogs \ No newline at end of file diff --git a/scripts/glogs b/scripts/glogs new file mode 100755 index 0000000..8fd3817 --- /dev/null +++ b/scripts/glogs @@ -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" From 78bda4fdb25b016e1fbbd4c775a9ed2dbd03cc8f Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Wed, 5 Jun 2024 20:15:24 +0200 Subject: [PATCH 04/10] bash: git* change symlink direction Signed-off-by: Michael Grote --- scripts/ghist | 43 +------------------------------------------ scripts/git_history | 43 ++++++++++++++++++++++++++++++++++++++++++- scripts/git_logs | 11 ++++++++++- scripts/glogs | 11 +---------- 4 files changed, 54 insertions(+), 54 deletions(-) mode change 100755 => 120000 scripts/ghist mode change 120000 => 100755 scripts/git_history mode change 120000 => 100755 scripts/git_logs mode change 100755 => 120000 scripts/glogs diff --git a/scripts/ghist b/scripts/ghist deleted file mode 100755 index bf88f54..0000000 --- a/scripts/ghist +++ /dev/null @@ -1,42 +0,0 @@ -#!/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/ghist b/scripts/ghist new file mode 120000 index 0000000..c10c826 --- /dev/null +++ b/scripts/ghist @@ -0,0 +1 @@ +git_history \ No newline at end of file diff --git a/scripts/git_history b/scripts/git_history deleted file mode 120000 index 4182fc7..0000000 --- a/scripts/git_history +++ /dev/null @@ -1 +0,0 @@ -ghist \ No newline at end of file diff --git a/scripts/git_history b/scripts/git_history new file mode 100755 index 0000000..bf88f54 --- /dev/null +++ b/scripts/git_history @@ -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_logs b/scripts/git_logs deleted file mode 120000 index 0290127..0000000 --- a/scripts/git_logs +++ /dev/null @@ -1 +0,0 @@ -glogs \ No newline at end of file diff --git a/scripts/git_logs b/scripts/git_logs new file mode 100755 index 0000000..8fd3817 --- /dev/null +++ b/scripts/git_logs @@ -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" diff --git a/scripts/glogs b/scripts/glogs deleted file mode 100755 index 8fd3817..0000000 --- a/scripts/glogs +++ /dev/null @@ -1,10 +0,0 @@ -#!/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" diff --git a/scripts/glogs b/scripts/glogs new file mode 120000 index 0000000..c90c48d --- /dev/null +++ b/scripts/glogs @@ -0,0 +1 @@ +git_logs \ No newline at end of file From 79bea1364a2a1040ea7127752aef1e16e7009e4e Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Wed, 5 Jun 2024 20:18:01 +0200 Subject: [PATCH 05/10] bash: move gc to scripts Signed-off-by: Michael Grote --- .bash_functions | 30 ------------------------------ scripts/gc | 1 + scripts/git_checkout | 28 ++++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 30 deletions(-) create mode 120000 scripts/gc create mode 100755 scripts/git_checkout diff --git a/.bash_functions b/.bash_functions index bcf660d..8b9dde8 100644 --- a/.bash_functions +++ b/.bash_functions @@ -57,36 +57,6 @@ function gcm { git commit -s -m "$*" fi } -function gc { - case "$1" in - --help | -h) - cat <>> 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 gp { git pull "$@" } diff --git a/scripts/gc b/scripts/gc new file mode 120000 index 0000000..fc8f2aa --- /dev/null +++ b/scripts/gc @@ -0,0 +1 @@ +git_checkout \ No newline at end of file diff --git a/scripts/git_checkout b/scripts/git_checkout new file mode 100755 index 0000000..cd854be --- /dev/null +++ b/scripts/git_checkout @@ -0,0 +1,28 @@ +#!/bin/bash +case "$1" in +--help | -h) + cat <>> 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 From fb1e4f6ccdac16c1b968e661d861c45ccc7228d8 Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Wed, 5 Jun 2024 20:21:04 +0200 Subject: [PATCH 06/10] bash: move gcm to scripts Signed-off-by: Michael Grote --- .bash_functions | 9 --------- scripts/gcm | 1 + scripts/git_commit | 8 ++++++++ 3 files changed, 9 insertions(+), 9 deletions(-) create mode 120000 scripts/gcm create mode 100755 scripts/git_commit diff --git a/.bash_functions b/.bash_functions index 8b9dde8..5311cec 100644 --- a/.bash_functions +++ b/.bash_functions @@ -48,15 +48,6 @@ 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 gp { git pull "$@" } diff --git a/scripts/gcm b/scripts/gcm new file mode 120000 index 0000000..57bf3e6 --- /dev/null +++ b/scripts/gcm @@ -0,0 +1 @@ +git_commit \ No newline at end of file diff --git a/scripts/git_commit b/scripts/git_commit new file mode 100755 index 0000000..762a20a --- /dev/null +++ b/scripts/git_commit @@ -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 From cad2c5337f0dd71c1074b6ed4a43c56e988a4d19 Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Wed, 5 Jun 2024 20:25:54 +0200 Subject: [PATCH 07/10] bash: move rg* to scripts Signed-off-by: Michael Grote --- .bash_functions | 39 +-------------------------------------- scripts/rgf | 1 + scripts/rgi | 1 + scripts/ripgrep_filenames | 18 ++++++++++++++++++ scripts/ripgrep_inline | 18 ++++++++++++++++++ 5 files changed, 39 insertions(+), 38 deletions(-) create mode 120000 scripts/rgf create mode 120000 scripts/rgi create mode 100755 scripts/ripgrep_filenames create mode 100755 scripts/ripgrep_inline diff --git a/.bash_functions b/.bash_functions index 5311cec..3b04b61 100644 --- a/.bash_functions +++ b/.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 " - 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 " - 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,6 +10,7 @@ function ssh { tmux rename-window "$(hostname -f)" fi } + function gp { git pull "$@" } diff --git a/scripts/rgf b/scripts/rgf new file mode 120000 index 0000000..c0db12f --- /dev/null +++ b/scripts/rgf @@ -0,0 +1 @@ +ripgrep_filenames \ No newline at end of file diff --git a/scripts/rgi b/scripts/rgi new file mode 120000 index 0000000..ac91c52 --- /dev/null +++ b/scripts/rgi @@ -0,0 +1 @@ +ripgrep_inline \ No newline at end of file diff --git a/scripts/ripgrep_filenames b/scripts/ripgrep_filenames new file mode 100755 index 0000000..d0e65de --- /dev/null +++ b/scripts/ripgrep_filenames @@ -0,0 +1,18 @@ +#!/bin/bash +if [[ "$1" == "--help" ]]; then + # shellcheck disable=SC2140 + echo "Finde alle Dateien die "\$1" im Namen haben." + echo "" + echo " Usage: rgf " + 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 diff --git a/scripts/ripgrep_inline b/scripts/ripgrep_inline new file mode 100755 index 0000000..d04dddd --- /dev/null +++ b/scripts/ripgrep_inline @@ -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 " + 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 From 873764d369f3a8e77d6ca4259b5b55ae7b698da0 Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Wed, 5 Jun 2024 20:31:34 +0200 Subject: [PATCH 08/10] bash: remove rgf Signed-off-by: Michael Grote --- scripts/rgf | 1 - scripts/ripgrep_filenames | 18 ------------------ 2 files changed, 19 deletions(-) delete mode 120000 scripts/rgf delete mode 100755 scripts/ripgrep_filenames diff --git a/scripts/rgf b/scripts/rgf deleted file mode 120000 index c0db12f..0000000 --- a/scripts/rgf +++ /dev/null @@ -1 +0,0 @@ -ripgrep_filenames \ No newline at end of file diff --git a/scripts/ripgrep_filenames b/scripts/ripgrep_filenames deleted file mode 100755 index d0e65de..0000000 --- a/scripts/ripgrep_filenames +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -if [[ "$1" == "--help" ]]; then - # shellcheck disable=SC2140 - echo "Finde alle Dateien die "\$1" im Namen haben." - echo "" - echo " Usage: rgf " - 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 From dcdfcd7cb40c7b075a699b7ffbb87bad16102353 Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Wed, 5 Jun 2024 20:33:18 +0200 Subject: [PATCH 09/10] bash: sr, create symlink Signed-off-by: Michael Grote --- scripts/search_and_replace | 79 +++++++++++++++++++++++++++++++++++++ scripts/sr | 80 +------------------------------------- 2 files changed, 80 insertions(+), 79 deletions(-) create mode 100755 scripts/search_and_replace mode change 100755 => 120000 scripts/sr diff --git a/scripts/search_and_replace b/scripts/search_and_replace new file mode 100755 index 0000000..eceb29e --- /dev/null +++ b/scripts/search_and_replace @@ -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 < + +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 diff --git a/scripts/sr b/scripts/sr deleted file mode 100755 index eceb29e..0000000 --- a/scripts/sr +++ /dev/null @@ -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 < - -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 diff --git a/scripts/sr b/scripts/sr new file mode 120000 index 0000000..083bd5b --- /dev/null +++ b/scripts/sr @@ -0,0 +1 @@ +search_and_replace \ No newline at end of file From 33d9422a597e3052de38fb2bfcbb670fa4443870 Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Wed, 5 Jun 2024 20:34:37 +0200 Subject: [PATCH 10/10] bash: remove suffix from show_color_script Signed-off-by: Michael Grote --- scripts/{show_color_palette.sh => show_color_palette} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename scripts/{show_color_palette.sh => show_color_palette} (100%) diff --git a/scripts/show_color_palette.sh b/scripts/show_color_palette similarity index 100% rename from scripts/show_color_palette.sh rename to scripts/show_color_palette