Skip to content

Instantly share code, notes, and snippets.

@gerrard00
Created May 6, 2023 16:22
Show Gist options
  • Save gerrard00/405266273b22c81e3cfa9241608de05f to your computer and use it in GitHub Desktop.
Save gerrard00/405266273b22c81e3cfa9241608de05f to your computer and use it in GitHub Desktop.
Make the tree CLI respect .gitignore without any additional packages
# make tree respect gitignore if we are in a repository
function tree_with_ignore() {
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
git ls-tree -r --name-only HEAD | tree --fromfile "$@"
else
tree $@
fi
}
alias tree="tree_with_ignore"
@sydney-sisco
Copy link

works great, thanks!

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