Created
September 4, 2023 17:26
-
-
Save kenzic/e5a8715419949ffd256c551f6be1c557 to your computer and use it in GitHub Desktop.
This file contains 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
function gir() { | |
# Check if the user provided an argument | |
if [ -z "$1" ]; then | |
echo "Error: You must specify a file or folder to add to .gitignore." | |
echo "Usage: $0 <file_or_folder_to_ignore>" | |
return 1 | |
fi | |
# Check if the current directory is a git repository | |
if [ ! -d ".git" ] && [ ! -f ".git" ]; then | |
echo "Error: This directory is not a git repository." | |
return 1 | |
fi | |
# Check if the file or folder specified exists | |
if [ ! -e "$1" ]; then | |
echo "Error: The specified file or folder does not exist." | |
return 1 | |
fi | |
# Get the current directory | |
current_dir=$(pwd) | |
# Path to the .gitignore file | |
gitignore_file="$current_dir/.gitignore" | |
# Create the .gitignore file if it doesn't exist | |
if [ ! -f "$gitignore_file" ]; then | |
touch "$gitignore_file" | |
fi | |
# Check for duplicate entries | |
if grep -Fxq "$1" "$gitignore_file"; then | |
echo "Warning: $1 is already in .gitignore." | |
else | |
# Add the file or folder to .gitignore | |
echo "$1" >> "$gitignore_file" | |
echo "$1 has been added to $gitignore_file." | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment