Taking quick notes in the terminal

A quick way to take down information from the terminal.

Every now and then someone asks me about my note-taking system. My job requires me to store a lot of information quickly and efficiently, and a few times now people have asked me what it is I’m doing. I thought this might be a good place to document my system.

Requirements

There are a few things I need from a note-taking system:

  • Speed
    • I have to be able to start writing instantly
  • Searchability
    • It’s important to be able to quickly search through notes
  • Sync
    • I have to keep them synced across my work desktop PC and my laptop.
  • Fire and forget
    • I need to store everything, but need to also bear in mind that I will not be looking at 90% of what I have ever again.

My system

I use Linux everywhere, and use the terminal for most things, so here’s what I ended up with.

In short, it’s a folder full of markdown files whose titles are the date they were created!

Pros and cons

I’ll just run though some of the ups and downs of it.

Pros

  • Plaintext
    • Easy to search and manipulate
  • Tracked and synced with git
    • But stored on your server
  • Opens in less than one second
  • Portable
  • Lightwieght
    • Uses mostly tools you probably already have installed.
  • Nerdy
    • Great if you know bash, vim and other Linux shit

Cons

  • Text only
    • Suits me, but some of the fancier systems do images etc
  • Nerdy
    • Not for everyone
    • Search is not intuitive (although very fast once you know how)
  • Manual sync
    • You can automate the sync, but setup in particular requires at least some thought.
  • Not great on mobiles
    • I actually use it on mobile a lot with sgit and a text editor, but it’s not ‘pretty’.
  • Titles only have the date
    • So you really need to know how to search

Dependencies

You need a few things installed to proceed, as a bare minimum to get the aliases below to work.

  • Vim - to create, edit and sometimes search files
  • Ranger - to flip through files
  • Git - to track changes and sync the files
  • ssh - to log into your server

You also need a folder to store your notes in. e.g. mkdir ~/notes

Git

I’ll briefly cover how to set up a git folder on your server, but more info can be found here.

ssh jimmy@myserver.com
cd /where/my/git/folder/is
mkdir notes.git && cd notes.git
git init --bare

Then get off ssh and go back to your local machine.

cd ~/notes
git init
git add .
git commit -m 'Initial Commit'
git remote add origin jimmy@myserver.com:/where/my/git/folder/is/notes.git
git push origin master

All set. To get your folder on other machines, just do

git clone jimmy@myserver.com:/where/my/git/folder/is/notes.git

And you’re done.

Bash aliases

To tackle the ‘speed’ requirements, I made some super short bash aliases to open and view notes.

Add the following to your .bashrc.

To open a new note:

function nn {
vim ~/notes/$(date --utc +%FT%H-%M-%S).markdown
}

Now, when you press nn, a new file is opened, in vim, its title being the date and time in UTC. This reduces the chances of you having two notes with the same name - you would have to open two at precisely the same second for this to occur. The extension is .markdown because I like to use markdown to format the text sometimes; this part is really not essential.

To view all your notes:

alias nv='ranger ~/notes'

When you type nv, ranger, a terminal based file manager, opens in your notes directory. You can use hjkl or the arrow keys to flip through them. The notes appear in a preview window to the right. If you have it set up correctly, you can open them in vim.

I actually wrote about getting ranger to read markdown files here.

To synchronise your notes:

function ns {
git -C /home/jimmy/notes pull
git -C /home/jimmy/notes add .
git -C /home/jimmy/notes commit -m 'notesync'
git -C /home/jimmy/notes push
}

When you type ns, git pulls the latest changes from the server if you are behind, then pushes any changes you have made.

Quicker searching

There’s a really nice way I found to search through the files. You need a couple more bits installed.

If you installed the above correctly you can do

cd ~/notes
sag searchterm

Then a list of results show consisting of files containing the word ‘searchterm’. They are numbered:

[1] Searchterm is really nice
[2] i like searchterm
[3] hi searchterm how are you

You pick the one you are looking for and open it like this:

F 2

It opens in vim if that’s set as your $EDITOR.

There’s also a vim extension you can use that does a similar thing. You just type :Ag searchterm and it brings up a list of files containing that word.

What I tried and eventually discarded

  • Evernote
    • A great system, but way too many features for me, plus I don’t like keeping my stuff with another company when I don’t have to.
  • Post-its
    • Sticky notes actually do 85% of what I need from this system, but it’s just too easy to lose them.
    • Also, my handwriting is terrible.
    • The other down sides of this are obvious
  • Google Keep
    • A great product, which I actually use for a slightly different purpose. However, it doesn’t work well with my ‘fire and forget’ rule.
    • It loads too slowly once you get to thousands of notes.
    • Again, the third party concern applies (although to be fair to Google, they sell it more as a ‘post-it note’ style thing, not as a store for essential information. Evernote encourages you to store your whole life in there).

Conclusion

Anyway that’s it. I’m always open to suggestions.