Created
February 11, 2017 12:41
-
-
Save relsqui/99a3ee5677a21904e6adf2f6c76332d0 to your computer and use it in GitHub Desktop.
A little script for making daily writing really easy.
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
#!/bin/bash | |
# <CONFIG> | |
# set to non-null to allow any user to read your dailies | |
# if you don't set this or daily_group, only you can read your dailies | |
public_dailies= | |
# set to a group name to allow that group to read your dailies | |
# (this is ignored if public_dailies is set) | |
daily_group=housemates | |
# set this to non-null to put your dailies in git | |
use_git=y | |
# set this to non-null to use automatic generic commit messages | |
# (this is ignored if use_git is empty) | |
auto_commit=y | |
# don't forget to set this in your .bashrc (but here is ok too) | |
EDITOR="$EDITOR" | |
# </CONFIG> | |
# stop executing after any error | |
# (avoids squashing but may leave entries uncommitted etc.) | |
set -e | |
if [ -n "$public_dailies" ]; then | |
daily_perms=644 | |
dir_perms=755 | |
daily_group="$(whoami)" | |
elif [ -n "$daily_group" ]; then | |
daily_perms=640 | |
dir_perms=750 | |
else | |
daily_perms=600 | |
dir_perms=700 | |
daily_group="$(whoami)" | |
fi | |
if [ -n "$EDITOR" ]; then | |
# user-configured preferred editor | |
editor="$EDITOR" | |
else | |
# this is what you get for not setting your editor | |
editor="$(which nano)" | |
fi | |
if [ ! -d ~/dailies ]; then | |
mkdir ~/dailies | |
chmod $dir_perms ~/dailies | |
chgrp $daily_group ~/dailies | |
cd ~/dailies | |
if [ -n "$use_git" ]; then | |
git init | |
fi | |
fi | |
old_dir="$PWD" | |
cd ~/dailies | |
today="$(date +%F)" | |
touch $today | |
chmod $daily_perms $today | |
chgrp $daily_group $today | |
$editor $today | |
if [ -n "$use_git" ]; then | |
git add $today | |
if [ -n "$auto_commit" ]; then | |
git commit -m "Commit automatically generated by daily writing script." | |
else | |
git commit | |
fi | |
fi | |
cd $old_dir |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Of course the actual right place for the configuration stuff is in a ~/.dailyrc or something, but I'm not worried about that while I'm just running it out of my ~/bin.