-
-
Save smeghead/973208 to your computer and use it in GitHub Desktop.
Attendance memo tool.
This file contains hidden or 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 | |
########################################################### | |
# | |
# 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