dotfiles/.config/shell/functions/todo
PowerUser64 06ab216290 zsh: realized some things need to be functions
By that, I mean things that change my working directory need to be
functions
2022-01-01 18:24:20 -08:00

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
}