Advertisement
Guest User

Untitled

a guest
Dec 28th, 2010
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.81 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement