-
-
Save JohnB/6432538 to your computer and use it in GitHub Desktop.
Added location, updated link to the access-os-x-keychain-from-terminal blog post and added some explanatory text.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Canonical location: https://gist.github.com/kljensen/4434992 | |
########################################################## | |
# | |
# This is a shell script for keeping a journal that is | |
# * plaintext, | |
# * time-stamped, | |
# * encrypted, and | |
# * edited with vim. | |
# | |
# I find it convenient because it | |
# * pulls the encryption key from OSX's KeyChain; | |
# * is easily launched from the shell; and, | |
# * can be stored in Dropbox. | |
# | |
# This is inspired by | |
# * Manuel Ebert's jrnl: https://github.com/maebert/jrnl, and | |
# * Sam Beam's post: http://chirp.syxyz.net/2011/06/keep-it-safe-with-blowfish-in-vim-7-3/ | |
# | |
# To run this you will need: | |
# * bash, | |
# * expect, | |
# * vim 7.3+, and, | |
# * an "internet password" KeyChain item with 'Where' set to "ftp://vim-journal" | |
# see http://www.frommknecht.net/2010/02/access-os-x-keychain-from-terminal/ | |
# (it won't really be used on the internet but that is one of the styles of passwords | |
# that KeyChain stores and that we will be looking for in the script below) | |
# | |
# All those dependencies are included by default in | |
# recent versions of OSX. | |
# | |
# License: BSD 2-Clause. See bottom. | |
# | |
########################################################## | |
# Turn off shell echo | |
# | |
set +o verbose | |
# Path to your journal. I keep mine in Dropbox. | |
# | |
JOURNAL_PATH="$HOME/Dropbox/journal.txt" | |
# Set KeyChain Item Name. This corresponds | |
# to a name of ftp://vim-journal | |
# | |
KEYCHAIN_ITEM="vim-journal" | |
# Get password from OSX Keychain | |
# | |
PW=`security 2>&1 >/dev/null find-internet-password -gs vim-journal | cut -d '"' -f 2` | |
if [[ "$PW" == *"could not be found"* || "$PW" == "password: " ]] | |
then | |
echo "vj.sh problem: No encryption password for $KEYCHAIN_ITEM in your KeyChain"; | |
return | |
fi | |
# Get the date | |
# | |
DATE=`date` | |
# Run vim inside expect | |
# | |
# Vim is started as described here | |
# http://chirp.syxyz.net/2011/06/keep-it-safe-with-blowfish-in-vim-7-3/ | |
# | |
# The output of 'interact' is captured and supressed so as not to echo | |
# the encryption password. | |
# | |
# I put some '##' signs before the date, which is Markdown format. | |
# You can, of course, do whatever. The \u001b puts vim back in edit | |
# mode before turning over control to the user via "interact". | |
# | |
expect -c " | |
spawn -noecho vim -nx --cmd \"set viminfo=\\\"\\\"\" --cmd \"set cryptmethod=blowfish\" $JOURNAL_PATH | |
expect -re \".+\" { | |
send \"$PW\r\" | |
send \"$PW\r\" | |
send \"Go\n\n## $DATE\n\n\u001b\" | |
interact | |
}" | |
# Copyright (c) 2013, Kyle Jensen | |
# All rights reserved. | |
# Redistribution and use in source and binary forms, with or | |
# without modification, are permitted provided that the | |
# following conditions are met: | |
# Redistributions of source code must retain the above | |
# copyright notice, this list of conditions and the following | |
# disclaimer. | |
# Redistributions in binary form must reproduce the above | |
# copyright notice, this list of conditions and the following | |
# disclaimer in the documentation and/or other materials | |
# provided with the distribution. | |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |
# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE | |
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR | |
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
# POSSIBILITY OF SUCH DAMAGE. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment