Skip to content

Instantly share code, notes, and snippets.

@traylenator
Last active January 2, 2016 12:09
Show Gist options
  • Save traylenator/8301597 to your computer and use it in GitHub Desktop.
Save traylenator/8301597 to your computer and use it in GitHub Desktop.
# A small wrapper script for todo.sh[1] that uses Dropbox-Uploader # to pull and push files from dropbox before they are operated # on locally. # [1] https://github.com/ginatrapani/todo.txt-cli # [2] https://github.com/andreafabrizi/Dropbox-Uploader
#!/bin/bash
# Steve Traylen <steve.traylen@cern.ch> , 7th January 2014.
# A small wrapper script for todo.sh[1] that uses Dropbox-Uploader[2]
# to pull and push files from dropbox before they are operated
# on locally. If changes happen then the files are uploaded.
# The purpose of using this is it allows todo.sh cli to be used
# on a multiuser system where drop box cannot be installed
# in the normal fashion.
# To use install todo.sh cli as normal in ~/bin
# configure todo.sh to use ~/todo as it's location
# to maintain .txt files.
# Install dropbox uploader in to the DROPBOX_UPLOADER
# location below.
# Finally set up in ~/.bashrc or equivelent
# alias t='todo-wrapper.sh'
# [ -f $HOME/etc/todo_completion ] && . $HOME/etc/todo_completion
# complete -F _todo t
# [1] https://github.com/ginatrapani/todo.txt-cli
# [2] https://github.com/andreafabrizi/Dropbox-Uploader
# This is the maximum number of minutes for which potential
# changes made upstream will be ignored. In other words do not
# edit a task via your phone to dropbox and then add another
# task locally here with CACHE_MINUTES or else things will get lost.
# While it's possible to stat dropbox it takes at least a couple
# of seconds which is annoying.
CACHE_MINUTES=5
DROPBOX_UPLOADER="${HOME}/GIT/Dropbox-Uploader/dropbox_uploader.sh"
[ -x $DROPBOX_UPLOADER ] || exit
if [ "$( expr $(date +%s ) - $(stat -L --format %Y ~/todo/last-download ))" -gt "$(expr 60 \* ${CACHE_MINUTES})" ] ; then
${DROPBOX_UPLOADER} download todo ~ && touch ~/todo/last-download && touch ~/todo/last-upload
fi
~/bin/todo.sh $@
LAST_UPLOAD=$(stat -L --format %Y ~/todo/last-upload)
UPLOAD=false
for I in ~/todo/*txt*
do
if [ "$(stat -L --format %Y $I)" -gt $LAST_UPLOAD ] ; then
UPLOAD=true
${DROPBOX_UPLOADER} upload $I todo/$(basename $I)
fi
done
touch ~/todo/last-upload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment