Skip to content

Instantly share code, notes, and snippets.

@jpwilliams
Last active May 7, 2025 19:39
Show Gist options
  • Save jpwilliams/dabff82b0ceb95dd57a7552ea7f2d675 to your computer and use it in GitHub Desktop.
Save jpwilliams/dabff82b0ceb95dd57a7552ea7f2d675 to your computer and use it in GitHub Desktop.
Tree using .gitignore

Uses tree along with a .gitignore file to filter results. Defaults to ignoring node_modules if no .gitignore can be found in the current directory or in the git repo's root directory.

Would be cooler if we knew exacty where .gitignore files made a difference. Even nicer if the output showed the status of files in Git (modified, unchanged, new, deleted etc).

Package?

tree -C -I $((cat .gitignore 2> /dev/null || cat $(git rev-parse --show-toplevel 2> /dev/null)/.gitignore 2> /dev/null || echo "node_modules") | egrep -v "^#.*$|^[[:space:]]*$" | tr "\\n" "|" | rev | cut -c 2- | rev)
@brunos3d
Copy link

brunos3d commented May 7, 2025

@jpwilliams Nice work btw, thanks for the attention! 🥳

hanshake

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment