Created
January 1, 2017 00:51
-
-
Save Muuo/b202f3d0861432128b2ac6a331d01fdf to your computer and use it in GitHub Desktop.
A simple script that lets me edit timestamped files in Vim
This file contains hidden or 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
#!/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