add a notes binary
This commit is contained in:
parent
abae4f2b1f
commit
51e512c83f
1 changed files with 48 additions and 0 deletions
48
home/private_bin/executable_notes
Normal file
48
home/private_bin/executable_notes
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
# Create a dated text file at a specific location and append text to it.
|
||||||
|
#
|
||||||
|
# Usage:
|
||||||
|
# $ notes something you want to jot down (appends that text to the file)
|
||||||
|
# $ xclip -o | notes (appends your clipboard to the file)
|
||||||
|
# $ notes (opens the file in your editor)
|
||||||
|
#
|
||||||
|
# Produces:
|
||||||
|
# YYYY-W.txt in your $NOTES_DIRECTORY (this is set below).
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
YEAR="$(date +"%Y")"
|
||||||
|
WEEK="$(date +"%W")"
|
||||||
|
NOTES_DIRECTORY="${NOTES_DIRECTORY:-${HOME}/stuff/notes/notes}"
|
||||||
|
NOTES_EDITOR="${EDITOR:-vim}"
|
||||||
|
NOTES_FILE="${YEAR}-${WEEK}.md"
|
||||||
|
NOTES_PATH="${NOTES_DIRECTORY}/${NOTES_FILE}"
|
||||||
|
|
||||||
|
readonly YEAR WEEK NOTES_FILE NOTES_PATH NOTES_EDITOR NOTES_DIRECTORY
|
||||||
|
|
||||||
|
if [ ! -d "${NOTES_DIRECTORY}" ]; then
|
||||||
|
while true; do
|
||||||
|
printf "%s does not exist, do you want to create it? (y/n) " "${NOTES_DIRECTORY}"
|
||||||
|
read -r yn
|
||||||
|
|
||||||
|
case "${yn}" in
|
||||||
|
[Yy]* ) mkdir -p "${NOTES_DIRECTORY}"; break;;
|
||||||
|
[Nn]* ) exit;;
|
||||||
|
* ) printf "Please answer y or n\n\n";;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f "${NOTES_PATH}" ]; then
|
||||||
|
printf '# %s Week %s\n' "${YEAR}" "${WEEK}" > "${NOTES_PATH}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ${#} -eq 0 ]; then
|
||||||
|
if [ -p "/dev/stdin" ]; then
|
||||||
|
(cat; printf "\n") >> "${NOTES_PATH}"
|
||||||
|
else
|
||||||
|
eval "${NOTES_EDITOR}" "${NOTES_PATH}"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
printf "%s\n" "${*}" >> "${NOTES_PATH}"
|
||||||
|
fi
|
Loading…
Reference in a new issue