]> git.cworth.org Git - notmuch-wiki/blob - remoteusage.mdwn
Updated remote usage script to my current version.
[notmuch-wiki] / remoteusage.mdwn
1 [[!img notmuch-logo.png alt="Notmuch logo" class="left"]]
2 #Using notmuch remotely#
3
4 ##Why?##
5 It is hard to keep nomuch tags in sync across multiple instances of
6 notmuch, on multiple computers. Though you can do this with "notmuch
7 dump" and "notmuch restore", it is often preferable to be able to use
8 notmuch on a remote computer as if it were present on a local
9 computer.
10
11 The following guidelines show how I have accomplished this. It isn't
12 perfect, but it works pretty well, and allows me to access notmuch on
13 my home computer, using only an emacs client on my netbook or work
14 computer, a trivial shell script, a few settings in my .emacs, and a
15 couple of common unix utilities (ssh and dtach).
16
17 ##What you will need##
18 You will need to have the following items in place:
19
20 1.  a working notmuch on one computer (let's call that computer
21 "server"). 
22 2.  a working notmuch emacs interface on another computer (let's call
23 that computer "client")
24 3.   `ssh` and `dtach` on your client computer. (TODO: Make dtach
25 optional, or allow screen or tmux to be used instead.)
26 4.   password-free login (public key authentication) from client to
27 server. [Here](http://www.debian-administration.org/articles/152) is a
28 good page on how to set it up.
29 5.   a reasonably fast connection. (This isn't really *neccessary*, but
30 if your connection is too slow, this won't be very pleasant to use,
31 and certainly won't seem transparent.)
32
33
34 ##Write a wrapper shell script##
35
36 Now we will need to write a simple shell script that does two things:
37
38 1.  replaces the call to the notmuch binary with a call to notmuch
39 over ssh.
40 2.  sets up a running, detached, ssh connection to the server, so that
41 future calls can reuse the socket.
42
43     #!/usr/bin/env bash
44     
45     SSH_BIN="ssh"
46     USER="example_user"
47     SSH_HOST="example.com"
48     SSH_SOCKET="/tmp/notmuch_ssh.socket"
49     NOTMUCH_REMOTE_BIN="notmuch"
50     DTACH="dtach"
51     DTACH_SOCKET="/tmp/notmuch_dtach.socket"
52     
53     check_for_socket ()
54     {
55         [ -S "${SSH_SOCKET}" ]
56     }
57     
58     check_if_socket_alive ()
59     {
60         timeout 1 $SSH_BIN -S ${SSH_SOCKET} $USER@$SSH_HOST true > /dev/null
61     }
62     
63     start_socket ()
64     {
65         dtach_command="${DTACH} -n ${DTACH_SOCKET} ${SSH_BIN} -M -S ${SSH_SOCKET} ${USER}@${SSH_HOST}"
66         command -v ${DTACH} &>/dev/null && ${dtach_command} || 
67         echo "${DTACH} not installed"
68     }
69     
70     notmuch_run ()
71     {
72         check_for_socket || start_socket
73         CMD=$1
74         shift
75         printf -v ARGS "%q " "$@"
76         $SSH_BIN -S $SSH_SOCKET $USER@$SSH_HOST $NOTMUCH_REMOTE_BIN ${CMD} ${ARGS}
77     }
78     
79     notmuch_run $@
80
81         
82 Save this to a file, "remote-notmuch.sh", in your path.
83
84 Now you can run "remote-notmuch.sh new". You can call the script
85 anything you like. I actually have $HOME/bin/notmuch linked to that
86 script, so I can have transparent
87 usage. 
88
89 ##Configure your emacs client##
90
91 The only thing you need to do is tell your emacs client to use the
92 script. Add the following to your .emacs (this is on your client
93 machine):
94
95     (setq notmuch-command "/path/to/your/remote-notmuch.sh")
96
97 ##Problems##
98 Some things probably won't work perfectly, and there might be some unexpected
99 mismatches between normal usage and this sort of usage. If you're
100 using this approach and run into any problems, please feel free to
101 list them here. And, of course, if you improve on any of these
102 approaches, please do edit this page and let people know!