Pastebin is 300% more awesome when you are logged in. Sign Up, it's FREE!
Guest

Untitled

By: a guest on Dec 28th, 2010  |  syntax: Bash  |  size: 0.81 KB  |  hits: 57  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. nn() {
  2.     local NOTE_FILE=$HOME/.notes
  3.     #if file doesn't exist, create it
  4.     [[ -f "$NOTE_FILE" ]] || touch "$NOTE_FILE"
  5.    
  6.     #no arguments, edit file
  7.     if [[ -z "$1" ]]; then
  8.        vim "+set number" "$NOTE_FILE"
  9.     elif (( $1 )); then tail -"$1" "$NOTE_FILE"
  10.     elif [[ "$1" == "-s" ]]; then /bin/grep -E --color=always -i -C 1 "$2" "${NOTE_FILE}"
  11.     elif [[ "$1" == "-h" || $1 == "--help" ]]; then
  12.         printf "nn [options|note]: Make quick notes\n"
  13.         printf "Options: <note>\t\twrite <note> to '${NOTE_FILE}'\n"
  14.         printf "\t\t\tshow '${NOTE_FILE}'\n"
  15.         printf "\t<number>\tshow last <number> lines of '${NOTE_FILE}'\n"
  16.         printf "\t-s <regex>\tsearch '${NOTE_FILE}' for <regex>\n"
  17.     #append all arguments to file
  18.     else
  19.         echo ">> '$@'" >> "$NOTE_FILE"
  20.     fi
  21. }