ned: multiple improvements, including re-writing the help page
This commit is contained in:
parent
de077cf070
commit
4cf4fab494
1 changed files with 19 additions and 8 deletions
|
@ -12,24 +12,30 @@
|
|||
NOTES_DIR="${NOTES_DIR:-"$HOME/Documents/college/current"}"
|
||||
EDITOR="nvim"
|
||||
EDITOR_CMD="nvim -c :ZenMode"
|
||||
DEFAULT_NOTE_NAME="$(date +'%m-%d').md"
|
||||
|
||||
usage() {
|
||||
cat <<-EOF
|
||||
Usage:
|
||||
ned <verb>
|
||||
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
|
||||
help Print this message
|
||||
|
||||
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
|
||||
Ned will automatically activate the ZenMode nvim extension
|
||||
Current repository path: $NOTES_DIR
|
||||
Ned will automatically activate the ZenMode neovim extension
|
||||
Current repository path: '$NOTES_DIR'
|
||||
EOF
|
||||
}
|
||||
|
||||
open_file() {
|
||||
cd $(dirname "$1")
|
||||
$EDITOR_CMD "$1"
|
||||
}
|
||||
|
||||
edit() {
|
||||
check_setup
|
||||
|
||||
|
@ -42,10 +48,14 @@ edit() {
|
|||
SEARCH_TERM="$2"
|
||||
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
|
||||
|
||||
cd "$(dirname "$NOTE_PATH")"
|
||||
$EDITOR_CMD "$NOTE_PATH"
|
||||
open_file "$NOTE_PATH"
|
||||
}
|
||||
|
||||
new() {
|
||||
|
@ -55,7 +65,7 @@ new() {
|
|||
if [ -n "$3" ]; then
|
||||
NOTE_NAME="$3.md"
|
||||
else
|
||||
NOTE_NAME="$(date +'%m-%d').md"
|
||||
NOTE_NAME="$DEFAULT_NOTE_NAME"
|
||||
fi
|
||||
|
||||
# TODO: use fzf instead of fd + fzf for picking the directory
|
||||
|
@ -85,17 +95,18 @@ new() {
|
|||
if [ -f "$NOTE_PATH/$NOTE_NAME" ]; then
|
||||
echo "File already exists. Opening..."
|
||||
sleep 0.5
|
||||
$EDITOR_CMD "$NOTE_PATH/$NOTE_NAME"
|
||||
open_file "$NOTE_PATH/$NOTE_NAME"
|
||||
else
|
||||
cd "$NOTE_PATH" || exit
|
||||
# apply a template for notes
|
||||
cat <<-EOF >> "$NOTE_PATH/$NOTE_NAME"
|
||||
# $NOTE_NAME
|
||||
|
||||
<!-- vim: wrap nonu nornu
|
||||
-->
|
||||
EOF
|
||||
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
|
||||
rm "$NOTE_PATH/$NOTE_NAME"
|
||||
fi
|
||||
|
|
Loading…
Add table
Reference in a new issue