Skip to content

Instantly share code, notes, and snippets.

@nestoru
Created February 20, 2024 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nestoru/6a78e03e6c093372062f8bb5227a7b82 to your computer and use it in GitHub Desktop.
Save nestoru/6a78e03e6c093372062f8bb5227a7b82 to your computer and use it in GitHub Desktop.
cd git-project && /opt/scripts/tree-gitignore.sh
#!/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