summaryrefslogtreecommitdiff
path: root/journal.sh
blob: 903440ffb1e2bb92d53d01deefa3cc87f660166e (plain)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env zsh

set_dates() {
  nowtime=$(gdate "+%H:%M") || exit
  day=$(gdate "+%A" -d "$*") || exit
  daynum=$(gdate "+%e" -d "$*") || exit
  month=$(gdate "+%m" -d "$*") || exit
  year=$(gdate "+%Y" -d "$*") || exit
  date=$(gdate "+%Y-%m-%d" -d "$*") || exit

  date_path=$(gdate "+%Y/%m" -d "$*") || exit
  journal_prefix=~/code/txt/cal
  file="$journal_prefix/$date_path/$date.txt"
}

change_status="Edited"

for arg in $@
case "$arg" in
  show)
    shift
    set_dates $*
    if [ ! -f "$file" ]; then
      printf "journal entry for $date not found.\n"
      exit 1;
    fi
    
    if [[ $(wc -l < $file) -le $["$LINES" - 20] ]]; then
      cat "$file"
    else
      $PAGER "$file"
    fi


    exit 0
esac

set_dates $*
cd "$journal_prefix"

#setup header
if [ ! -f "$file" ]; then
  mkdir -p $(dirname "$file") 2> /dev/null

  printf "%0.s=" {1..13} >> $file
  printf "\n" >> $file
  cal -h "$month" "$year" | gsed "0,/$daynum/{s//XX/}" >> $file
  truncate -s -1 $file
  
  printf "\n$day\n" >> $file
  printf "%0.s=" {1..13} >> $file
  printf "\n" >> $file

  change_status="Created" 
fi

if ! grep -xq "$nowtime" "$file"; then
  printf "\n* At $nowtime\n" >> $file
fi

$EDITOR $file

stty sane
printf "Save in git? [Y|n]: "
read yn
case $yn in
  Y|y| )
   git add "$file"
   git commit -S -m "$change_status entry for $date at $nowtime" -m "$(randomart.py --ascii "$file")" 
esac