aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-02-15 16:47:16 +1300
committerTom Ryder <tom@sanctum.geek.nz>2016-02-15 16:47:16 +1300
commit509b3d57668a819efe1a57ad48e7eec938689ea0 (patch)
tree74458ff9b50260cc47e48d49ea1da54506438199 /bin
parentA few more comments (diff)
downloaddotfiles-509b3d57668a819efe1a57ad48e7eec938689ea0.tar.gz
dotfiles-509b3d57668a819efe1a57ad48e7eec938689ea0.zip
Discard Taskwarrior, replace with td(1)
Diffstat (limited to 'bin')
-rwxr-xr-xbin/td56
1 files changed, 56 insertions, 0 deletions
diff --git a/bin/td b/bin/td
new file mode 100755
index 00000000..1c8828d2
--- /dev/null
+++ b/bin/td
@@ -0,0 +1,56 @@
+#!/usr/bin/env bash
+
+#
+# td(1) -- Manage a to-do file with just $EDITOR and git(1), because I've
+# completely given up on finding a more useful way to do it.
+#
+# Author: Tom Ryder <tom@sanctum.geek.nz>
+# Copyright: 2016
+# License: Public domain
+#
+self=td
+
+# Specify the path to the file; you can override this with a $TODO environment
+# variable
+path=${TODO:-$HOME/Todo/todo.markdown}
+file=${path##*/}
+dir=${path%/*}
+
+# If the directory doesn't exist, create it
+if [[ ! -d $dir ]] ; then
+ mkdir -p -- "$dir" || exit
+fi
+
+# Change into the directory
+cd -- "$dir" || exit
+
+# Quick function to determine if a directory is a Git repository
+isrepo() {
+ { git symbolic-ref --quiet HEAD || \
+ git rev-parse --short HEAD
+ } >/dev/null 2>&1
+}
+
+# If the current directory isn't a Git repository, try to create one
+if ! isrepo ; then
+ git init || exit
+fi
+
+# If the to-do file doesn't exist yet, create it
+if ! [[ -e $file ]] ; then
+ touch -- "$file" || exit
+fi
+
+# Launch $VISUAL (or $EDITOR (or vi(1))), with any arguments given as options,
+# to edit the to-do file
+"${VISUAL:-${EDITOR:-vi}}" "$@" "$file"
+
+# Add the file to the changeset
+git add -- "$file"
+
+# If there are changes to commit, commit them
+message=$(printf 'Changed by %s(1)' "$self")
+if ! git diff-index --quiet HEAD ; then
+ git commit --message "$message" --quiet
+fi
+