added loggit
This commit is contained in:
parent
aaf6f566d9
commit
c90517676c
1 changed files with 41 additions and 0 deletions
41
loggit
Normal file
41
loggit
Normal file
|
@ -0,0 +1,41 @@
|
|||
#!/usr/bin/env sh
|
||||
# Create a Log text file at a specific location and append text entries to it.
|
||||
#
|
||||
# Usage:
|
||||
# $ loggit something you want to jot down (appends that text to the file)
|
||||
# $ xclip -o | loggit (appends your clipboard to the file)
|
||||
# $ loggit (opens the file in your editor)
|
||||
#
|
||||
# Produces:
|
||||
# Log.txt in your $NOTES_DIRECTORY (this is set below).
|
||||
|
||||
set -e
|
||||
|
||||
readonly NOTES_DIRECTORY="${NOTES_DIRECTORY:-${HOME}/loggit}"
|
||||
readonly NOTES_EDITOR="${EDITOR:-nano}"
|
||||
|
||||
readonly NOTES_FILE="$Log.txt"
|
||||
readonly NOTES_PATH="${NOTES_DIRECTORY}/${NOTES_FILE}"
|
||||
|
||||
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 [ ${#} -eq 0 ]; then
|
||||
if [ -p "/dev/stdin" ]; then
|
||||
(cat; printf "\n\n") >> "${NOTES_PATH}"
|
||||
else
|
||||
eval "${NOTES_EDITOR}" "${NOTES_PATH}"
|
||||
fi
|
||||
else
|
||||
printf "%s\n\n" "${*}" >> "${NOTES_PATH}"
|
||||
fi
|
Loading…
Reference in a new issue