Various shell scripts for use on the RTC server. Not your official RTC stuff!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

41 lines
1.1 KiB

#! /bin/bash
#
# jot - distributed note-taker
# Syntax:
# jot
# - read latest entries
# jot /string
# - look for entries containing 'string'
# jot something noteworthy
# jot "something noteworthy with #tag1 #tag2 #tag3"
# - take note
#
readonly JOTFILE="$HOME/.jot"
readonly PAT1='\/(.*)'
jot::printline () {
local D="$(date +"%s.%N")"
echo -e "${D:0:18}\t$*"
}
jot::write() {
jot::printline "$*" >> $JOTFILE || { echo "Cannot write $JOTFILE" > /dev/tty ; exit 1; }
chmod 0644 $JOTFILE
}
jot::read () {
local SENDER
for d in /home/*/.jot ; do
SENDER="${d##/home/}"
SENDER="${SENDER%%/.jot}"
if [[ "$1" =~ $PAT1 ]]; then
[ -r "$d" ] && egrep -e "${BASH_REMATCH[1]}" $d | awk 'BEGIN{FS="\t"}{printf("%s \x1b[1m%-14.14s\x1b[0m %s\n",strftime("%Y-%m-%d %H:%M:%S",$1),"'${SENDER:-"..."}'",$2)}'
else
[ -r "$d" ] && tail -20 $d | awk 'BEGIN{FS="\t"}{printf("%s \x1b[1m%-14.14s\x1b[0m %s\n",strftime("%Y-%m-%d %H:%M:%S",$1),"'${SENDER:-"..."}'",$2)}'
fi
done | sort -nr
}
[[ -z "$@" ]] && jot::read && exit 0
[[ "$1" =~ $PAT1 ]] && jot::read "$@" && exit 0
jot::write "$@"