Skip to content

Instantly share code, notes, and snippets.

@heywoodlh
Created May 13, 2022 16:05
Show Gist options
  • Save heywoodlh/ecf518b57db2b4d4f4627661d6e9fb1c to your computer and use it in GitHub Desktop.
Save heywoodlh/ecf518b57db2b4d4f4627661d6e9fb1c to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
## Personal log script. Assumes the following:
### - All logs will be placed in the same directory (set with journal_dir environment variable)
### - Logs will organized in directories by year, month, day (i.e. 2020/Nov/25.txt)
### - Password-store will be used to encrypt and edit files (default $EDITOR will be used)
## Script assumes that all logs will be placed in the same root directory
if [[ -n $log_dir ]]
then
root_dir="$log_dir"
else
root_dir="$HOME/log"
fi
## Figure out if user wants to read, write, edit or cancel
action="$(printf "read\nwrite\nedit\ncancel" | fzf)"
if [[ "$action" == "cancel" ]]
then
exit 0
fi
## Read in log
if [[ "$action" == "read" ]]
then
target="$root_dir/"
selection=$(cd $target && find -L . -name '*.gpg' | sed -e 's/.\///' -e 's/.gpg//' | sort -t '/' -k 1,1 -k 2M | fzf --tac --no-sort)
PASSWORD_STORE_DIR="$root_dir" pass "$selection" | less
fi
## Write in log
if [[ "$action" == "write" ]]
then
target="$root_dir"
year=$(date +%Y)
month=$(date +%h)
day=$(date +%d)
PASSWORD_STORE_DIR="$root_dir" pass edit "$year/$month/$day.md"
fi
## Edit log entry
if [[ "$action" == "edit" ]]
then
target="$root_dir"
selection=$(cd $target && find -L . -name '*.gpg' | sed -e 's/.\///' -e 's/.gpg//' | sort -t '/' -k 1,1 -k 2M | fzf --tac --no-sort)
PASSWORD_STORE_DIR="$root_dir" pass edit "$selection"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment