Epistle Linker for Dropbox on Linux
I've been using Epistle for writing
on my Android devices and while I adore the software there are a
couple of significant limitations. Notably that all files need to be
in one directory with no hierarchy and that all files need to have
.txt extensions. I have pretty good file organization in a number of
git repositories, and I don't use the .txt extension at all. hile
Epistle is great, I needed a way to integrate it with my current
system without causing a nightmare.
Luckily the command line Linux dropbox program recognizes symbolic links, so you can link to a file (that exists outside of the dropbox, in a git repository) and the sync will work. So that this can all make sense, I've made sure that the symbolic links will begin with a "tag" that identifies their context in the Epistle interface, which makes everything easier to track.
#!/bin/zsh
# usage: dbl [source-directory] [file-tag]
EPISTLEDIR=~/Dropbox/epistle/
LISTFILE=00-link-list.txt
files=`find $1 -maxdepth 1 -type f \( ! -iname ".*" \)`
for i in $files; do
filename=`echo $i | awk -F/ '{print $NF} '`
linkfilename=`echo $filename | sed "s/mdwn/txt/
s/md/txt/
s/mdn/txt/
s/org/txt/
s/rst/txt/
s/text/txt/"`
ln -s $i ~/Dropbox/epistle/$2-$linkfilename
done
list-file(){
rm $EPISTLEDIR$LISTFILE
touch $EPISTLEDIR$LISTFILE
echo "# Link List for Epistle Notes" >> $EPISTLEDIR$LISTFILE
echo >> $EPISTLEDIR$LISTFILE
IFS=$'\n'
for link in `ls --color=never -lha $EPISTLEDIR | cut -d " " -f 11-13`; do
echo "- $link" >> $EPISTLEDIR$LISTFILE
done
sed -i "/- 00-link-list.txt/d" $EPISTLEDIR$LISTFILE
}
list-file
Notes
There's no error checking on the command arguments so it's possible to break things. Luckily, the worst that can happen is you'll create weird links that you can just delete, and move on from there.
This is a
zshscript, but my brain wrote it inbashI just tested it withzshso you should be able to use other shells, but I just wanted to be safe.The sed script to change the file extension is simple and probably not adaptive if you're using a kind of file that I haven't foreseen. It would be better to chop off everything after the final
.character and append .txt to the link names, but myawkskills are minimal.When the file is updated on the Dropbox side, dropbox will often (always?) replace the link with a copy of the file. Apparently this isn't the case with whole directories, but this doesn't fix the extension issue.
The solution to this problem is to improve the way Dropbox handles plain text files (i.e. opening the file handle and writing the changes,) but this would probably represent a substantial change in approach for the Dropbox application.
As an alternative, this script could be augmented (or rewritten) to do the sync in the reverse so that: it would track where files originated from (in a machine parse-able format) and a checksum of the original file, if it detected a file where a symlink ought to be it would check to see if the original file changes. If the original file didn't change, it would copy the new file over the original file (with the original name,) and recreate the symlink. If the file had changed in the original, it would email you a notification.