Last active
January 2, 2016 12:09
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Steve Traylen <[email protected]> , 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