xwmx / nb

CLI and local web plain text note‑taking, bookmarking, and archiving with linking, tagging, filtering, search, Git versioning & syncing, Pandoc conversion, + more, in a single portable script.
https://xwmx.github.io/nb
GNU Affero General Public License v3.0
6.57k stars 187 forks source link

A way to favorite notes? #82

Open mgrecar opened 3 years ago

mgrecar commented 3 years ago

I might just have missed something in the documentation, but is there a way to 'favorite' certain notes, so they get pinned when your run nb? For example, I have a couple notes that are of special significance that I'd like to easily see without having to craft a query.

Right now, I've got a shell alias favorites='nb search --list '#favorite', and I just tag anything I need to with #favorite. It works fine, just wondering if there was anything built in that saved me needing a shell alias set up.

xwmx commented 3 years ago

Hi @mgrecar! I was working on search and list and realized I could just implement experimental search-based pinning similar to your approach, so that’s now available in the latest versions in the project repo.

To enable it, set the $NB_PINNED_PATTERN environment variable to the desired tag. In your case, you can add the following line to your ~/.nbrc file, which can be opened in your editor with nb settings edit:

export NB_PINNED_PATTERN="#favorite"

When $NB_PINNED_PATTERN is set, nb and nb ls will display any items in the notebook containing that tag first in the list with a pushpin 📌 indicator.

This is still an experiment and I have some implementation ideas, so it will likely evolve.

mgrecar commented 3 years ago

I just grabbed 6.0.0-alpha and tested it out, super cool! That's pretty much exactly what I was looking for. Much easier than having a separate alias for that capability. I'll keep using the alpha until that gets polished up and merged into a legit release. Thanks for putting in the work on this!

xwmx commented 3 years ago

I just added a second pinning implementation with new pin and unpin subcommands that save pinned items to a .pindex file in each folder. This makes it possible to pin items of any type. This approach cooperates with search-based pinning, so they can be used together.

The icons / emoji characters are also now customizable, so if you want to use a different character for pinned items, just add a line like the following to your ~/.nbrc file (open with nb settings edit):

# reassign pinned indicator
export NB_INDICATOR_PINNED="💖"
mgrecar commented 3 years ago

Great work on this. I really like the new functionality better, as I can remove metadata from the notes themselves. The only minor quibble I have at the moment is that I can't set the pinning order, it would seem. I tried manually editing the .pindex file entries, but it did some kind of operation on my next execution of nb and nothing had moved. It seemed to revert my edit on me. It seems like the pinned entries are stored in a fixed sort by filename that can't currently be manipulated.

Not a real big deal, just something I noticed while trying to sort my pins to a sequence I preferred. Still really happy with the feature!

xwmx commented 3 years ago

@mgrecar OK, it now preserves the order. Thanks for the heads up!

mgrecar commented 3 years ago

Updated and it works great, I can re-order entries and it's respected. Thanks!

ohyhyb commented 3 years ago

Just a heads up, when deleting a pinned item it still persists in the notebook list as the item isn't cleared from the .pindex file.

xwmx commented 3 years ago

@ohyhyb Thanks for letting me know. It's working in my testing and I haven't been able to reproduce the issue yet, so there might be something about your environment that nb isn't accounting for. There are tests for unpin and I just added another, and they seem to be passing on macOS and Ubuntu on GitHub Actions. The unpin operation itself is pretty simple with two sed -i calls.

The only thing I can think of so far is if $NB_PINNED_PATTERN is set and that item contains the search pattern / tag, in which case unpin wouldn't stop it from being pinned.

What system are you running nb on (e.g., uname -a && bash --version)? You can also try running the bats tests with bats test/pin-unpin.bats in a clone of the repo on your system and see if it passes or provides more error information.

ohyhyb commented 3 years ago

@xwmx The pin and unpin operations work perfectly and the tests pass on up-to-date versions of Mojave and Debian, but I think the issue is when calling '_delete()' there are no checks to see if the item exists in the .pindex file. Infact you can put any text in .pindex and it will show up as a pinned item, there is no validation like there is for the .index file.

realshovanshah commented 9 months ago

Hey, on a similar note, is there a way to list notes (using nb ls) without the pinned items? Recent notes that could otherwise be viewed using nb tends to get blocked as the number of pinned notes increases.