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

"notes recent" command to show recently edited notes #52

Open
stevenbell opened this issue Dec 31, 2017 · 9 comments
Open

"notes recent" command to show recently edited notes #52

stevenbell opened this issue Dec 31, 2017 · 9 comments

Comments

@stevenbell
Copy link

stevenbell commented Dec 31, 2017

It would be nice if I could see the notes I've recently edited (or perhaps even the ones I've recently accessed), with a command like notes recent. I may take a whack at this myself and submit a PR, but am interested in hearing thoughts on this before I go off coding.

@stevenbell stevenbell changed the title notes recent" "notes recent" command to show recently edited notes Dec 31, 2017
@pimterry
Copy link
Owner

I'm potentially open to something like this, although I'd like to dig into the details a little. What exactly would notes recent output? Are you supposed to use it like notes recent | notes open, to open recent files, and if so, what does that do?

Depending on what you're looking for, one interesting alternative would be to add a --sort argument to notes ls/notes find/etc. That way you could sort by modified date, and so notes ls --sort=created | head -n10 (for example) would list the 10 latest notes, and notes ls --sort=created | head -n1 | notes open would immediately open the last edited note.

It feels a little more powerful to add it to the existing commands, rather create a whole new separate command. Alternatively, you could have a standalone command for it? Maybe something like notes ls | notes sort --created | ..., which would let you manage it totally independently, but otoh is a bit more awkward imo... Open to ideas.

@stevenbell
Copy link
Author

My basic use case is that I want to open one of the notes that I edited yesterday, but I can't remember what I called it. For this case, I'm more concerned with speed (i.e., less thinking/typing) than with flexibility and power, so just listing the last five notes in reverse chronological order would be sufficient. I'll look at the output, and then run notes open ... to open a particular file.

If you'd prefer to keep things general, then printing all the notes with a command like notes ls --sort=created is a good way to do this, and I can make an alias for my more limited use case.

@primis
Copy link
Collaborator

primis commented Feb 13, 2018

I'd suggest a .notes-history file somewhere, then head append latest files opened

@BenjaminHae
Copy link

How about a notes filter command that allows to search by different criteria? One of them might be modification=yesterday.

@primis
Copy link
Collaborator

primis commented Feb 15, 2018

That would require date & time stamps on all the openings, might be tricky to implement

@rmNULL
Copy link
Contributor

rmNULL commented Mar 19, 2018

@primis maintaining a '.notes-history' file will add overhead costs to creating and opening files(I think), got different approach?.

@pimterry
Copy link
Owner

If your filesystem doesn't have noatime set, you can more or less do this just by looking at existing metadata, with no history file needed. If you check the atime for a note, it'll tell you exactly when it was last opened.

If you're using relatime (now the default in lots of distros I think) it might be a little inaccurate - I believe that means it gets updated once a day max. Not enough to do minute by minute filtering, but still easily enough to filter to 'notes I opened yesterday'.

@Fraasi
Copy link

Fraasi commented Jul 21, 2023

I would also like to have this feature, but as this conversation has been stale for awhile, I put together my own little solution and made myself a new command: lsm (m for modified).

  "lsm" )
    for f in $(ls -pt "$notes_dir"); do
      printf "%s %s %s\n" "$f" $(date -r "$notes_dir/$f" "+%Y-%m-%d %H:%M:%S")
    done | column -t
    ;;

So now I can do

$ n lsm
contr.md    2023-06-26  20:02:46
summ.md     2023-06-26  18:50:01
td_c.md     2023-01-02  13:57:17

to see the notes in last modified order.
If you have lot of notes or notes in directories, this propably will not work for you.
here's a little simpler version if -l in ls is enough for you.

  "lsm" )
    ls -lt "$notes_dir"
  ;;

results in

$ n lsm
total 32
-rwxrwxrwx 1 fraasi fraasi   113 Jun 26 20:02 contr.md
-rwxrwxrwx 1 fraasi fraasi   122 Jun 26 18:50 summ.md
-rwxrwxrwx 1 fraasi fraasi   343 Jan  2  2023 td_c.md

@stevenbell
Copy link
Author

I should have shared my solution from years ago!

recent_notes() {
    if [ "$#" -gt 0 ]; then
      count="$*"
    else
      count=1
    fi
    find $NOTES_DIRECTORY -type f -name "*.$NOTES_EXT" -printf '%T@ %P\n' | sort -n -r | awk '{print $2}' | head -n $count
}

I bound this to notes recent. So I can do notes recent 5 to show the five most recently edited notes, or notes recent | notes open to open the most recently edited note. It's probably not for everyone, but it's been working for me.

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

No branches or pull requests

6 participants