Last active
June 4, 2020 10:10
-
-
Save jujhars13/86ffe526bf25199db39088779e51767c to your computer and use it in GitHub Desktop.
Create a log entry for my daily work log, a bit like workingon.co used to work. Commits changes to git
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
# log what I'm working on to a text file unde `$repo/<year>/<month>/<day>.md` | |
# change the $repo variable to point to a dir on your machine | |
# if the dir is a git repo then it will also commit to git, otherwise just do nothing | |
# | |
# USAGE: on "working on creating a script to make things better" | |
function on(){ | |
local version="1.1.4" | |
local repo="/home/jujhar/proj/jujhar-daily-log" | |
local year=$(date +%Y) | |
local month=$(date +%m) | |
local day=$(date +%d) | |
local now=$(date "+%Y-%m-%d %H:%M:%S") | |
if [[ -z ${1} ]]; then | |
>&2 echo "You didn't supply anything to log" | |
return false | |
fi | |
# grab text, non need for quotes as we'll munge the param array | |
shift $((OPTIND-1)) | |
local text="$@" | |
mkdir -p "${repo}/${year}/${month}" | |
echo -e "${now} -- ${text} \n" | \ | |
tee -a "${repo}/${year}/${month}/${day}.md" | |
# if it's a git repo then commit it | |
output=$( | |
cd "${repo}" | |
if git -C . rev-parse; then | |
echo "commiting repo" | |
git pull | |
git add . | |
git commit -am "a new update ${now}" | |
git push | |
fi | |
) | |
echo "all done" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment