Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions zsh/custom-functions/custom-functions.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,31 @@ function filesize() {
stat -c "%s bytes" "$@"
fi
}

# ignore files from git
# usage: ignore_from_git file1.md file2.txt folder1/ folder2/**
ignore_from_git() {
local exclude_file=".git/info/exclude"

if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo "Error: Not a git repository." >&2
return 1
fi

if [ $# -eq 0 ]; then
echo "Error: No file or folder was specified." >&2
echo "Usage: ignore_from_git file1.md file2.txt folder1/ folder2/**" >&2
return 1
fi

for pattern in "$@"; do
local escaped_pattern=$(printf '%s\n' "$pattern" | sed 's/[[\.*^$()+?{|]/\\&/g')

if ! grep -Fxq -- "$pattern" "$exclude_file" 2>/dev/null; then
echo "$pattern" >> "$exclude_file"
echo "Added: $pattern to $exclude_file"
else
echo "$pattern already exists in $exclude_file"
fi
done
}