Skip to content

Instantly share code, notes, and snippets.

@smeghead
Forked from fukata/atnd
Created May 15, 2011 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smeghead/973208 to your computer and use it in GitHub Desktop.
Save smeghead/973208 to your computer and use it in GitHub Desktop.
Attendance memo tool.
#!/bin/bash
###########################################################
#
# Clone repo:
# git clone git://gist.github.com/973208.git attendance
#
# Edit your .bashrc
# export ATND_TOOL=/home/fukata/usr/local/attendance
# export PATH=$PATH:$ATND_TOOL
#
# Reload .bashrc:
# source ~/.bashrc
#
# Usage:
# atnd msg
#
###########################################################
# Basic Settings
BASEDIR=$(dirname $0)
PGNAME=$(basename $0)
# Database
DB_NAME="$BASEDIR/$PGNAME.db"
CMD_CONNECT="sqlite3 $DB_NAME"
function exec_sql() {
local sql=${1?"SQL is required."}
echo "$sql" | $CMD_CONNECT
}
function create_atnd() {
local msg=${1?"Message is required."}
msg=${msg/\'/\'\'}
local sql="INSERT INTO logs (msg, created_at) VALUES ('$msg', julianday('now'));"
exec_sql "$sql"
}
if [ ! -e $DB_NAME ]; then
exec_sql "CREATE TABLE logs ( \
id INTEGER PRIMARY KEY, \
msg TEXT NOT NULL, \
created_at REAL NOT NULL);"
fi
create_atnd $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment