dotfiles/zsh/modules/bin/todo_sync
James Patrick 94252d74b9 Added todo_sync script.
This will move/link/create project todo.org to git repo.
2021-02-17 23:45:39 -05:00

37 lines
743 B
Bash
Executable File

#! /usr/bin/env bash
GIT_ROOT=$(git root 2> /dev/null)
if [ -z "${GIT_ROOT}" ]; then
echo "Not in a git repo. Aborting."
exit 1
fi
if [[ -L ${GIT_ROOT}/todo.org ]] ; then
echo "Sym link already exist here."
exit 1
fi
if [[ ! -d ${HOME}/org/projects ]]; then
echo "No directory at \${HOME}/org/projects"
exit 1
fi
REPO_NAME=${GIT_ROOT##*/}
TODO_ORG="${HOME}/org/projects/${REPO_NAME}.org"
TODO_REPO="${GIT_ROOT}/todo.org"
if [[ -e ${TODO_ORG} ]] && [[ -e ${TODO_REPO} ]] ; then
echo "Both todo.org and ${REPO_NAME}.org already exist."
exit 1;
fi
if [[ -e "${TODO_REPO}" ]] ; then
echo "Moving exist todo.org to ~/org"
mv "${TODO_REPO}" "${TODO_ORG}"
else
touch "${TODO_ORG}"
fi
ln -vs "${TODO_ORG}" "${TODO_REPO}"