emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
blob f91ff17923c9404187c206d96b33ca1378036174 1013 bytes (raw)
name: contrib/scripts/dir2org.zsh 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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 "${@}"

debug log:

solving f91ff17923c9404187c206d96b33ca1378036174 ...
found f91ff17923c9404187c206d96b33ca1378036174 in https://git.savannah.gnu.org/cgit/emacs/org-mode.git

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).