121 lines
3.6 KiB
Bash
Executable File
121 lines
3.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
##############################################################################
|
|
#
|
|
# Basic structure derived from the note taking application named zetz;
|
|
# - https://gist.github.com/kutacoder/de2c0e624477efce920904125f0fb7b0
|
|
#
|
|
# Prerequisites:
|
|
# - tmux, fzf, bat, rg
|
|
#
|
|
# - Notes should have a .md extention.
|
|
# - Notes should have a title on the *first* line prefixed by one hash symbol, i.e. "# Cool Title".
|
|
#
|
|
# Key Bindings:
|
|
# - ctrl-r: reload list
|
|
# - ctrl-x: delete note
|
|
# - ctrl-i: add new note
|
|
#
|
|
# NOTE: The new note's name is its creation date in the follwing format: %Y%m%d%H%M%S
|
|
##############################################################################
|
|
|
|
#################################################
|
|
# default note path if not specified
|
|
NOTEPATH="$HOME/.notes/notes"
|
|
|
|
#################################################
|
|
# DOTAGS is false by default
|
|
DOTAGS="false"
|
|
|
|
#################################################
|
|
# Usage Function
|
|
|
|
usage () {
|
|
echo ""
|
|
echo "Usage: $0 [-p <path to note directory>] [-t]"
|
|
echo ""
|
|
echo "-p Path to desired note directory. Can be relative or absolute."
|
|
echo " ie, \"-p \$HOME/.notes/notes\""
|
|
echo ""
|
|
echo "-t Use tags search (default is to use filename search)"
|
|
echo ""
|
|
}
|
|
|
|
#################################################
|
|
# Parse the CLA
|
|
|
|
parse_args() {
|
|
while getopts "p:t" opt; do
|
|
case $opt in
|
|
p)
|
|
NOTEPATH=${OPTARG}
|
|
;;
|
|
|
|
t)
|
|
DOTAGS="true"
|
|
;;
|
|
|
|
\?)
|
|
usage
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
}
|
|
|
|
|
|
#################################################
|
|
main() {
|
|
|
|
parse_args "$@"
|
|
|
|
#############################################
|
|
# check if the supplied note path exists
|
|
|
|
if [ ! -d "$NOTEPATH" ];
|
|
then
|
|
echo ""
|
|
echo "Error: Directory \"${NOTEPATH}\" does not exist!"
|
|
usage
|
|
exit 1
|
|
fi
|
|
|
|
cd "$NOTEPATH"
|
|
|
|
if [ "$DOTAGS" == "false" ];
|
|
then
|
|
#########################################
|
|
# Run against filenames
|
|
|
|
FZF_DEFAULT_COMMAND="find *.md -type f -exec sed -n 1p {} \; | sed 's_# __g' | sort -rn" \
|
|
fzf --height=100% --preview-window=right:65%:wrap \
|
|
--preview 'bat --language=md --style=plain --color=always $(rg -slF {})' \
|
|
--bind 'enter:execute:$EDITOR $(rg -slF {})' \
|
|
--bind 'ctrl-r:reload:$SHELL -c "${FZF_DEFAULT_COMMAND}"' \
|
|
--bind 'ctrl-x:execute-silent(rm -f $(rg -slF {}))+reload:$SHELL -c "${FZF_DEFAULT_COMMAND}"' \
|
|
--bind 'ctrl-i:execute:tmux split-window "FZF_DEFAULT_COMMAND=\"${FZF_DEFAULT_COMMAND}\" $EDITOR $(date +"%Y%m%d%H%M%S").md"'
|
|
else
|
|
#########################################
|
|
# Run against tags
|
|
|
|
FZF_DEFAULT_COMMAND="rg '^\#[a-zA-Z]' *.md" \
|
|
fzf --exact --height=100% --preview-window=right:65%:wrap \
|
|
--preview 'bat --language=md --style=plain --color=always $(echo {} | cut -d':' -f1)' \
|
|
--bind 'enter:execute:$EDITOR $(echo {} | cut -d':' -f1)' \
|
|
--bind 'ctrl-r:reload:$SHELL -c "${FZF_DEFAULT_COMMAND}"' \
|
|
--bind 'ctrl-x:execute-silent(rm -f $(echo {} | cut -d':' -f1))+reload:$SHELL -c "${FZF_DEFAULT_COMMAND}"' \
|
|
--bind 'ctrl-i:execute:tmux split-window "FZF_DEFAULT_COMMAND=\"${FZF_DEFAULT_COMMAND}\" $EDITOR $(date +"%Y%m%d%H%M%S").md"'
|
|
fi
|
|
|
|
#############################################
|
|
# check changes made into git
|
|
git add . && git commit -q -m "checking in changes made at $(date +%Y%m%d-%H%M%S)"
|
|
|
|
cd -
|
|
}
|
|
|
|
#################################################
|
|
# This is the way...
|
|
main "$@"
|
|
|
|
# EOF
|