瀏覽代碼

Added dir2org.zsh to contrib

Phil Jackson 17 年之前
父節點
當前提交
4ec4e01a1a
共有 3 個文件被更改,包括 58 次插入0 次删除
  1. 4 0
      CONTRIB/ChangeLog
  2. 1 0
      CONTRIB/README
  3. 53 0
      CONTRIB/scripts/dir2org.zsh

+ 4 - 0
CONTRIB/ChangeLog

@@ -1,3 +1,7 @@
+2008-02-08  Phil Jackson  <phil@shellarchive.co.uk>
+
+	* scripts/dir2org.zsh: New file.
+
 2008-02-07  Phil Jackson  <phil@shellarchive.co.uk>
 
 	* lisp/org-annotate-file.el: New file.

+ 1 - 0
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

+ 53 - 0
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 "${@}"