DEV Community

Ricardo Molina
Ricardo Molina

Posted on • Edited on

Simple note taking from the command line

This is a simple function that can be called from the command line, just like if it was a regular command. It is a quick way of taking notes and storing them in a text file.

Just add the following lines to your ~/.bashrc:

# My function to take quick notes on useful commands
notes() {
    echo $1 >> $HOME/notes.md
}
Enter fullscreen mode Exit fullscreen mode

It can be used like this:

$ notes "my_command -which -I -want -to remember"
Enter fullscreen mode Exit fullscreen mode

You can read your notes like this:

$ more ~/notes.md
Enter fullscreen mode Exit fullscreen mode

Latest comments (28)

Collapse
 
avalander profile image
Avalander

Lovely trick, thanks for sharing!

Collapse
 
cannuhlar profile image
Can Nuhlar

I recently wrote a python script to do this sort of thing. You can create gists or retrieve gists with it. It takes input from stdin so I guess you can use it to take notes too. Here check it out: github.com/CanNuhlar/CLI-Gist-Client

Collapse
 
rrampage profile image
Raunak Ramakrishnan

A minimal tool I use for command line notes is jrnl.
Installing it is as simple as pip install jrnl
A note can be created by jrnl today at 3pm : Subject. Content.
It is especially useful when debugging, for revisiting assumptions.

Collapse
 
rssi profile image
rSSi • Edited

that's how i did it:
in .bash_aliases

to add an entry
how() { echo "$@" | tee -a ~/Dropbox/howto.txt; }

to display the notes taken
alias howto='more ~/Dropbox/howto.txt'

Collapse
 
gkchestertron profile image
John Fellman

I love this - and ran away with it a bit - here is a version that also allows editing in vim and making the notes distributable with git. Also lets you serve a pretty version with grip if you have it.

#!/bin/bash

note() {
  # start a new heading and append from stdout
  if [ ! -z "$1" ]; then
    clear
    echo "" >> "$HOME/notes/notes.md"
    echo "## $@" >> "$HOME/notes/notes.md"
    cat "$HOME/notes/notes.md"
    cat - >> "$HOME/notes/notes.md"
    clear
    cat "$HOME/notes/notes.md"

  # append to file from stdout
  else
    clear
    cat "$HOME/notes/notes.md"
    cat - >> "$HOME/notes/notes.md"
    clear
    cat "$HOME/notes/notes.md"
  fi
}

notes() {
  cur_dir=$(pwd)

  if [ ! -z "$1" ]; then
    # commit and push if args are exactly "push"
    if [ "$1" = "push" ]; then
      cd "$HOME/notes"
      git add -A
      git commit -m "update notes"
      git push
      cd $cur_dir

    # pull from github if args are exactly "pull"
    elif [ "$1" = "pull" ]; then
      cd "$HOME/notes"
      git pull
      cd $cur_dir

    # serve with grip if args are exactly "serve"
    elif [ "$1" = "serve" ]; then
      open "http://localhost:6419"
      grip "$HOME/notes/notes.md"

    # open vim to search of the args
    else
      escaped=$(echo "$@" | sed s/\ /\\\\\ /g)
      echo $escaped
      vim +/"$escaped" "$HOME/notes/notes.md"
    fi

  # just open the notes
  else
    vim + "$HOME/notes/notes.md"
  fi
}
Collapse
 
roger profile image
Roger Stach

You could also make this into a time journal to note how you feel on certain time, it's the same thing.

Collapse
 
roger profile image
Roger Stach

I've created the system only for me since I don't to deal with auth and stuff. It has two versions, one on the web and the other one on terminal running on NodeJS. I use Firebase as my database.

Collapse
 
maestromac profile image
Mac Siri

Wow nice!, this is so useful.

Collapse
 
xochilpili profile image
xOCh • Edited
notes(){
   if [ ! -z "$1" ]; then
       echo "[" $(date +"%Y%m%d %H:%M:%S"@$(hostname)"]" "@" >> "$HOME/notes.md";
   else
       if [ ! -f "$HOME/notes.md" ]; then
           echo "No notes!";
           #touch "$HOME/notes.md";
           exit 0;
       else
           cat - >> "$HOME/notes.md";
           # or cat "$HOME/notes.md"; for show all notes :P
       fi
   fi
}
Collapse
 
ttugates profile image
Michael Stramel

And in Windoze Cmd its.. copy con mynotes.txt with Shift + F6 to exit. :)

Collapse
 
adamthiede profile image
Adam Thiede

Nice! I created a similar thing for PowerShell just a while back.

function noteit {
  Param(
    [Parameter(Mandatory=$true)]
    [string]$data
  )

  set-variable curdatetime $(get-date -format yyyy-MM-dd_HH_mm)
  set-variable title $notes\$curdatetime.txt

  if(Test-Path -LiteralPath $title) {
    #echo $curdatetime >> $title
    echo $data >> $title
    echo "note appended at $title"
  }
  else {
    touch $title
    echo $curdatetime > $title
    echo $data >> $title
  echo "note created at $title"
  }
}


``