Skip to content

Instantly share code, notes, and snippets.

@obfusk
Created January 20, 2020 22:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save obfusk/0d0a988827c33bcb6d4ac5f557ef5224 to your computer and use it in GitHub Desktop.
Save obfusk/0d0a988827c33bcb6d4ac5f557ef5224 to your computer and use it in GitHub Desktop.
gtree (tree w/ quick-and-dirty .gitignore support)
#!/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