#!/bin/bash # Source this and then run `todo` # a simple way to manage your todo list # Usage: # todo -- pull latest repo version and edit ~/todo # todo [any git command] -- manage todo for easy syncing, assuming ~/todo is # a symlink that points to a file in a git repo # # Suggested use: make a git repo for holding your todo list, then make # a symlink called 'todo' that points to your todo list in your home directory # todo() { todo_dir="$(dirname "$(realpath ~/todo)")" todo_file="$(realpath ~/todo)" if [ -z "$*" ];then ( # subshell to protect against directory changes cd "$todo_dir" || return # pull the latest commits git rev-parse && git pull # open the file "$EDITOR" "$todo_file" # commit and push the file if it's in a git repo and the file has changed if git rev-parse && ! git diff --exit-code "$todo_file"; then git commit "$todo_file" -m 'todo' && git push fi ) elif [ "$*" = "cd" ]; then cd "$todo_dir" || return else git -C "$todo_dir" $@ fi }