59 lines
1.4 KiB
Bash
59 lines
1.4 KiB
Bash
|
#!/usr/bin/env bash
|
||
|
#
|
||
|
# Dump the AST of an org-mode document from emacs
|
||
|
set -euo pipefail
|
||
|
IFS=$'\n\t'
|
||
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||
|
|
||
|
REALPATH=$(command -v uu-realpath || command -v realpath)
|
||
|
MAKE=$(command -v gmake || command -v make)
|
||
|
|
||
|
############## Setup #########################
|
||
|
|
||
|
function die {
|
||
|
local status_code="$1"
|
||
|
shift
|
||
|
(>&2 echo "${@}")
|
||
|
exit "$status_code"
|
||
|
}
|
||
|
|
||
|
function log {
|
||
|
(>&2 echo "${@}")
|
||
|
}
|
||
|
|
||
|
############## Program #########################
|
||
|
|
||
|
function main {
|
||
|
if [ $# -eq 0 ]; then
|
||
|
dump_ast_stdin "${@}"
|
||
|
else
|
||
|
dump_ast_file "${@}"
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
function dump_ast_stdin {
|
||
|
# Until we can find a good way to encode stdin as an elisp string in bash, I cannot operate on stdin.
|
||
|
die 1 "This script only works on files."
|
||
|
}
|
||
|
|
||
|
function dump_ast_file {
|
||
|
local target_file mounted_file elisp_script
|
||
|
target_file=$($REALPATH "$1")
|
||
|
mounted_file="/input${target_file}"
|
||
|
elisp_script=$(cat <<EOF
|
||
|
(progn
|
||
|
(erase-buffer)
|
||
|
(require 'org)
|
||
|
(defun org-table-align () t)
|
||
|
(find-file-read-only "${mounted_file}")
|
||
|
(org-mode)
|
||
|
(message "%s" (pp-to-string (org-element-parse-buffer)))
|
||
|
)
|
||
|
EOF
|
||
|
)
|
||
|
exec docker run --init --rm -i --mount type=tmpfs,destination=/tmp -v "/:/input:ro" --entrypoint "" organic-test emacs -q --no-site-file --no-splash --batch --eval "$elisp_script"
|
||
|
}
|
||
|
|
||
|
|
||
|
main "${@}"
|