From 66d08907fbf64654cbb9ced80f0257acb8df2663 Mon Sep 17 00:00:00 2001 From: Guennadi Maximov C Date: Thu, 6 Jun 2024 19:08:57 -0600 Subject: [PATCH] feat(scripts): Added simple script for replacing. --- scripts/global_replace.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 scripts/global_replace.sh diff --git a/scripts/global_replace.sh b/scripts/global_replace.sh new file mode 100755 index 00000000..29741f1c --- /dev/null +++ b/scripts/global_replace.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +[[ $# -eq 0 ]] && exit 1 + +IFS=$'\n' FILES=($(find . -type f -regex '.*\.lua$' | cut -d '/' -f2-)) + +while [[ $# -gt 0 ]]; do + if ! [[ "$1" =~ ^s/.+/.*/g$ ]] ; then + shift + continue + fi + + REGEX="$1" + + for F in "${FILES[@]}"; do + sed -i "${REGEX}" "$F" || break + done + + shift +done + +exit 0