pimterry / notes

:pencil: Simple delightful note taking, with more unix and less lock-in.
https://github.com/pimterry/notes
MIT License
1.24k stars 82 forks source link

Edit and save a file that is not of the default NOTES_EXT #82

Closed Newchair2644 closed 3 years ago

Newchair2644 commented 3 years ago

My NOTES_EXT variable is set to markdown, which is good, because that's what I take most of my notes in. However many of my "notes" are .c or .py files filled with comments on however the code in the file works. Whenever I open one of these files, notes makes a new blank .md file and names it exactly the same as the file I was trying to open instead of just opening the file. So, for example, if I were trying to open file.c, notes will make a new file titled file.c.md. I want to be able to edit .md notes along with .c and .py. Thanks!

pimterry commented 3 years ago

Hi @NumenHackerCracker good suggestion, thanks. I think this sounds like an easy & sensible fix: if the exact filename exists, notes open should use that rather than appending an extension.

Would you be interested in putting together a PR to fix that? I think the main place the extension is used is here: https://github.com/pimterry/notes/blob/428946ed32a29d5fdd100778aa185d548db6b2c2/notes#L173-L184 and it should be easy to add another test for this similar to: https://github.com/pimterry/notes/blob/428946ed32a29d5fdd100778aa185d548db6b2c2/test/test-open.bats#L84-L91

eshapard commented 3 years ago

I've been doing some hacking on the script recently and I actually implemented this feature.

I think all I had to do was change get_full_note_path to just not add the file extension if $notes_dir/$notes_path is a file. If not, then test for the extension and add if not there.

Looking at the code you posted, I'm wondering about this:

if [ ! -f "$note_path" ]; then
    note_path="$notes_dir/$note_path"
fi

Is this there in case a user supplies an absolute path or something? it seems like the $nodes_dir should always be prepended, shouldn't it?

pimterry commented 3 years ago

If you've got a fix for this issue in general, please do put in a PR, that'd be great.

Is this there in case a user supplies an absolute path or something?

Yes, I'm pretty sure that's why that's there. I don't remember the original reasoning for that (that line was last touched 5 years ago!) but it's a useful option to have, especially for composing notes with other CLI tools.