From ef5256bd35bd340fcad5b267977c9c80db7d3589 Mon Sep 17 00:00:00 2001 From: Tiago Celestino Date: Fri, 31 Oct 2025 10:26:05 -0300 Subject: [PATCH 1/2] feat: create custom fn to use git exclude folder and file --- .../custom-functions.plugin.zsh | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/zsh/custom-functions/custom-functions.plugin.zsh b/zsh/custom-functions/custom-functions.plugin.zsh index 7fd2dcc..644b7ba 100755 --- a/zsh/custom-functions/custom-functions.plugin.zsh +++ b/zsh/custom-functions/custom-functions.plugin.zsh @@ -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 [ ! -f "$exclude_file" ]; then + echo "Error: Git repository not found (file $exclude_file does not exist)" + return 1 + fi + + if [ $# -eq 0 ]; then + echo "Error: No file or folder was specified" + echo "Usage: ignore_from_git file1.md file2.txt folder1/ folder2/**" + return 1 + fi + + for pattern in "$@"; do + local escaped_pattern=$(printf '%s\n' "$pattern" | sed 's/[[\.*^$()+?{|]/\\&/g') + + if ! grep -q "^${escaped_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 +} From e89a89212b5b12475af5f952ed215666dda3eaf9 Mon Sep 17 00:00:00 2001 From: Tiago Celestino Date: Fri, 31 Oct 2025 10:39:05 -0300 Subject: [PATCH 2/2] refactor: improvement from gemini code reviewer --- zsh/custom-functions/custom-functions.plugin.zsh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/zsh/custom-functions/custom-functions.plugin.zsh b/zsh/custom-functions/custom-functions.plugin.zsh index 644b7ba..a3f0c22 100755 --- a/zsh/custom-functions/custom-functions.plugin.zsh +++ b/zsh/custom-functions/custom-functions.plugin.zsh @@ -99,21 +99,21 @@ function filesize() { ignore_from_git() { local exclude_file=".git/info/exclude" - if [ ! -f "$exclude_file" ]; then - echo "Error: Git repository not found (file $exclude_file does not exist)" + 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" - echo "Usage: ignore_from_git file1.md file2.txt folder1/ folder2/**" + 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 -q "^${escaped_pattern}$" "$exclude_file" 2>/dev/null; then + if ! grep -Fxq -- "$pattern" "$exclude_file" 2>/dev/null; then echo "$pattern" >> "$exclude_file" echo "Added: $pattern to $exclude_file" else