Created
June 3, 2021 21:07
-
-
Save juliovedovatto/ea51679a85ed6c68ef90ee2cb0bef893 to your computer and use it in GitHub Desktop.
GIT: ignoring files locally only (bash script)
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
#!/bin/bash | |
set -e | |
GIT_EXCLUDE_FILE="./.git/info/exclude" | |
[ "$#" -lt 1 ] && echo -e "Please give at least one argument" && exit 1 | |
[ ! -d "./.git" ] && echo -e "It seems this directory is not a root dir of a git repo. Aborting." && exit 1 | |
for file in "$@" | |
do | |
SKIP_FILE=false | |
if [ ! -e "${file}" ]; then | |
while true; do | |
read -p "It seems this file/directory does not exists. Add it anyway? [Y/n]" answer | |
case "${answer}" in | |
[Nn]* ) SKIP_FILE=true; break;; | |
[Yy]* ) exit;; | |
* ) echo "Please answer yes or no.";; | |
esac | |
done | |
fi | |
[ "${SKIP_FILE}" = true ] && continue | |
echo "${file}" >> "${GIT_EXCLUDE_FILE}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment