Skip to content

Instantly share code, notes, and snippets.

@Muuo
Created January 1, 2017 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Muuo/b202f3d0861432128b2ac6a331d01fdf to your computer and use it in GitHub Desktop.
Save Muuo/b202f3d0861432128b2ac6a331d01fdf to your computer and use it in GitHub Desktop.
A simple script that lets me edit timestamped files in Vim
#!/bin/sh
numargs=$#
t='today'
secFlag=''
editPath='.'
pos=1
while getopts ':sd' flag; do
case "${flag}" in
# Secure the note
s) secFlag='-x' ;;
# Save to the diary
d) editPath="$HOME/Documents/diary" ;;
\?) echo "Unexpected option: -$OPTARG"; exit 1;;
esac
pos=$OPTIND;
done
function join_by { local IFS="$1"; shift; echo "$*"; }
if [ "$pos" -le "$numargs" ]
then
t=$( join_by ' ' ${@:pos:((numargs-pos+1))} )
fi
vim $secFlag $editPath/$(date -I --date "$t").txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment