Skip to content

Instantly share code, notes, and snippets.

@pyliaorachel
Last active January 21, 2019 00:22
Show Gist options
  • Select an option

  • Save pyliaorachel/3221865484666d234c4bc43959a82ce4 to your computer and use it in GitHub Desktop.

Select an option

Save pyliaorachel/3221865484666d234c4bc43959a82ce4 to your computer and use it in GitHub Desktop.
Command to display directory tree structure ignoring everything in .gitignore
# Tested on AWS EC2 Linux
# tree -I '<pattern-to-ignore>' -> display tree
# grep -o '^[^#]*' .gitignore -> remove comments in .gitignore
# | sed 's/\/$//g' -> replace trailing '/' after directories
# | tr '\n' '|' -> join strings with '|'
tree -I $(grep -o '^[^#]*' .gitignore | sed 's/\/$//g' | tr '\n' '|')
# Tested on MacOSX
# tree -I '<pattern-to-ignore>' -> display tree
# grep -o '^[^#]*' .gitignore -> remove comments in .gitignore
# | sed 's/\/$//g' -> replace trailing '/' after directories
# | sed '/^$/d' -> delete newlines
# | tr '\n' '|' -> join strings with '|'
# | sed 's/|$//g' -> remove the last '|'
tree -I $(grep -o '^[^#]*' .gitignore | sed 's/\/$//g' | sed '/^$/d' | tr '\n' '|' | sed 's/|$//g')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment