Last active
November 10, 2018 14:43
-
-
Save shnupta/28231011ee11705a8fe9b7b3b9f3c5de to your computer and use it in GitHub Desktop.
My macOS version of Alexis Janvier's did shell script.
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
export MDV_THEME=729.8953 | |
export DID_PATH=~/.did | |
function did(){ | |
export LC_ALL=C | |
mkdir -p ${DID_PATH} | |
if [ ! -f ${DID_PATH}/$(date +%Y-%V).md ]; then | |
echo -e "# Week $(date +"%V (%B %Y)") \n\n## $(date +"%A %d-%m-%y")" > ${DID_PATH}/$(date +%Y-%V).md | |
fi | |
FILE_EDITION_DATE="$(stat -f %Sm -t %d-%m-%Y ${DID_PATH}/$(date +%Y-%V).md)" | |
NOW="$(date +"%d-%m-%Y")" | |
if [ ${FILE_EDITION_DATE:0:10} != ${NOW} ] | |
then | |
echo -e "\n## $(date +"%A %d-%m-%Y")\n" >> ${DID_PATH}/$(date +%Y-%V).md | |
fi | |
unset LC_ALL | |
vim +'normal Go' ${DID_PATH}/$(date +%Y-%V).md | |
} | |
function didv(){ | |
if [ $1 ] | |
then | |
mdv ${DID_PATH}/${1}.md | |
else | |
mkdir -p ${DID_PATH} | |
if [ ! -f ${DID_PATH}/$(date +%Y-%V).md ]; then | |
LC_ALL=C echo "# Week $(date +"%V (%B %Y)") \n\n## $(date +"%A %d-%m-%Y")" > ${DID_PATH}/$(date +%Y-%V).md | |
fi | |
mdv ${DID_PATH}/$(date +%Y-%V).md | |
fi | |
} | |
function week2Month(){ | |
export LC_ALL=C | |
year=$(echo $1 | cut -f1 -d-) | |
week=$(echo $1 | cut -f2 -d-) | |
local dayofweek=1 # 1 for monday | |
date -j -f "%Y-%W" $1 +"%B %Y" | |
unset LC_ALL | |
} | |
function didl(){ | |
for file in `ls ${DID_PATH}/*.md | sort -Vr`; do | |
filenameRaw="$(basename ${file})" | |
filename="${filenameRaw%.*}" | |
echo "${filename} ($(week2Month ${filename}))" | |
done | |
} | |
function dids(){ | |
export LC_ALL=C | |
if [ $1 ] | |
then | |
for file in `ls ${DID_PATH}/*.md | sort -Vr`; do | |
NB_OCCURENCE="$(grep -c ${1} ${file})" | |
if [ ${NB_OCCURENCE} != "0" ] | |
then | |
filenameRaw="$(basename ${file})" | |
filename="${filenameRaw%.*}" | |
echo -e "\n\033[32m=> ${filename} ($(week2Month ${filename}), ${NB_OCCURENCE} results) \033[0m" && grep -n -B 1 ${1} ${file} | |
fi | |
done | |
else | |
echo "You must add a something to search..." | |
fi | |
unset LC_ALL | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment