aboutsummaryrefslogblamecommitdiff
path: root/bin/td
blob: e6cbfd93e43b3c57f5311622c3d3774bc0776e42 (plain) (tree)
1
2
3
4
5
6
7
8
9


                                                 
                           

                               

                                           
                                           



                           
                                                                    
                                      
                                          
          
  
                        

                                                
                                          
 
                                                                           
                                    




                                             

                                               
#!/bin/sh
# Manage to-do files with just $EDITOR and git(1)

# Specify the path and file
dir=${TODO_DIR:-"$HOME"/Todo}
file=${1:-"${TODO_NAME:-todo}"}

# 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 -v isgr >/dev/null ; then
    printf >&2 'isgr: command not found\n'
    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