[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] Advice needed: Cant find a decent way to autosync my work TODO o
From: |
Richard Lawrence |
Subject: |
Re: [O] Advice needed: Cant find a decent way to autosync my work TODO org file between laptop and work pc |
Date: |
Sat, 24 May 2014 09:49:41 -0700 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) |
Hi Xebar,
Xebar Saram <address@hidden> writes:
> i mainly used git over the last 6 months but that forces me to
> pull/commit/push manually each time i add something to either machine and
> that is really annoying. plus i get merge conflicts all the time
>
> I have tried dropbox at the past but again this causes conflicts,
> isntreliable to me (on my
> linux laptop it doesn't always resume sync after sleep)
If neither git nor Dropbox works for you, I'm not sure this will be
helpful, but...
I personally use git for this. To keep the effort of syncing and
merging low, I have a cron job set up to automatically commit in certain
repositories containing my Org files every hour. It's just a
quick-and-dirty hack, but here it is:
#+BEGIN_SRC bash
#!/bin/bash
# Add org file changes to the repository
ROOT=$HOME
REPOS="org Documents/philosophy/dissertation Documents/philosophy/teaching
Documents/philosophy/reading src/emacs"
commit_and_push()
{
for REPO in $REPOS
do
echo "Repository: $ROOT/$REPO"
cd $ROOT/$REPO
if [ ! -d .git ]; then
echo "Not a git repository; skipping"
continue
fi
if [ ! -r autocommits ]; then
echo "No autocommits file found; skipping"
continue
fi
# Remove deleted files
git ls-files --deleted -z | xargs -0 git rm >/dev/null 2>&1
# Add files on whitelist to commit for current branch
while read FILE
do
git add $FILE
done < autocommits
git commit -m "$(date) from $(hostname) by autocommit.sh"
STATUS=$?
if [ $STATUS != 0 ]; then
echo "git commit failed with exit status $STATUS"
fi
# Push the current branch
# requires branch.<name>.remote to be specified in git config
# and ideally push.default = tracking
git push --porcelain
STATUS=$?
if [ $STATUS != 0 ]; then
echo "git push failed with exit status $STATUS"
fi
done
}
pull()
{
for REPO in $REPOS
do
echo "Repository: $REPO"
cd $ROOT/$REPO
git status | grep 'modified:'
if [ $? == 0 ]; then
echo "modified files present; fetching, but not pulling."
CMD="fetch"
else
CMD="pull"
fi
git $CMD
STATUS=$?
if [ $STATUS != 0 ]; then
echo "git $CMD failed with exit status $STATUS"
fi
done
}
case "$1" in
commit)
commit_and_push
;;
pull)
pull
;;
*)
echo "Usage: $0 {commit|pull}"
exit 1
;;
esac
exit 0
#+END_SRC
This script requires a file called "autocommits" in each repository in
$REPOS which is a whitelist of files to autocommit changes in. Most of
my Org files are on such a list.
I run this from Cron like:
#+BEGIN_SRC cron
0 * * * * ~/bin/autocommits.sh commit >/dev/null 2>&1
#+END_SRC
To make sure my changes are saved before this script runs, I have in my .emacs:
#+BEGIN_SRC elisp
(run-at-time "00:59" 3600 'org-save-all-org-buffers) ; cron commits on the hour
(add-hook 'before-save-hook 'org-update-all-dblocks)
#+END_SRC
And finally, to pull the autocommitted changes on a new machine:
$ autocommits.sh pull
So you still have to manually pull and fix any merge conflicts, but I
find that committing often generally keeps the work involved here
minimal (because I can't usually work on two machines at once!).
Hope that helps!
Best,
Richard
Re: [O] Advice needed: Cant find a decent way to autosync my work TODO org file between laptop and work pc, Ken Mankoff, 2014/05/24
Re: [O] Advice needed: Cant find a decent way to autosync my work TODO org file between laptop and work pc, Josh Berry, 2014/05/25
Re: [O] Advice needed: Cant find a decent way to autosync my work TODO org file between laptop and work pc, Thierry Banel, 2014/05/26