38 lines
1.1 KiB
Bash
38 lines
1.1 KiB
Bash
#!/bin/bash
|
|
|
|
# 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" || exit
|
|
|
|
# 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" || exit
|
|
else
|
|
git -C "$todo_dir" $@
|
|
fi
|
|
}
|