#!/usr/bin/env bash # Display git-tracked files (or with -d, just directories) as a compact tree. # With -u, show untracked files instead. # With -u -I, show all untracked files, including ignored ones. # With a REGEX argument, show only the paths it matches. # Requires hledger (with a version <1.40, remove the -n below). set -e usage() { cat <&2 echo "Error: unknown option $1" exit 1 fi ;; esac done if [[ $HELP = 1 ]]; then usage; exit; fi REGEX="${ARGS[0]:-.}" ROOT=$(pwd) GITLS="git ls-files ${U:+-o $(if [[ $I = 1 ]]; then echo ''; else echo '--exclude-standard'; fi)}" # XXX the hledger accounts trick doesn't work for paths with double spaces in them $GITLS \ | grep -iE "$REGEX" \ | sed -e 's%/%/:%g' -e "s%^%account $ROOT/:%" \ | hledger -n -f- accounts -t \ | grep -E "$(if [[ $D = 1 ]]; then echo '/$'; else echo '.'; fi)"