#!/bin/sh
#
# trel - [tre]e [l]ist

# shellcheck disable=SC2249
case "$1" in
  [0-9])
    depth="$1"
    shift
    ;;
esac

if command -v tree >/dev/null 2>&1; then
  # tree --dirsfirst --du -h -C -L "${depth:-3}" -I .git -I node_modules "$@" \
  #   | ${PAGER:-less} -rF
  exec tree --charset=ascii --dirsfirst --du -h -CF -L "${depth:-3}" \
    -I '.git' "$@" | ${PAGER:-"less -RF"}
else
  exec find -- . -maxdepth "${depth:-3}" -path '*/.git' -prune -o -path './*' 2>/dev/null \
    | sed -Ee '2,$s:[^/]*/:   :g; s:   ([^ ]+)$:|_ \1:' \
    | ${PAGER:-"less -RF"}
fi
