dotfiles

personal configuration files and scripts
git clone https://tongong.net/git/dotfiles.git
Log | Files | Refs | README

diary-edit (626B)


      1 #!/bin/bash
      2 GPG_KEYID=${DIARY_KEYID:-"83BB96DF"}
      3 EDITOR=${DIARY_EDITOR:-"vi"}
      4 
      5 FILE="$1"
      6 [[ -n "$FILE" ]] || FILE=$(diary-list)
      7 if [[ -z "$FILE" ]]; then
      8     echo "file not found!"
      9     exit 1
     10 fi
     11 tmp=$(mktemp /dev/shm/diary.XXXXXXXXXX)
     12 # save every draft
     13 # fswatch -0 "$tmp" | xargs -0 -n 1 -I {} gpg --output "$1.tmp" --encrypt --armor --recipient "$GPG_KEYID" --yes --quiet "$tmp"  &
     14 # FSWATCH_PID=$!
     15 
     16 # decrypt, edit, encrypt
     17 gpg --decrypt --output "$tmp" --yes --quiet "$FILE" && \
     18 $EDITOR "$tmp"
     19 gpg --output "$FILE" --encrypt --armor --recipient "$GPG_KEYID" --yes --quiet "$tmp"
     20 
     21 # cleanup
     22 # kill $FSWATCH_PID
     23 rm "$tmp"