-
-
Save sridatta/9027573 to your computer and use it in GitHub Desktop.
A simple file-based task manager in Bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ -z $TASK_DIR ]; then | |
TASK_DIR=$HOME/tasks | |
fi | |
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
Have you considered replacing lines 58 onward with:
Variables in command names are pretty universally supported by shells; I learned this dispatching trick from
git-submodule.sh
, and git's coding guidelines are explicitly very stringent about cross-compat.