ned: too much has happened. Lots of things work but something is borked

This commit is contained in:
PowerUser64 2022-01-27 03:48:06 -08:00
parent 6b7e877e6c
commit 52c490dcea

View file

@ -29,39 +29,71 @@ usage() {
edit() { edit() {
check_setup check_setup
NOTE_PATH=("$NOTES_DIR/$2"*) NOTE_PATH="$(fd -at f "$2" "$NOTES_DIR")"
NOTE_PATH="${NOTE_PATH[0]}" # if there was more than one result
if ! [ -d "$NOTE_PATH" ]; then if [ "$(echo "$NOTE_PATH" | wc -l)" -gt 1 ]; then
echo "No such directory: '$NOTE_PATH'" NOTE_PATH="$(echo "$NOTE_PATH" | fzy)"
exit 1
fi fi
# TODO: change fzf for `fd`, `fzy`, and ($3) to allow for more ergonomic use $EDITOR_CMD "$NOTE_PATH"
NOTE_NAME="$(cd "$NOTE_PATH" && fzf --height=10 --layout=reverse)" || exit
$EDITOR_CMD "$NOTE_PATH/$NOTE_NAME"
} }
new() { new() {
check_setup check_setup
# Find out note name
if [ -z "$3" ]; then if [ -z "$3" ]; then
NOTE_NAME="$(date +'%F').md" NOTE_NAME="$(date +'%F').md"
else else
NOTE_NAME="$3.md" NOTE_NAME="$3.md"
fi fi
NOTE_PATH=("$NOTES_DIR/$2"*/notes) NOTE_PATH="$(fd -ad 1 "^$2" "$NOTES_DIR")"
NOTE_PATH="${NOTE_PATH[0]}" # check if there were no results
if ! [ -d "$NOTE_PATH" ]; then if [ -z "$NOTE_PATH" ]; then
echo "No such directory: '$NOTE_PATH'" echo "No directories found for '$2'."
exit 1 echo "All possible directories:"
(cd "$NOTES_DIR" && fd -d 1 -t d "$NOTES_DIR")
exit
# if there was more than one result
elif [ "$(echo "$NOTE_PATH" | wc -l)" -gt 1 ]; then
NOTE_PATH="$(echo "$NOTE_PATH" | fzy)" || exit
fi fi
# TODO: allow setting location for files to go with $3, and $4 for file name
# check if there is a notes directory in the note path
if [ -d "$NOTE_PATH/notes" ]; then
NOTE_PATH="$NOTE_PATH/notes"
# if there is no notes directory
else
PROMPT="Place note in… "
NOTE_PATH="$(cd "$NOTE_PATH" && fd -ad 1 -t d | fzy -p "$PROMPT")" || exit
fi
if [ -f "$NOTE_PATH/$NOTE_NAME" ]; then
echo "File already exists. Opening..."
$EDITOR_CMD "$NOTE_PATH/$NOTE_NAME" $EDITOR_CMD "$NOTE_PATH/$NOTE_NAME"
else
cd "$NOTE_PATH" || exit
# apply a template for notes
cat <<-EOF >> "$NOTE_PATH/$NOTE_NAME"
<!-- vim: wrap nonu nornu
-->
EOF
$EDITOR_CMD "$NOTE_PATH/$NOTE_NAME"
fi
} }
subshell() { subshell() {
echo 'entering subshell' echo 'entering subshell'
zsh $SHELL
}
shell() {
cd "$NOTES_DIR" && subshell
} }
check_setup() { check_setup() {
@ -80,9 +112,11 @@ case "${1:0:1}" in
'n') new $@;; 'n') new $@;;
# edit an existing document or file # edit an existing document or file
'e') edit $@;; 'e') edit $@;;
# run a shell (cd to) in the directory
'c'|'x'|'s') shell;;
# me: edit ned (the file you are looking at) # me: edit ned (the file you are looking at)
'm') $EDITOR "$(realpath "$0")";; 'm') $EDITOR "$(realpath "$0")";;
*) echo "no such option";; *) echo "no such option";;
esac esac
# vim: et sw=3 ts=3 # vim: et sw=3 ts=3 ft=bash