Skip to content

Instantly share code, notes, and snippets.

/task

Created February 16, 2014 00:48
Show Gist options
  • Save anonymous/9027570 to your computer and use it in GitHub Desktop.
Save anonymous/9027570 to your computer and use it in GitHub Desktop.
#!/bin/sh
TASK_DIR=$HOME/tasks
help () {
echo "Valid subcommands: create, ls, rm, cat, edit"
}
nth () {
ls $TASK_DIR | sed "$1q;d"
}
taskcreate () {
ESCAPE=$(printf "%q" $1)
FILENAME="${*}.txt"
touch "$TASK_DIR/$FILENAME"
}
taskls () {
ls $TASK_DIR | cat -n | sed "s/\..*//g"
}
taskrm () {
N=$1
if [ -z $N ] ; then
echo "** TASKS **"
taskls
read -p "Select a task number: " N
fi
F=$(nth $N)
rm "$TASK_DIR/$F"
}
taskcat () {
N=$1
if [ -z $N ] ; then
echo "** TASKS **"
taskls
read -p "Select a task number: " N
fi
F=$(nth $N)
cat "$TASK_DIR/$F"
}
taskedit () {
N=$1
if [ -z $N ] ; then
echo "** TASKS **"
taskls
read -p "Select a task number: " N
fi
F=$(nth $N)
$EDITOR "$TASK_DIR/$F"
}
case $1 in
cat) taskcat $2
;;
rm) taskrm $2
;;
ls) taskls
;;
edit) taskedit $2
;;
create) taskcreate $2
;;
*) help
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment