diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2011-04-13 23:20:15 -0400 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2011-04-13 23:20:15 -0400 |
commit | f7464fdd2e33e5dc6c159a4adc8f53902e6d4511 (patch) | |
tree | b1d65db982af54cc2088de3228174c4ea710c2f4 /.emacs.d/org-7.4/contrib/scripts/dir2org.zsh |
Initial commit of Luke Shumaker's "dot-files".
Diffstat (limited to '.emacs.d/org-7.4/contrib/scripts/dir2org.zsh')
-rwxr-xr-x | .emacs.d/org-7.4/contrib/scripts/dir2org.zsh | 56 |
1 files changed, 56 insertions, 0 deletions
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 "${@}" |