Initial commit: loc_az_hci (smom-dbis-138 excluded via .gitignore)
Some checks failed
Test / test (push) Has been cancelled
Some checks failed
Test / test (push) Has been cancelled
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
28
scripts/utils/auto-prep-new-scripts.sh
Executable file
28
scripts/utils/auto-prep-new-scripts.sh
Executable file
@@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
source ~/.bashrc
|
||||
# Automatically add 'source ~/.bashrc' after shebang to all .sh scripts in subdirs
|
||||
# Usage: ./auto-prep-new-scripts.sh [--watch]
|
||||
|
||||
SCRIPTS_ROOT="/home/intlc/projects/loc_az_hci/scripts"
|
||||
|
||||
add_bashrc_source() {
|
||||
local file="$1"
|
||||
# Only add if not already present and if it's a bash script
|
||||
if grep -q "^#!/bin/bash" "$file" && ! grep -q "^source ~/.bashrc" "$file"; then
|
||||
awk 'NR==1{print; print "source ~/.bashrc"; next}1' "$file" > "$file.tmp" && mv "$file.tmp" "$file"
|
||||
echo "Patched: $file"
|
||||
fi
|
||||
}
|
||||
|
||||
find "$SCRIPTS_ROOT" -type f -name '*.sh' | while read -r script; do
|
||||
add_bashrc_source "$script"
|
||||
done
|
||||
|
||||
if [[ "$1" == "--watch" ]]; then
|
||||
echo "Watching for changes to .sh scripts..."
|
||||
while inotifywait -e create -e modify -e move --format '%w%f' -r "$SCRIPTS_ROOT" | grep -E '\.sh$'; do
|
||||
find "$SCRIPTS_ROOT" -type f -name '*.sh' | while read -r script; do
|
||||
add_bashrc_source "$script"
|
||||
done
|
||||
done
|
||||
fi
|
||||
Reference in New Issue
Block a user