lib (951B)
1 # Common functions for scripts 2 3 out() { printf '%s\n' "$@" >&2 ;} 4 err() { printf 'err: %s\n' "$@" >&2 ;} 5 die() { err "$@"; exit 1 ;} 6 7 lsindex() { 8 # This is a functionized version of lsindex. 9 # Script version: https://gist.github.com/4d8a03d65b7744365aaef88f7877cd22 10 case "$1" in 11 '') set -- "$PWD" ;; 12 /*) ;; 13 *) set -- "$(cd "$1" || return 1; printf "$PWD")" 14 esac 15 16 unset parentdir 17 curdir="${PWD#$1}" title="index of ${curdir:=/}" 18 19 [ "$curdir" = / ] || { parentdir=${curdir%/*}; : "${parentdir:=/}" ;} 20 printf "<html><head><title>$title</title></head><body><h1>$title</h1><ul>" 21 22 [ "$parentdir" ] && printf "<li><a href=$parentdir>Parent Directory</a></li>" 23 for file in *; do 24 [ "$file" = index.html ] && continue 25 [ -d "$file" ] && file="$file/" 26 printf '<li><a href="%s">%s</a></li>' "$file" "$file" 27 done 28 printf '%s\n' "</ul></body></html" 29 }