- #!/usr/bin/env bash
-
- SSH_BIN="/path/to/ssh/on/client"
- USER="user_name"
- HOST="server_name"
- NOTMUCH_REMOTE_BIN="/path/to/notmuch/on/server"
-
- if [ $1 = "search" ]; then
- COUNT=0;
- OUT=`$SSH_BIN $USER@$HOST $NOTMUCH_REMOTE_BIN $@`
- echo "$OUT" | while read line; do
- COUNT=`expr $COUNT + 1`
- echo "$line";
- if [ $COUNT = 10 ]; then
- sleep 0.1;
- fi
- done
- else
- $SSH_BIN $USER@$HOST $NOTMUCH_REMOTE_BIN $@
- fi
-
+ #!/usr/bin/env bash
+ SSH_BIN="/path/to/ssh/on/client"
+ USER="user_name"
+ SSH_HOST="server_name"
+ NOTMUCH_REMOTE_BIN="/path/to/notmuch/on/server"
+ CACHE="${HOME}/.notmuch-cache.d"
+
+ hash_name ()
+ {
+ echo -n ${1} | sha1sum | awk '{print $1}'
+ }
+
+ check_for_file_name ()
+ {
+ [ -f "${CACHE}/${1}" ]
+ }
+
+ notmuch_run ()
+ {
+ [ -d "${CACHE}" ] || mkdir -p "${CACHE}"
+ CMD=$1
+ shift
+ # we need to a little sanitizing of msg ids so the shell
+ # doesn't mangle them
+ printf -v ARGS "%q " "$@"
+ $SSH_BIN $USER@$SSH_HOST $NOTMUCH_REMOTE_BIN ${CMD} ${ARGS}
+ }
+
+ notmuch_search ()
+ {
+ notmuch_run search $@ |
+ while read line; do
+ sleep 0.02 # Workaround a bug (missing lines) in the emacs interface
+ # NOTE: This workaround is no longer necessary as of
+ # git rev eead2382. You can just run
+ # `notmuch_run search $@'
+ echo "${line}"
+ done
+ }
+
+
+ notmuch_show ()
+ {
+ if [ ${1} = "--format=raw" ]; then
+ hashed=`hash_name ${2}`
+ check_for_file_name ${hashed} ||
+ notmuch_run show --format=raw ${2} > "${CACHE}/${hashed}"
+ cat "${CACHE}/${hashed}"
+ else
+ notmuch_run show $@
+ fi
+ }
+
+
+ if [ ${1} = "search" ]; then
+ shift
+ notmuch_search $@
+ elif [ ${1} = "show" ]; then
+ shift
+ notmuch_show $@
+ else
+ notmuch_run $@
+ fi
+
+