Created
January 20, 2020 22:23
-
-
Save obfusk/0d0a988827c33bcb6d4ac5f557ef5224 to your computer and use it in GitHub Desktop.
gtree (tree w/ quick-and-dirty .gitignore support)
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 | |
set -e | |
args=() gitdir=. excl='.git|*~' | |
oldpwd="$PWD" | |
while [ "$PWD" != / -a "$PWD" != // ]; do | |
if [ -e .git ]; then | |
gitdir="$PWD"; break | |
fi | |
cd .. | |
done | |
cd "$oldpwd" | |
while read -r; do | |
excl="$( grep -Ev '^#|^$' "$REPLY" \ | |
| sed 's!^/!!; s!$!|!' | tr -d '\n' )$excl" | |
done < <( find "$gitdir" -name .gitignore ) | |
while [ $# -gt 0 ]; do | |
if [ "$1" = -I ]; then | |
shift; excl+="|$1" | |
else | |
args+=( "$1" ) | |
fi | |
shift | |
done | |
exec tree -I "$excl" "${args[@]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment