Skip to content

Instantly share code, notes, and snippets.

@Ultrabenosaurus
Created January 23, 2016 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ultrabenosaurus/b44b62c58f989edbadaa to your computer and use it in GitHub Desktop.
Save Ultrabenosaurus/b44b62c58f989edbadaa to your computer and use it in GitHub Desktop.
handy bash function to show the directory tree from your current location
# tree
# list the directory structure with the current location as the top level
# based on https://gist.github.com/gpupo/c546128385493c71246d
tree() {
if [ ! $# -eq 0 ]; then
case $1 in
-a) ls -aR | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/';;
-at) ls -a | grep "/$" | sed -e 's~/$~~' -e 's/^/--/g' -e 's/^/ /' -e 's/-/|/';;
-t) ls | grep "/$" | sed -e 's~/$~~' -e 's/^/--/g' -e 's/^/ /' -e 's/-/|/';;
*) ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/';;
esac
else
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/';
fi;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment