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