1. # Add this to your .bashrc or .zshrc or wherever
  2. # Copyright (C) 2012 by Adam Katz <http://www.khopis.com/scripts>, GPLv3+
  3. # see also http://www.commandlinefu.com/commands/view/10592/
  4. function tree() {
  5.   local dirs_only=''
  6.   case $1 in
  7.     -d )   dirs_only="-type d"; shift ;;
  8.     -?* )  [ ! -r "$1" ] && echo "Usage: tree [-d] [PATH...]" && return 1 ;;
  9.   esac
  10.   find "${@:-.}" $dirs_only |sed 's:[^-][^/]*/:--:g; s/^-/ |/'
  11. }