From c9b000765edc3d2e5b92543812b3df4377ff9f3f Mon Sep 17 00:00:00 2001 From: PowerUser64 <blakelysnorth@gmail.com> Date: Tue, 21 Sep 2021 21:50:43 -0700 Subject: [PATCH] zsh: more enhancements to todo() --- .zshrc | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.zshrc b/.zshrc index b60cc65..06ad865 100644 --- a/.zshrc +++ b/.zshrc @@ -171,22 +171,24 @@ todo() { ( # subshell to protect against directory changes todo_dir="$(dirname "$(realpath ~/todo)")" + todo_file="$(realpath ~/todo)" if [ -z "$@" ];then - cd "$(dirname "$(realpath ~/todo)")" + cd "$todo_dir" # pull the latest commits git rev-parse && git pull - "$EDITOR" ~/todo + # open the file + "$EDITOR" "$todo_file" - # commit and push the file if it's in a git repo - git rev-parse && - git commit "$(realpath ~/todo)" -m 'todo' && + # 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 else - cd "$todo_dir" - git $@ + git -C "$todo_dir" $@ fi ) }