Created
November 4, 2009 15:58
-
-
Save rkumar/226149 to your computer and use it in GitHub Desktop.
shell script template, fairly comprehensive program
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/bash | |
#*******************************************************# | |
# Shell script template # | |
# # | |
# Arunachalesha # | |
# $Id$ # | |
#*******************************************************# | |
# if running as a cronjob prepend /opt/local/bin:/opt/local/sbin | |
# export PATH="/opt/local/bin:/opt/local/sbin:$PATH:/Users/rahul/bin" | |
# also cd in the folder you want. | |
# cd /Users/rahul/bin | |
#### --- cleanup code use at start ---- #### | |
# TMP_FILE=${TMPDIR:-/tmp}/prog.$$ | |
# trap "rm -f $TMP_FILE.?; exit 1" 0 1 2 3 13 15 | |
# at end of prog | |
#rm -f $TMP_FILE.? | |
#trap 0 | |
#exit 0 | |
PROG_SH=$(basename "$0") | |
export PROG_SH | |
#ext=${1:-"default value"} | |
#today=$(date +"%Y-%m-%d-%H%M") | |
oneline_usage="$PROG_SH [-fhpantvV] [-d todo_config] action [task_number] [task_description]" | |
usage() | |
{ | |
sed -e 's/^ //' <<EndUsage | |
Usage: $oneline_usage | |
Try '$PROG_SH -h' for more information. | |
EndUsage | |
exit 1 | |
} | |
help() | |
{ | |
sed -e 's/^ //' <<EndHelp | |
Usage: $oneline_usage | |
Actions: | |
add "THING I NEED TO DO +project @context" | |
a "THING I NEED TO DO +project @context" | |
Adds THING I NEED TO DO to your todo.txt file on its own line. | |
Project and context notation optional. | |
Quotes optional. | |
addto DEST "TEXT TO ADD" | |
See "help" for more details. | |
EndHelp | |
exit 0 | |
} | |
die() | |
{ | |
echo "$*" | |
exit 1 | |
} | |
cleanup() | |
{ | |
[ -f "$TMP_FILE" ] && rm "$TMP_FILE" | |
exit 0 | |
} | |
vflag=0 | |
out= | |
file= | |
Dflag= | |
while getopts hvVf:o:D: flag | |
do | |
case "$flag" in | |
(h) help; exit 0;; | |
(V) echo "$arg0: version $Revision$ ($Date$)"; exit 0;; | |
(v) vflag=1;; | |
(f) file="$OPTARG";; | |
(o) out="$OPTARG";; | |
(D) Dflag="$Dflag $OPTARG";; | |
(*) usage;; | |
esac | |
done | |
shift $(($OPTIND - 1)) | |
[ $# -eq 0 ] && { | |
exit 0; | |
} | |
action=$( printf "%s\n" "$1" | tr 'A-Z' 'a-z' ) | |
shift | |
case $action in | |
"add" | "a") | |
echo "action is $action" | |
echo "left is $*" | |
cleanup;; | |
"del" | "rm") | |
echo "action is $action" | |
echo "left is $*" | |
cleanup;; | |
"move" | "mv") | |
echo "action is $action" | |
echo "left is $*" | |
cleanup;; | |
"list" | "ls") | |
echo "action is $action" | |
echo "left is $*" | |
cleanup;; | |
* ) | |
usage | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment