Skip to content

Commit

Permalink
Add update_gitignore.sh helper command
Browse files Browse the repository at this point in the history
  • Loading branch information
nickwilliams-zaxiom committed Sep 28, 2023
1 parent c85e45e commit 7c292a3
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions ACE/bin/update_gitignore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash

cmd="$1"
if [[ "$cmd" == "help" ]] || [[ "$cmd" != "run" && "$cmd" != "dry-run" ]]
then
if [[ "$cmd" != "help" ]]
then
echo "Error: Unrecognized command '$0 $1'"
echo ""
fi

echo "Usage:"
echo " update_gitignore.sh run"
echo " update_gitignore.sh dry-run"
echo ""
echo "This command finds all untracked and un-git-add-ed files in the repository and adds each file name to "
echo "a '.gitignore' file in the same directory. If a '.gitignore' file does not exist, one will be created. "
echo "Otherwise, the existing '.gitignore' file will be appended to. The 'dry-run' command enables you to "
echo "see a list of all detected file names that will be added to '.gitignore' files without making any "
echo "changes."
echo ""
echo "If the 'run' command does its job properly, running 'dry-run' immediately after should display no "
echo "planned actions."

if [[ "$cmd" == "help" ]]
then
exit 0
fi

exit 1
fi

export IFS=$'\n';

for line in $(git status --short --untracked-files)
do
if [[ $line == '??'* ]]
then
file="${line:3}"
d="$(dirname "${file}")"
f="$(basename "${file}")"

if [[ "$cmd" == "run" ]]
then
echo "Ignoring ${f} in ${d}/.gitignore"
echo "${f}" >> "${d}/.gitignore"
else
echo "Will ignore ${f} in ${d}/.gitignore"
fi
fi
done

0 comments on commit 7c292a3

Please sign in to comment.