Last active
August 26, 2025 08:11
-
-
Save amydevs/0dacedd9eb6a1ea92f016598d3f70450 to your computer and use it in GitHub Desktop.
Script for automatically setting up a DSA/Adv Algorithms Project with Bazel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
URL="https://github.com/amydevs/dsa-aa-template.git" | |
cd $1 | |
git remote set-url template $URL 2>/dev/null || git remote add template $URL | |
git fetch template | |
git merge template/master --allow-unrelated-histories --no-edit 1>/dev/null | |
FILELIST="" | |
while read -d '' -r file; do | |
if | |
[[ $file == *.cpp ]] || \ | |
[[ $file == *.hpp ]] || \ | |
[[ $file == *.c ]] || \ | |
[[ $file == *.h ]] | |
then | |
FILELIST="$FILELIST\n$file" | |
fi | |
done < <(git ls-files -z) | |
TEMPFILE=$(mktemp) | |
awk -v new_content=$FILELIST ' | |
/srcs *= *\[/ { | |
print " srcs = [" | |
split(new_content, lines, "\n") | |
for (i in lines) { | |
if (length(lines[i]) != 0) { | |
print " \"" lines[i] "\"," | |
} | |
} | |
print " ]," | |
# Skip the original content until we find the closing bracket | |
while (getline > 0 && !/\]/) {} | |
next | |
} | |
{ print } | |
' ./BUILD > $TEMPFILE | |
cp $TEMPFILE ./BUILD | |
cd - 1>/dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment