Created
February 20, 2024 12:09
-
-
Save nestoru/6a78e03e6c093372062f8bb5227a7b82 to your computer and use it in GitHub Desktop.
cd git-project && /opt/scripts/tree-gitignore.sh
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment