ned: multiple improvements, including re-writing the help page

This commit is contained in:
PowerUser64 2022-03-05 22:45:21 -08:00
parent de077cf070
commit 4cf4fab494

View file

@ -12,24 +12,30 @@
NOTES_DIR="${NOTES_DIR:-"$HOME/Documents/college/current"}" NOTES_DIR="${NOTES_DIR:-"$HOME/Documents/college/current"}"
EDITOR="nvim" EDITOR="nvim"
EDITOR_CMD="nvim -c :ZenMode" EDITOR_CMD="nvim -c :ZenMode"
DEFAULT_NOTE_NAME="$(date +'%m-%d').md"
usage() { usage() {
cat <<-EOF cat <<-EOF
Usage: Usage:
ned <verb> ned <verb>
new <folder> [note name] Create a new note in the matched folder new <folder> [note name] Create a new note in the matched folder
[edit|ed] <folder> [note name] Search for and edit a text document in a folder [edit|ed] [folder] <note name> Search for and edit a text document in a folder
ned Edit ned ned Edit ned
help Print this message help Print this message
Notes: Notes:
Right now, only the first letter of each option is considered, so \`ned n\` and \`ned neww\` do the same thing 'T' is an edit pointer to the default file name (today's date)
Folder and file names are searched with fuzzy search Folder and file names are searched with fuzzy search
Ned will automatically activate the ZenMode nvim extension Ned will automatically activate the ZenMode neovim extension
Current repository path: $NOTES_DIR Current repository path: '$NOTES_DIR'
EOF EOF
} }
open_file() {
cd $(dirname "$1")
$EDITOR_CMD "$1"
}
edit() { edit() {
check_setup check_setup
@ -42,10 +48,14 @@ edit() {
SEARCH_TERM="$2" SEARCH_TERM="$2"
fi fi
if [ "$SEARCH_TERM" = 'T' ]; then
SEARCH_TERM="$DEFAULT_NOTE_NAME"
fi
NOTE_PATH="$NOTES_DIR/$(cd "$NOTES_DIR" && fzf -1 -q "$SEARCH_TERM" --layout=reverse --info=inline --height=10%)" || exit NOTE_PATH="$NOTES_DIR/$(cd "$NOTES_DIR" && fzf -1 -q "$SEARCH_TERM" --layout=reverse --info=inline --height=10%)" || exit
cd "$(dirname "$NOTE_PATH")" cd "$(dirname "$NOTE_PATH")"
$EDITOR_CMD "$NOTE_PATH" open_file "$NOTE_PATH"
} }
new() { new() {
@ -55,7 +65,7 @@ new() {
if [ -n "$3" ]; then if [ -n "$3" ]; then
NOTE_NAME="$3.md" NOTE_NAME="$3.md"
else else
NOTE_NAME="$(date +'%m-%d').md" NOTE_NAME="$DEFAULT_NOTE_NAME"
fi fi
# TODO: use fzf instead of fd + fzf for picking the directory # TODO: use fzf instead of fd + fzf for picking the directory
@ -85,17 +95,18 @@ new() {
if [ -f "$NOTE_PATH/$NOTE_NAME" ]; then if [ -f "$NOTE_PATH/$NOTE_NAME" ]; then
echo "File already exists. Opening..." echo "File already exists. Opening..."
sleep 0.5 sleep 0.5
$EDITOR_CMD "$NOTE_PATH/$NOTE_NAME" open_file "$NOTE_PATH/$NOTE_NAME"
else else
cd "$NOTE_PATH" || exit cd "$NOTE_PATH" || exit
# apply a template for notes # apply a template for notes
cat <<-EOF >> "$NOTE_PATH/$NOTE_NAME" cat <<-EOF >> "$NOTE_PATH/$NOTE_NAME"
# $NOTE_NAME
<!-- vim: wrap nonu nornu <!-- vim: wrap nonu nornu
--> -->
EOF EOF
STARTING_MD5="$(md5sum "$NOTE_PATH/$NOTE_NAME")" STARTING_MD5="$(md5sum "$NOTE_PATH/$NOTE_NAME")"
$EDITOR_CMD "$NOTE_PATH/$NOTE_NAME" open_file "$NOTE_PATH/$NOTE_NAME"
if [ "$(md5sum "$NOTE_PATH/$NOTE_NAME")" = "$STARTING_MD5" ]; then if [ "$(md5sum "$NOTE_PATH/$NOTE_NAME")" = "$STARTING_MD5" ]; then
rm "$NOTE_PATH/$NOTE_NAME" rm "$NOTE_PATH/$NOTE_NAME"
fi fi