Simple Command-Line Diet Log Script

Extremely simple diet logging from your terminal to stay conscious of what you eat.


~/.functions

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function da () {
local LOG_DIR=~/.diet
if [ -d $LOG_DIR ]; then
mkdir -p $LOG_DIR
fi

local LOG_FILE=$LOG_DIR/`date +"%Y-%m-%d"`

if [ $# -eq 1 ]; then
echo `date +"%H:%M"`" -- $1" >> $LOG_FILE
elif [ $# -eq 2 ]; then
echo "$1 -- $2" >> $LOG_FILE
fi
}

function ds () {
local LOG_DIR=~/.diet

if [ $# -eq 0 ]; then
local LOG_FILE=$LOG_DIR/`date +"%Y-%m-%d"`
cat $LOG_FILE
elif [ $# -eq 1 ]; then
for f in $LOG_DIR/*; do
echo `basename $f`
cat $f
done
fi
}

Usage

1
2
3
da "10:00" "muesli"
da "pizza"
ds