Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Newchair2644 opened this issue Mar 5, 2021 · 3 comments · Fixed by #84
Closed

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

Newchair2644 opened this issue Mar 5, 2021 · 3 comments · Fixed by #84

Comments

@Newchair2644
Copy link

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
Copy link
Owner

pimterry commented Mar 8, 2021

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:

notes/notes

Lines 173 to 184 in 428946e

get_full_note_path() {
local note_path=$1
if [[ "$note_path" != *.$NOTES_EXT ]]; then
note_path="$note_path.$NOTES_EXT"
fi
if [ ! -f "$note_path" ]; then
note_path="$notes_dir/$note_path"
fi
echo "$note_path"
}
and it should be easy to add another test for this similar to:
@test "Accepts names without .md to open" {
touch $NOTES_DIRECTORY/note.md
run bash -c "$notes open note"
assert_success
assert_output "Editing $NOTES_DIRECTORY/note.md"
}

@eshapard
Copy link
Contributor

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
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants