Skip to content

Instantly share code, notes, and snippets.

/priv

Created September 3, 2014 22:39
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/df1ba398dd4e4748c6cd to your computer and use it in GitHub Desktop.
Save anonymous/df1ba398dd4e4748c6cd to your computer and use it in GitHub Desktop.
My journal
#!/bin/bash
gpg_id='my@email.address.ca'
inv_dir="$HOME/.priv"
gpg_cmd='gpg'
edit_cmd='emacs'
pager_cmd='less'
if [ $# -ge 2 ]; then
op=$1
file=$2
elif [ $# -ge 1 ]; then
op=$1
file=$(date '+%d-%b-%Y-%a.txt')
else
op='create'
file=$(date '+%d-%b-%Y-%a.txt')
fi
if [ "${file:(-4)}" == '.gpg' ]; then
enc_file="$file"
file="${file:0:$((${#file}-4))}"
else
enc_file="$file.gpg"
fi
case "$op" in
'create')
cd "$inv_dir"
umask 0077
"$edit_cmd" "$file"
"$gpg_cmd" -r "$gpg_id" -o "$enc_file" -e "$file"
rm "$file"
;;
'edit')
cd "$inv_dir"
umask 0077
"$gpg_cmd" -o "$file" -d "$enc_file"
"$edit_cmd" "$file"
"$gpg_cmd" -r "$gpg_id" -o "$enc_file" -e "$file"
rm "$file"
;;
'view')
cd "$inv_dir"
umask 0077
"$gpg_cmd" -o "$file" -d "$enc_file"
"$pager_cmd" "$file"
rm "$file"
;;
*)
echo "usage: $0 [create] [filename]"
echo " $0 edit [filename]"
echo " $0 view [filename]"
exit
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment