From fc13da5260dd16b62ab7a54119fe226845ac52d1 Mon Sep 17 00:00:00 2001 From: cscherr Date: Mon, 11 Aug 2025 16:36:08 +0200 Subject: [PATCH] recursive edit --- .zshrc | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/.zshrc b/.zshrc index 6615b35..ba9e46a 100644 --- a/.zshrc +++ b/.zshrc @@ -133,9 +133,7 @@ else fi return $ret } -function confirm() { - CMD=$@ - echo "Execute: '$CMD' ?"; +function confirm_inner() { echo -n "[Y/n]: " # a weid difference between zsh and bash if [[ "$SHELL" =~ (.*zsh) ]]; then @@ -144,11 +142,17 @@ function confirm() { read -s -n1; fi case "${REPLY}" in - y|Y|$'\n'|" "|"A"|"" ) echo yes;eval $CMD;; + y|Y|$'\n'|" "|"A"|"" ) echo yes; eval $@;; n|N ) echo no;echo 'Aborted.' ; return 1;; * ) echo -e 'Invalid choice, aborted.'; return 2;; esac; } + +function confirm() { + CMD=$@ + echo "Execute: '$CMD' ?"; + confirm_inner $CMD +} function confirm-important() { echo "Write 'yes do as i say' to confirm that you REALLY want to do this: $@" read @@ -168,7 +172,23 @@ function writepatch() { nvim b/$fname diff -Naru --color='auto' a/$fname b/$fname } - +function recursive_file_sed () +{ + USAGE="USAGE: $0 FILE_ENDING REGEX" + ENDING=$1 + REGEX=$2 + if [[ -z $ENDING ]]; then + echo $USAGE + return 1 + fi + if [[ -z $REGEX ]]; then + echo $USAGE + return 1 + fi + echo "Are you SURE you want to recursively change all files with the ending '$ENDING' in $PWD with this regex: $REGEX ?" + confirm_inner + find $PWD -type f -name "*.$ENDING" | xargs sed -i "$REGEX" +} ### ---- zsh options ------------------------------------- setopt autocd