Final decisions about global/local for sticky agendas.
[org-mode/org-tableheadings.git] / contrib / scripts / dir2org.zsh
blobf91ff17923c9404187c206d96b33ca1378036174
1 #!/usr/bin/env zsh
3 # desc:
5 # Output an org compatible structure representing the filesystem from
6 # the point passed on the command line (or . by default).
8 # options:
9 # none
11 # usage:
12 # dir2org.zsh [DIR]...
14 # author:
15 # Phil Jackson (phil@shellarchive.co.uk)
17 set -e
19 function headline {
20 local depth="${1}"
21 local text="${2}"
23 printf "%${depth}s %s" "" | tr ' ' '*'
24 echo " ${text}"
27 function scan_and_populate {
28 local depth="${1}"
29 local dir="${2}"
31 headline ${depth} "${dir}"
33 # if there is no files in dir then just move on
34 [[ $(ls "${dir}" | wc -l) -eq 0 ]] && return
36 (( depth += 1 ))
38 for f in $(ls -d "${dir}"/*); do
39 if [ -d "${f}" ]; then
40 scan_and_populate ${depth} "${f}"
41 else
42 headline ${depth} "[[file://${f}][${${f##*/}%.*}]]"
44 done
46 (( depth -= 1 ))
49 function main {
50 local scan_dir="${1:-$(pwd)}"
51 local depth=0
53 scan_and_populate ${depth} "${scan_dir}"
56 main "${@}"