A comprehensive git extension for managing .gitignore files with intelligent autocomplete support for bash and zsh shells.
- Intuitive Command Interface: Manage
.gitignorepatterns using familiar git-style commands - Intelligent Autocomplete: Full tab completion for files, directories, and patterns in both bash and zsh
- Smart Pattern Management: Add, remove, and list patterns with duplicate detection
- File Status Checking: Verify whether files are ignored by current patterns
- Repository Awareness: Works seamlessly within git repositories with proper root detection
- Tracked File Warnings: Alerts when attempting to ignore already-tracked files
Clone the repository and run the installation script:
git clone <repository-url> git-ignore-extension
cd git-ignore-extension
chmod +x install.sh
./install.sh-
Install the main script:
cp git-ignore ~/.local/bin/ chmod +x ~/.local/bin/git-ignore
-
Add to PATH (if not already included):
echo 'export PATH="$PATH:$HOME/.local/bin"' >> ~/.bashrc
-
Install bash completion:
mkdir -p ~/.local/share/bash-completion/completions cp git-ignore-completion.bash ~/.local/share/bash-completion/completions/git-ignore
-
Install zsh completion:
mkdir -p ~/.zsh/completions cp git-ignore-completion.zsh ~/.zsh/completions/_git-ignore
Add to your ~/.bashrc:
# Enable git-ignore completion
for file in ~/.local/share/bash-completion/completions/*; do
[ -f "$file" ] && source "$file"
doneAdd to your ~/.zshrc:
# Add completion directory to fpath
fpath=(~/.zsh/completions $fpath)
# Initialise completion system
autoload -Uz compinit && compinitThe extension supports both standalone and git subcommand usage:
git ignore <pattern> # Add pattern (default action)
git ignore add <pattern>... # Explicitly add patterns
git ignore remove <pattern>... # Remove patterns
git ignore list # List all patterns
git ignore check <file>... # Check if files are ignored
git ignore help # Show help informationAdd single or multiple patterns to .gitignore:
# Default add (without 'add' command)
git ignore "*.log"
# Explicit add command
git ignore add "*.tmp" "*.cache"
# Add directories
git ignore add build/ dist/ node_modules/
# Add with wildcards (use quotes)
git ignore add "*.py[co]" "__pycache__/"Remove existing patterns from .gitignore:
git ignore remove "*.log"
git ignore rm "*.tmp" # 'rm' is an alias for 'remove'Display all patterns in the current .gitignore:
git ignore list
git ignore ls # 'ls' is an alias for 'list'Verify whether files match ignore patterns:
git ignore check file.txt
git ignore check src/main.py tests/*.pyThe extension provides context-aware autocomplete:
When adding patterns, autocomplete suggests:
- Untracked files in the repository
- Directories (up to 2 levels deep)
- Common ignore patterns (when no input is provided)
git ignore add src/<TAB> # Completes files in src/
git ignore build/<TAB> # Completes subdirectories
git ignore <TAB> # Shows files, directories, and commandsWhen removing patterns, autocomplete shows existing patterns from .gitignore:
git ignore remove <TAB> # Lists current .gitignore patterns
git ignore rm *.lo<TAB> # Completes to *.log if it existsgit ignore <TAB> # Shows available commands
git ignore a<TAB> # Completes to 'add'
git ignore r<TAB> # Shows 'remove' and 'rm'The autocomplete system suggests common patterns when appropriate:
*.log- Log files*.tmp- Temporary files*.swp- Vim swap files.DS_Store- macOS system filesnode_modules/- Node.js dependenciesbuild/- Build directoriesdist/- Distribution directories*.pyc- Python compiled files__pycache__/- Python cache directories.env- Environment variable files.vscode/- VS Code settings.idea/- IntelliJ IDEA settings
The extension automatically normalises patterns:
- Removes leading
./from paths - Handles relative paths correctly
- Preserves pattern syntax (wildcards, negations)
Prevents adding duplicate patterns and provides feedback:
$ git ignore add "*.log"
✓ Added: *.log
$ git ignore add "*.log"
⚠ Pattern already exists: *.logWarns when attempting to ignore files already tracked by git:
$ git ignore add src/main.py
✓ Added: src/main.py
⚠ File 'src/main.py' is already tracked by git. You may want to run:
git rm --cached src/main.pyAutomatically operates from the repository root, ensuring consistent behaviour regardless of current working directory.
If git ignore is not recognised:
-
Ensure
~/.local/binis in your PATH:echo $PATH | grep -q "$HOME/.local/bin" || echo "Not in PATH"
-
Reload your shell configuration:
source ~/.bashrc # For bash source ~/.zshrc # For zsh
-
Verify completion file exists:
ls ~/.local/share/bash-completion/completions/git-ignore -
Check if completion is sourced in
.bashrc -
Restart your terminal or run:
source ~/.local/share/bash-completion/completions/git-ignore
-
Verify completion file exists:
ls ~/.zsh/completions/_git-ignore -
Ensure
fpathincludes the completion directory:echo $fpath | grep -q ".zsh/completions" || echo "Not in fpath"
-
Rebuild completion cache:
rm -f ~/.zcompdump && compinit
Ensure the script is executable:
chmod +x ~/.local/bin/git-ignore- Git (version 2.0 or higher)
- Bash 4.0+ or Zsh 5.0+
- Standard Unix utilities (grep, sed, find)
git-ignore-extension/
├── git-ignore # Main executable script
├── git-ignore-completion.bash # Bash completion script
├── git-ignore-completion.zsh # Zsh completion script
├── install.sh # Installation script
└── README.md # Documentation
Contributions are welcome. When submitting changes:
- Maintain consistent code style
- Test with both bash and zsh shells
- Update documentation as needed
- Ensure autocomplete functionality remains intact
MIT
Celso Pinto celso@celsopinto.com