Skip to content

Instantly share code, notes, and snippets.

@amydevs
Last active August 26, 2025 08:11
Show Gist options
  • Save amydevs/0dacedd9eb6a1ea92f016598d3f70450 to your computer and use it in GitHub Desktop.
Save amydevs/0dacedd9eb6a1ea92f016598d3f70450 to your computer and use it in GitHub Desktop.
Script for automatically setting up a DSA/Adv Algorithms Project with Bazel
#!/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