summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaromil <jaromil@dyne.org>2011-10-23 22:54:41 (GMT)
committer Jaromil <jaromil@dyne.org>2011-10-23 22:54:41 (GMT)
commit6cf306b807cb1a76da857b7c6907e922d70a9c41 (patch)
treef463841b5fc4554774e3bdeb52af1b354d123c2c
parent714144a1158722dab27b18d3cefeb00a0b7ddcda (diff)
correct rendering of mobileorg indexes
-rw-r--r--.gitignore6
-rw-r--r--share/elisp/org-batch.el.in16
-rwxr-xr-xsrc/autorg325
3 files changed, 337 insertions, 10 deletions
diff --git a/.gitignore b/.gitignore
index 5b24c07..6bee3f8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -39,12 +39,6 @@ ltmain.sh
Makefile
Makefile.in
missing
-/org
-src/*.el
-src/autorg
-src/autorg-*
-!/src/autorg-*.in
-!/src/*.png
stamp-h1
tags
src/old
diff --git a/share/elisp/org-batch.el.in b/share/elisp/org-batch.el.in
index d6ae003..6de0417 100644
--- a/share/elisp/org-batch.el.in
+++ b/share/elisp/org-batch.el.in
@@ -119,14 +119,22 @@
(list project))))))
; directory used for mobile-org files
-
+; %meta-paths% are filled in by config
(custom-set-variables
-
- ; meta-paths (filled in by config)
+; Set to the location of your Org files on your local system
'(org-directory "%autorg_path%")
+;; Set to the name of the file where new notes will be stored
+;; Set to <your drop directory>/MobileOrg.
'(org-mobile-directory "%autorg_path%/mobile")
- '(org-agenda-files (quote ("%autorg_path%/agenda.org")))
'(org-mobile-files (quote ("%autorg_path%/mobile.org")))
+ '(org-mobile-inbox-for-pull "%autorg_path%/mobilepull.org")
+ '(org-mobile-capture-file "%autorg_path%/sync/mobileorg.org")
+
+
+; '(org-agenda-files (quote ("%autorg_path%/agenda.org")))
+
+ ;; '(org-agenda-files (quote ("%autorg_path%/agenda.org")))
+ ;; '(org-mobile-files (quote ("%autorg_path%/mobile.org")))
; export options (todo: make them configurable)
'(org-export-html-inline-images t)
diff --git a/src/autorg b/src/autorg
new file mode 100755
index 0000000..0021bc1
--- /dev/null
+++ b/src/autorg
@@ -0,0 +1,325 @@
+#!/bin/zsh
+#
+# Autorg :: autonomy is organization
+#
+# a tool to privately handle your agenda
+# based on Emacs and org-mode
+#
+# Copyleft (C) 2010-2011 Denis Roio <jaromil@dyne.org>
+#
+# This source code is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This source code is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# Please refer to the GNU Public License for more details.
+#
+# You should have received a copy of the GNU Public License along with
+# this source code; if not, write to:
+# Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+VERSION=0.3
+DATE=Oct/2011
+AUTORGEXEC=$0
+typeset -a OLDARGS
+for arg in ${argv}; do OLDARGS+=($arg); done
+
+#declare global variables
+QUIET=0
+DEBUG=0
+PARAM=()
+typeset -A global_opts
+typeset -A opts
+
+
+autoload colors; colors
+
+# standard output message routines
+# it's always useful to wrap them, in case we change behaviour later
+notice() { if [[ $QUIET == 0 ]]; then print "$fg_bold[green][*]$fg_no_bold[white] $1" >&2; fi }
+error() { if [[ $QUIET == 0 ]]; then print "$fg[red][!]$fg[white] $1" >&2; fi }
+func() { if [[ $DEBUG == 1 ]]; then print "$fg[blue][D]$fg[white] $1" >&2; fi }
+act() {
+ if [[ $QUIET == 0 ]]; then
+ if [ "$1" = "-n" ]; then
+ print -n "$fg_bold[white] . $fg_no_bold[white] $2" >&2;
+ else
+ print "$fg_bold[white] . $fg_no_bold[white] $1" >&2;
+ fi
+ fi
+}
+
+
+# parse configuration
+if [ -r /etc/autorg/config ]; then source /etc/autorg/config; fi
+if [ -r $HOME/.autorg/config ]; then source $HOME/.autorg/config
+else WORKDIR=$HOME/.autorg; fi # default
+# environment variable overrides all
+if [ $AUTORG ]; then
+ if [ -r $AUTORG/config ]; then
+ source $AUTORG/config
+ else
+ error "configuration not found in $AUTORG"
+ error "correct your AUTORG environment."
+ return 1
+ fi
+fi
+
+# temp dir
+mkdir -p /tmp/autorg
+
+notice "Autorg $VERSION starting...."
+act "using directory in $WORKDIR"
+
+# ZSH commandline parser by Boyska ( Tomb.dyne.org )
+option_is_set() {
+ #First argument, the option (something like "-s")
+ #Second (optional) argument: if it's "out", command will print it out 'set'/'unset'
+ # This is useful for if conditions
+ #Return 0 if is set, 1 otherwise
+ [[ -n ${(k)opts[$1]} ]];
+ r=$?
+ if [[ $2 == out ]]; then
+ if [[ $r == 0 ]]; then
+ echo 'set'
+ else
+ echo 'unset'
+ fi
+ fi
+ return $r;
+}
+option_value() {
+ #First argument, the option (something like "-s")
+ <<< ${opts[$1]}
+}
+
+emacs-batch() {
+ # used internally: renders the elisp file with config paths
+ # then launches the desired command.
+
+ local org_batch_templ
+ org_batch_templ="${DATADIR}/elisp/org-batch.el.in"
+ if ! [ -r "${org_batch_templ}" ]; then
+ error "org_batch template not found in `dirname ${org_batch_templ}`"
+ return 1
+ fi
+ act "using org-batch template ${org_batch_templ}"
+
+ act "emacs-batch executing ${1}"
+
+ rm -f /tmp/autorg/org-batch.el
+
+ sed -e 's@\%orgmode_path\%@'"$ORGMODE_DIR"'@g' \
+ -e 's@\%autorg_path\%@'"$WORKDIR"'@g' \
+ -e 's@\%data_path\%@'"$DATADIR"'@g' \
+ ${DATADIR}/elisp/org-batch.el.in > \
+ /tmp/autorg/org-batch.el
+
+ emacs ${EMACS_OPTS} -batch -l /tmp/autorg/org-batch.el --eval="${1}"
+
+}
+
+init() {
+ if [ $1 ]; then
+ WORKDIR=${1}
+ fi
+
+ # initializes a blank directory
+ if [ -r $WORKDIR/.git/index ]; then
+ error "AutOrg already initialized in $WORKDIR"
+ error "operation aborted."
+ return 1
+ fi
+ mkdir -p $WORKDIR
+ mkdir -p $WORKDIR/manual
+ mkdir -p $WORKDIR/mobile
+ cp /etc/autorg/config $WORKDIR
+ cp $DATADIR/org-templates/agenda-setup.org $WORKDIR
+ cat <<EOF > $WORKDIR/.gitignore
+manual
+*.ps
+EOF
+ cat <<EOF > $WORKDIR/agenda.org
+#+TITLE: AutOrg agenda
+#+SETUPFILE: $WORKDIR/agenda-setup.org
+* `date +%Y`
+EOF
+ cat <<EOF > $WORKDIR/mobile.org
+#+TITLE: AutOrg mobile notes
+EOF
+
+ cd $WORKDIR
+ git init
+ git add .
+ git commit -m "AutOrg automatic initialization"
+ cd -
+}
+
+mobile-sync() {
+ mkdir -p $WORKDIR/mobile
+
+ # refreshes files
+# emacs-batch "(org-mobile-apply)"
+# emacs-batch "(org-mobile-pull)"
+
+# emacs-batch "(org-mobile-create-sumo-agenda)"
+ emacs-batch "(org-mobile-push)"
+
+
+ which obexftp &> /dev/null
+ if [[ $? != 0 ]]; then
+ error "obexftp not found, needed for bluetooth: operation aborted."
+ return 1
+ fi
+ # push all via bluetooth
+
+ mkdir -p $WORKDIR/sync
+ cd $WORKDIR/sync
+
+ files=`ls $WORKDIR/mobile | grep .org`
+
+ notice "Syncing files with device: $MOBILE dir: $MOBILEDIR"
+
+ for f in ${(f)files}; do gets+=("-G"); gets+=("$f"); done
+
+ for f in ${(f)files}; do puts+=("-p"); puts+=("$WORKDIR/mobile/$f"); done
+
+ obexftp -b ${MOBILE} -C ${MOBILEDIR} \
+ -k checksums.dat ${(@)gets}
+
+ emacs-batch "(org-mobile-pull)"
+
+ obexftp -b ${MOBILE} -C ${MOBILEDIR} \
+ -p $WORKDIR/mobile/checksums.dat ${(@)puts}
+ # obexftp -b ${MOBILE} -C ${MOBILEDIR} \
+ # -k checksums.dat -k mobileorg.org -k index.org -k agendas.org -k mobile.org \
+ # -p $WORKDIR/mobile/checksums.dat \
+ # -p $WORKDIR/mobile/mobileorg.org -p $WORKDIR/mobile/index.org \
+ # -p $WORKDIR/mobile/agendas.org -p $WORKDIR/mobile/mobile.org
+
+ # TODO error code
+ # return code of obexftp seems to be 255
+ return 0
+}
+
+publish() {
+# takes two args: name of project
+# and optionally "force" if should be all recompiled
+ local force="nil"
+ if [ "$2" = "force" ]; then
+ force="t"
+ act "forcing recompilation of all contents"
+ fi
+
+ emacs-batch "(org-publish-batch-project \"$1\" ${force})"
+}
+
+browse() {
+ sensible-browser "http://$WEBHOST:$PORT/index.html" &
+ gawk -f $DATADIR/awk/server.awk -v docroot=$1
+}
+
+
+main()
+ {
+ local -A subcommands_opts
+ ### Options configuration
+ #Hi, dear developer! Are you trying to add a new subcommand, or to add some options?
+ #Well, keep in mind that:
+ # 1. An option CAN'T have differente meanings/behaviour in different subcommands.
+ # For example, "-s" means "size" and accept an argument. If you are tempted to add
+ # an option "-s" (that means, for example "silent", and doesn't accept an argument)
+ # DON'T DO IT!
+ # There are two reasons for that:
+ # I. usability; user expect that "-s" is "size
+ # II. Option parsing WILL EXPLODE if you do this kind of bad things
+ # (it will say "option defined more than once, and he's right)
+ main_opts=(q -quiet=q D -debug=D h -help=h v -version=v n -dry-run=n)
+ subcommands_opts[__default]=""
+ subcommands_opts[init]=""
+ subcommands_opts[browse]=""
+ subcommands_opts[help]=""
+ subcommands_opts[edit]=""
+ subcommands_opts[sync]=""
+ subcommands_opts[source]=""
+
+# subcommands_opts[mount]=${subcommands_opts[open]}
+# subcommands_opts[create]="s: -size=s -ignore-swap k: -key=k"
+ ### Detect subcommand
+ local -aU every_opts #every_opts behave like a set; that is, an array with unique elements
+ for optspec in $subcommands_opts$main_opts; do
+ for opt in ${=optspec}; do
+ every_opts+=${opt}
+ done
+ done
+ local -a oldstar
+ oldstar=($argv)
+ zparseopts -M -E -D -Adiscardme ${every_opts}
+ unset discardme
+ subcommand=$1
+ if [[ -z $subcommand ]]; then
+ subcommand="__default"
+ fi
+ if [[ -z ${(k)subcommands_opts[$subcommand]} ]]; then #there's no such subcommand
+ error "Subcommand '$subcommand' doesn't exist"
+ exit 127
+ fi
+ argv=(${oldstar})
+ unset oldstar
+
+ ### Parsing global + command-specific options
+ # zsh magic: ${=string} will split to multiple arguments when spaces occur
+ set -A cmd_opts ${main_opts} ${=subcommands_opts[$subcommand]}
+ if [[ -n $cmd_opts ]]; then #if there is no option, we don't need parsing
+ zparseopts -M -E -D -Aopts ${cmd_opts}
+ if [[ $? != 0 ]]; then
+ error "Some error occurred during option processing."
+ exit 127
+ fi
+ fi
+ #build PARAM (array of arguments) and check if there are unrecognized options
+ local ok=0
+# PARAM=()
+ for arg in $*; do
+ if [[ $arg == '--' || $arg == '-' ]]; then
+ ok=1
+ continue #it shouldnt be appended to PARAM
+ elif [[ $arg[1] == '-' ]]; then
+ if [[ $ok == 0 ]]; then
+ error "unrecognized option $arg"
+ exit 127
+ fi
+ fi
+ PARAM+=$arg
+ done
+ #first parameter actually is the subcommand: delete it and shift
+ if [[ $subcommand != '__default' ]]; then
+ PARAM[1]=()
+ shift
+ fi
+ ### End parsing command-specific options
+
+ if option_is_set -v; then act "AutOrg - $VERSION"; fi
+ if option_is_set -h; then error "TODO usage here"; fi
+ if option_is_set -q; then QUIET=1; fi
+ if option_is_set -D; then func "Debug messages ON"; DEBUG=1; fi
+
+ case "$subcommand" in
+ init) init ;;
+ browse) browse ${PARAM} ;;
+ sync) mobile-sync ;;
+ edit) act "EDIT TODO" ;;
+ help) act "HELP TODO" ;;
+ __default) ;;
+ *) error "command \"$subcommand\" not recognized"
+ act "try -h for help"
+ return 1
+ ;;
+ esac
+ return 0
+}
+
+main $@