From f7464fdd2e33e5dc6c159a4adc8f53902e6d4511 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 13 Apr 2011 23:20:15 -0400 Subject: Initial commit of Luke Shumaker's "dot-files". --- .emacs.d/org-7.4/contrib/scripts/dir2org.zsh | 56 ++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 .emacs.d/org-7.4/contrib/scripts/dir2org.zsh (limited to '.emacs.d/org-7.4/contrib/scripts/dir2org.zsh') diff --git a/.emacs.d/org-7.4/contrib/scripts/dir2org.zsh b/.emacs.d/org-7.4/contrib/scripts/dir2org.zsh new file mode 100755 index 0000000..f91ff17 --- /dev/null +++ b/.emacs.d/org-7.4/contrib/scripts/dir2org.zsh @@ -0,0 +1,56 @@ +#!/usr/bin/env zsh + +# desc: +# +# Output an org compatible structure representing the filesystem from +# the point passed on the command line (or . by default). +# +# options: +# none +# +# usage: +# dir2org.zsh [DIR]... +# +# author: +# Phil Jackson (phil@shellarchive.co.uk) + +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}" + + # if there is no files in dir then just move on + [[ $(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 "${@}" -- cgit v1.2.3-2-g168b