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
#!/bin/bash | |
# /opt/scripts/tree-gitignore.sh | |
# Author: Nestor Urquiza | |
# Date: 20240220 | |
# Description: A tree wrapper to show contents of a git project respecting .gitignore | |
# Usage: cd git-project && /opt/scripts/tree-gitignore.sh | |
cmd="tree -a -I '.git'" | |
# Read each line from .gitignore | |
while IFS= read -r line; do | |
# Skip empty lines and comments | |
if [[ "$line" != "" && "$line" != \#* ]]; then | |
# Remove leading "**/" from patterns, if present | |
pattern="${line/\*\*\//}" | |
# Remove trailing "/*" from patterns, if present | |
pattern="${pattern/\/\*/}" | |
# Append each cleaned pattern as an ignore option | |
cmd+=" -I '$pattern'" | |
fi | |
done < .gitignore | |
# Execute the constructed command | |
eval $cmd |
No comments:
Post a Comment