Ben Oliver

Banner image for Taking quick notes in the terminal
technology

Taking quick notes in the terminal

A quick way to take down information from the terminal.
23 January 2016

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:

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

Cons

Dependencies

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

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 here6.

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 markdown7 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 here8.

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 extension11 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

Conclusion

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

Reply by email