Skip to content

Instantly share code, notes, and snippets.

/priv

Created Sep 3, 2014
Embed
What would you like to do?
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