blob: 18bcfde4a1a9030bd8e03a51167783925c360671 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#!/bin/sh
# Manage to-do files with just $EDITOR and git(1)
# Specify the path to the file
dir=${TODO_DIR:-$HOME/Todo}
file=${1:-${TODO_NAME:-todo}}
path="$dir"/"$file"
# If the directory doesn't exist, create it
[ -d "$dir" ] || mkdir -p -- "$dir" || exit
# Change into the directory
cd -- "$dir" || exit
# If the current directory isn't a Git repository, try to create one
if ! command isgr >/dev/null ; then
printf >&2 'isgr: command not found'
exit 1
fi
isgr || git init || exit
# If the to-do file doesn't exist yet, create it
[ -e "$file" ] || touch -- "$file" || exit
# Launch $VISUAL (or $EDITOR (or vi(1))) to edit the appropriate to-do file
"${VISUAL:-${EDITOR:-vi}}" "$file"
# Add the file to the changeset
git add -- "$file"
# If there are changes to commit, commit them
git diff-index --quiet HEAD ||
git commit --message 'Changed by td(1)' --quiet
|