#!/usr/bin/env zsh set -e function headline { depth="${1}" text="${2}" printf "%${depth}s %s" "" | tr ' ' '*' echo " ${text}" } function scan_and_populate { depth="${1}" dir="${2}" headline ${depth} "${dir}" let "depth += 1" for f in $(ls -d "${dir}"/* 2>/dev/null); do if [ -d "${f}" ]; then scan_and_populate ${depth} "${f}" else headline ${depth} "[[file://${f}][${${f##*/}%.*}]]" fi done let "depth -= 1" } function main { scan_dir="${1:-$(pwd)}" depth=0 scan_and_populate ${depth} "${scan_dir}" } main "${@}"