top | item 15377015

Simple note taking from the command line

152 points| djug | 8 years ago |dev.to | reply

56 comments

order
[+] lucb1e|8 years ago|reply
So if I'm reading this correctly, you need to quote your text, and it can't be multi-line... why not this:

    alias notes='cat >> ~/notes'
Just hit ctrl+c (stops cat) or ctrl+d (signals EOF) when you're done writing. No quoting, special characters that might act funny, line or size limits, etc.
[+] dylanpyle|8 years ago|reply
I've been using a variation on this for a bit:

    (echo && date && cat) >> ~/notes.txt
Adds a newline and datestamp above each note group
[+] jasonm23|8 years ago|reply
Depending on the shell in use C-c (will|won't) write to the redirected output file.

C-d remains constant, but it's irritating that there's no way to consistently abort.

To deal with this our edit target needs to be a temporary file which we subsequently bless, append to the notes file and then trash.

Keeping notes open in an editor buffer that I can jump to easily, and manually:

>> notes.md

From the command line gains me all the utility I need while using a modern machine and zsh.

Of course, if I time travel, the GP trick is useful on old ultrix machines.

[+] corobo|8 years ago|reply
Anyone else use http://jrnl.sh/ ?

I prefer it over echoing into a file because it has more advanced display features - such as by date - and topics (hashtags [don't forget to escape the hash!], or @tags)

Got the journal files stored in Dropbox so they're everywhere I am

[+] balladeer|8 years ago|reply
I have it setup but don’t use it as my main notes app. That would still be Simplenote (with Notational Velocity on desktop).

Mainly because I figured would rather use GUI for notes on both desktop and mobile. Maybe one of these days I should give Standard Notes a try (https://standardnotes.org). It’s OSS and client side encrypted (afaik).

[+] pwelch|8 years ago|reply
Yes! Jrnl is awesome and I've been using it for awhile now. Highly recommend it.
[+] pweissbrod|8 years ago|reply
Not as simple but well worth the extra weight would be org-mode. I personally find the vim-orgmode a balance between the full power of org vs my reliance on vim for day-to-day operations but I must admit I'm sometimes jealous of the power I see in emacs for this.
[+] uep|8 years ago|reply
I have been a long-time Emacs user and I finally just started learning org-mode. I wish I had started earlier. Previously, I had used Zim to do my note-taking, but org-mode is just so much better in every way.

I have a feeling it's going to be my gateway into more heavy LaTeX usage for all manner of documents. The ability to evaluate code during document generation is a big deal to me.

[+] JoshMnem|8 years ago|reply
Another vote for Org Mode. I just added this idea from the post to my laptop (adding a timestamp and sending it into an org-mode file):

    note() {
        echo "`date +%s`\t$1" >> ~/org/unsorted-notes.org
    }
[+] lysium|8 years ago|reply
Sounds as if you will love spacemacs!
[+] Fletch137|8 years ago|reply
I like to use: `alias sp='vim ~/notes/scratchpad-$(date +"%m-%d-%Y-%T")'`
[+] dheera|8 years ago|reply
I use

    #!/bin/bash
    mkdir -p ~/Dropbox/scratch/$(date +"%Y-%m-%d")
    vim ~/Dropbox/scratch/$(date +"%Y-%m-%d")/$(date +"%Y-%m-%d-%H-%M-%S")
for convenient sorting by date, and throw stuff in Dropbox for automatic syncing across my machines.
[+] Diederich|8 years ago|reply
This is neat, and there's a lot of interesting comments and pointers elsewhere in these comment threads.

What I've been doing (for the last 25 years or so) is simple. I always keep a window open, visible in all virtual desktops, on the bottom right of my screen, with: vi ~/notes/notes

For somewhat less than the last 25 years, ~/notes is an encrypted git repo. I have a cron that, minutely, adds, commits, pulls and pushes to a couple of my servers on the Internet.

I generally have one of these for each company I work for, and another one that I've used for all things personal.

[+] perryprog|8 years ago|reply
Do you have code for this on GitHub?
[+] cat199|8 years ago|reply
or just learn ed/ex, etc.

just as fast and you can actually edit when needed.

    $ ed ~/.todo
    a
    this is a new bloat 
    .
    s/bloat/note/
    this is a new note
    w
    q
    $ cat ~/.todo
    this is a new note
    $ ed ~/.todo
    19
    a
    this is another note.
    it goes across more lines.
    woo!
    .
    w
    q
    $
[+] rhizome|8 years ago|reply
Take note, people: ed is the standard text editor.
[+] hathym|8 years ago|reply
now go and pitch VCs for you notes taking app
[+] lillesvin|8 years ago|reply
Why .md when you're inputting the command as plain text without any markdown?
[+] delinka|8 years ago|reply
Why not just have the flexibility of adding markdown whenever you feel like it (and not when you don't)? Now, you've got a file a markdown renderer can render whether or not you used markdown.
[+] lottin|8 years ago|reply
Do you really need a function for that?

cat >> ~/notes

does the same thing.

[+] ConfucianNardin|8 years ago|reply
This will work fine until the day when you mistype >> into >, and all your notes are gone.
[+] tyingq|8 years ago|reply
rlwrap cat >> ~/notes

Would give you some rudimentary readline editing capability.

[+] nsb1|8 years ago|reply
Small improvements: - No quotes needed - Just type 'notes' alone to less the file

notes() {

        if [ "$1" == "" ]; then

                less $HOME/notes.md

        else

                echo $@ >> $HOME/notes.md

        fi

}
[+] vacri|8 years ago|reply
Combination of your improvements and the first commentor's in the link

- 'notes' by itself views the file (interactive shell only)

- 'notes' with args, the args are appended to file (original function)

- 'notes' with heredoc (or any piped data) allows for multiline notes

    notes() {
      if [ -n "$1" ]; then
        echo $@ >> "$HOME/notes.md"
      else
        # detect if we're in a tty or a pipe
        if [ -t 0 ]; then
          less "$HOME/notes.md"
        else
          cat - >> "$HOME/notes.md"
        fi
      fi
    }



    usage:
    $ notes 1
    $ notes 1 2 3
    $ notes <<EOF
    > this is a 
    > multiline note
    > EOF
    $ uptime | notes
    $ notes
    (opens less with the following content)
    1
    1 2 3
    this is a 
    multiline note
     23:22:06 up 3 days, 11:41,  1 user,  load average: 0.25, 0.15, 0.26
[+] hk__2|8 years ago|reply
You still need quotes to prevent the shell from expanding $variables and globs. It’ll also mangle your spaces (try with `notes foo<space><space>bar`: it saves it as "foo<space>bar") due to the $@.
[+] tincholio|8 years ago|reply
This probably sets the lowest bar for note taking...
[+] digitalsushi|8 years ago|reply
It's like the camera-you-have being best - if my fingers remember how to take notes, I'll take notes.
[+] jaddood|8 years ago|reply
This is extremely similar to the 'microscopic planner for shell' that I wrote and often use.

Take a look at https://news.ycombinator.com/item?id=14126006

I also add a few aliases to make it even quicker:

  alias mcr='mplan create'
  alias msh='mplan show'
  alias mrm='mplan remove'
  alias mclear='mplan remove \*'
This will provide (in my opinion) both a very simple way to take notes and a somewhat mature and usable note taking 'program'.
[+] vermaden|8 years ago|reply
Such 'notes' function can seem 'useful' at first glance, but how You gonna 'organize these notes, for example after You have used it for about a year, or several years?

I prefer other approach.

Everytime I get to know some new switch for a command, or new use for them, or even a new command, I create ~/man/command file with examples and commends inside, like ~/man/tar or ~/man/gstat or ~/man/xorg.conf.

This way its already organized and you can grep -r 'something' ~/man for the thing you need.

My $0.02.

[+] talideon|8 years ago|reply
I have this: https://github.com/kgaughan/dotfiles/blob/master/local/bin/n...

It allows the editing of notes for a given day, listing of all notes, and display of a note for a given day, defaulting to today if no date is provided.

I keep meaning to add support for RCS or some other form of basic version control, but it's never been that much of an issue.

[+] reacharavindh|8 years ago|reply
Would any such note-taking solution work across several ssh sessions?

I'm a small scale sysadmin, SSHing into multiple servers configured by my predecessors. I'd love to be able to some command | notes.txt or whatever. And no, I don't have my home directory mounted at all locations the same way. I even need to login as different user for different machines. The command factor is my Mac and Terminal.app

[+] amdavidson|8 years ago|reply
I'm going to assume that you can edit .bashrc for these as that's the premise from the original article.

You could adjust it so that it uses a central notes store on one ssh host pretty easily with something like:

  notes() {
      echo $1 | ssh user@remotehost "cat >> ~/notes.md"
  }
then you probably need something like

  read_notes() {
      ssh user@remotehost "cat ~/notes.md" | more
  }
[+] Flimm|8 years ago|reply
I have a very similar script that lets me write notes to a file with today's filestamp. I use it to keep track of what I've done on which days.
[+] stevekemp|8 years ago|reply
Yup, I have a script `worklog` which boils down to this:

    #!/bin/sh
    mkdir ~/.worklog || true
    if [ -z "$1" ]; then
       cat ~/.worklog/$(date +%w).md
    else
       echo "$(date): $*" >> ~/.worklog/$(date +%w).md
    fi

That gives a file per-week which can either have contents appended to it, or viewed. Usage is the obvious:

    $ worklog  "I did some stuff"
    $ worklog  [shows the output]
[+] indigodaddy|8 years ago|reply
You could decentish vi bindings within this by using vi mode for bash I'd guess? I'd probably usually just end up vim notes.md5 TBH.