Created
May 6, 2023 16:22
-
-
Save gerrard00/405266273b22c81e3cfa9241608de05f to your computer and use it in GitHub Desktop.
Make the tree CLI respect .gitignore without any additional packages
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
# 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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
works great, thanks!