Skip to content

Instantly share code, notes, and snippets.

@lasta
Created May 25, 2014 10:38
Show Gist options
  • Save lasta/dadc97bc6e9005609191 to your computer and use it in GitHub Desktop.
Save lasta/dadc97bc6e9005609191 to your computer and use it in GitHub Desktop.
Copy diary_file and edit new one.
#!/bin/bash
set -euxo pipefail
## usage
# cd /path/to/diary_files/
# ./newDiary
# if you pass any value, new_diary_file will be opened with diary_editor
diary_editor="/Applications/MacVim.app/Contents/MacOS/Vim -g"
last_diary_file=`ls -1t 201[0-9]*.mkd | head -n 1`
last_diary_date=`echo ${last_diary_file} | cut -d "." -f1`
new_diary_date=`date +"%Y-%m-%d"`
new_diary_file="${new_diary_date}.mkd"
echo $last_diary_file
cp ${last_diary_file} ${new_diary_file}
if [ $# -eq 0 ]
then
echo "copied ${last_diary_file} to ${new_diary_file}"
else
diary_editor=$1
echo "copied ${last_diary_file} to ${new_diary_file}"
echo "running ${diary_editor}"
${diary_editor} ${new_diary_file}
fi
# unset
unset last_diary_file
unset last_diary_date
unset new_diary_date
unset new_diary_file
unset diary_editor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment