ned: too much has happened. Lots of things work but something is borked
This commit is contained in:
parent
6b7e877e6c
commit
52c490dcea
1 changed files with 50 additions and 16 deletions
|
@ -29,39 +29,71 @@ usage() {
|
|||
edit() {
|
||||
check_setup
|
||||
|
||||
NOTE_PATH=("$NOTES_DIR/$2"*)
|
||||
NOTE_PATH="${NOTE_PATH[0]}"
|
||||
if ! [ -d "$NOTE_PATH" ]; then
|
||||
echo "No such directory: '$NOTE_PATH'"
|
||||
exit 1
|
||||
NOTE_PATH="$(fd -at f "$2" "$NOTES_DIR")"
|
||||
# if there was more than one result
|
||||
if [ "$(echo "$NOTE_PATH" | wc -l)" -gt 1 ]; then
|
||||
NOTE_PATH="$(echo "$NOTE_PATH" | fzy)"
|
||||
fi
|
||||
|
||||
# TODO: change fzf for `fd`, `fzy`, and ($3) to allow for more ergonomic use
|
||||
NOTE_NAME="$(cd "$NOTE_PATH" && fzf --height=10 --layout=reverse)" || exit
|
||||
$EDITOR_CMD "$NOTE_PATH/$NOTE_NAME"
|
||||
$EDITOR_CMD "$NOTE_PATH"
|
||||
}
|
||||
|
||||
new() {
|
||||
check_setup
|
||||
|
||||
# Find out note name
|
||||
if [ -z "$3" ]; then
|
||||
NOTE_NAME="$(date +'%F').md"
|
||||
else
|
||||
NOTE_NAME="$3.md"
|
||||
fi
|
||||
|
||||
NOTE_PATH=("$NOTES_DIR/$2"*/notes)
|
||||
NOTE_PATH="${NOTE_PATH[0]}"
|
||||
if ! [ -d "$NOTE_PATH" ]; then
|
||||
echo "No such directory: '$NOTE_PATH'"
|
||||
exit 1
|
||||
NOTE_PATH="$(fd -ad 1 "^$2" "$NOTES_DIR")"
|
||||
# check if there were no results
|
||||
if [ -z "$NOTE_PATH" ]; then
|
||||
echo "No directories found for '$2'."
|
||||
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
|
||||
|
||||
$EDITOR_CMD "$NOTE_PATH/$NOTE_NAME"
|
||||
# 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"
|
||||
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() {
|
||||
echo 'entering subshell'
|
||||
zsh
|
||||
$SHELL
|
||||
}
|
||||
|
||||
shell() {
|
||||
cd "$NOTES_DIR" && subshell
|
||||
}
|
||||
|
||||
check_setup() {
|
||||
|
@ -80,9 +112,11 @@ case "${1:0:1}" in
|
|||
'n') new $@;;
|
||||
# edit an existing document or file
|
||||
'e') edit $@;;
|
||||
# run a shell (cd to) in the directory
|
||||
'c'|'x'|'s') shell;;
|
||||
# me: edit ned (the file you are looking at)
|
||||
'm') $EDITOR "$(realpath "$0")";;
|
||||
*) echo "no such option";;
|
||||
esac
|
||||
|
||||
# vim: et sw=3 ts=3
|
||||
# vim: et sw=3 ts=3 ft=bash
|
||||
|
|
Loading…
Add table
Reference in a new issue