Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
DID
# What did i do today?
# from https://theptrk.com/2018/07/11/did-txt-file/
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 "# Week $(date +"%V (%B %Y)") \n\n## $(date +"%A %Y-%m-%d")" > ${DID_PATH}/$(date +%Y-%V).md
fi
FILE_EDITION_DATE="$(stat -c "%y" ${DID_PATH}/$(date +%Y-%V).md)"
NOW="$(date +"%Y-%m-%d")"
if [ ${FILE_EDITION_DATE:0:10} != ${NOW} ]
then
echo "\n## $(date +"%A %Y-%m-%d")\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
vmd ${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 %Y-%m-%d")" > ${DID_PATH}/$(date +%Y-%V).md
fi
vmd ${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 -d "$year-01-01 +$(( $week * 7 + 1 - $(date -d "$year-01-04" +%w ) - 3 )) days -2 days + $dayofweek days" +"%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\e[32m=> ${filename} ($(week2Month ${filename}), ${NB_OCCURENCE} results) \e[0m" && grep -n -B 1 ${1} ${file}
fi
done
else
echo "You must add a something to search..."
fi
unset LC_ALL
}
@Kmaschta

This comment has been minimized.

Copy link

Kmaschta commented Nov 7, 2018

I would suggest someting like mkdir -p ${DID_PATH} at the first line of the did command in order to init the folder!

@alexisjanvier

This comment has been minimized.

Copy link
Owner Author

alexisjanvier commented Nov 9, 2018

👍

@knutholst

This comment has been minimized.

Copy link

knutholst commented Nov 13, 2018

Hi, I did a fork of your script to make a bash script that I can use independently of my shell, as long as bash is available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.