Skip to content

Instantly share code, notes, and snippets.

@lamberta
Created October 27, 2009 21:29
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lamberta/219976 to your computer and use it in GitHub Desktop.
Save lamberta/219976 to your computer and use it in GitHub Desktop.
using a git repo as a todo list
;;add to your .emacs
(defun git-commit-file-and-push (&optional commit-msg)
"Commit current file and push to git repository."
(interactive)
(if (null commit-msg)
(setq commit-msg (read-from-minibuffer "Commit message: ")))
(if (buffer-modified-p (current-buffer))
(if (y-or-n-p "Save modified buffer? ")
(save-buffer)))
(let ((file (buffer-file-name (current-buffer)))
(git (lambda (command error-msg)
;;run git command and check return status
(if (not (eq 0 (shell-command (concat "git " command))))
(error "Git: %s" error-msg)))))
;;run git commands
(funcall git (concat "add " file) "Unable to add file")
(let ((commit (concat "commit -q -m '" commit-msg "'")))
(funcall git commit "Nothing to commit"))
(funcall git "push origin" "Unable to update repository")
(message "Git: Pushed %s to master" file)))
;;key-binding to auto-update with a default commit message
;;using todo-list-mode:
;;http://github.com/biilly/scripts/blob/master/emacs/lisp/todo-list-mode.el
(add-hook 'todo-list-mode-hook
'(lambda ()
(local-set-key (kbd "C-x p")
(lambda () (interactive)
(git-commit-file-and-push "updated from emacs")))))
* Abstract
Using a remote git repository as a version controlled todo list.
There are two problems with using a local text file as a todo list,
remote access and continuity. Hosting the file on a server introduces
a number of sync issues along with restricting access to an internet
connection. Marking items off your todo list deletes them forever,
making retrieval of previous task details unavailable without some
kind of backup system in place.
This example uses git's decentralized version control capabilities to
manage a todo list that provides backup, retrieval, remote access, and
that is easily synchronized across multiple machines. It uses git,
github.com and some emacs lisp for easy integration.
* Create a new git repository
After signing up for a GitHub account, create a new 'gist' at
http://gist.github.com/ Copy your current todo list into the file
section and create a private gist. Copy the url from the
'Private Clone URL' and enter it at the command line. This will
download your todo list into the todo-list directory:
$ git clone git@gist.github.com:4f5fd685937c0c946f82.git todo-list
* Update file
Modify the todo list as needed, when finished execute the following
git commands in your repository to update the remote file:
$ git add .
$ git commit -m 'my commit message'
$ git push origin
Go back to your github gist and the file should now be synchronized with
your local todo list. Clicking through the revisions on the right will allow
you to see older versions of your list.
* Make it convenient
By putting the below code in your .emacs file you can automate the git
commands to a single key-stroke and without leaving Emacs.
Since github requires authentication you may need to run 'ssh-add' to
add your public key. See man page for details.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment