From 4ec4e01a1abdcccd993144d30ef2c58be59fb447 Mon Sep 17 00:00:00 2001 From: Phil Jackson Date: Fri, 8 Feb 2008 11:12:28 +0000 Subject: [PATCH] Added dir2org.zsh to contrib --- CONTRIB/ChangeLog | 4 +++ CONTRIB/README | 1 + CONTRIB/scripts/dir2org.zsh | 53 +++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100755 CONTRIB/scripts/dir2org.zsh diff --git a/CONTRIB/ChangeLog b/CONTRIB/ChangeLog index 0c63dd28d..9c5b146d9 100644 --- a/CONTRIB/ChangeLog +++ b/CONTRIB/ChangeLog @@ -1,3 +1,7 @@ +2008-02-08 Phil Jackson + + * scripts/dir2org.zsh: New file. + 2008-02-07 Phil Jackson * lisp/org-annotate-file.el: New file. diff --git a/CONTRIB/README b/CONTRIB/README index 04402fef2..4383c4175 100644 --- a/CONTRIB/README +++ b/CONTRIB/README @@ -34,3 +34,4 @@ org-export-freemind --- exporting utilities from org-mode to freemind SCRIPTS (shell, bash, etc.) =========================== +dir2org.zsh --- Org compatible fs structure output diff --git a/CONTRIB/scripts/dir2org.zsh b/CONTRIB/scripts/dir2org.zsh new file mode 100755 index 000000000..27e34a566 --- /dev/null +++ b/CONTRIB/scripts/dir2org.zsh @@ -0,0 +1,53 @@ +#!/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.bash [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}" + + (( 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 { + local scan_dir="${1:-$(pwd)}" + local depth=0 + + scan_and_populate ${depth} "${scan_dir}" +} + +main "${@}"