From e2f3a1a7bd03a8de46bbd599ee0ffcee4ff2d2e6 Mon Sep 17 00:00:00 2001 From: nirenjan Date: Wed, 23 Jan 2013 22:20:06 -0800 Subject: [PATCH] Fix note issues Fix the following issues in note 1. Always use a combo of lowercase letters, hyphen, underscore and numbers for the file name. This is taken from the title and uses sed to translate the uppercase letters to lowercase. Unfortunately, sed's translation mode doesn't support ranges, so we must use the full alphabet. 2. Add support for displaying version information. 3. Reformat the help display so it all fits in a single line. 4. Add checking to ensure that at least one argument is passed to note so that the parse_args routine doesn't barf an error with shift. 5. Remove argument checking in notes_init. It's called only by the init function, so there's no need to add a flag to control warnings. --- note | 51 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/note b/note index 060e866..8600851 100755 --- a/note +++ b/note @@ -1,6 +1,7 @@ -#!/bin/sh -# Note taking script +#!/bin/bash +# Notes manager for the command line +NOTES_VER="0.1a" NOTES_DIR="$HOME/.notes" # Initialize with the default editor @@ -17,12 +18,13 @@ notes_init() { git init . else - [ ! -z $1 ] && echo "Notes has already been initialized." + echo "Notes has already been initialized." fi } make_title() { - echo "$*" | sed 's/[^A-Za-z0-9_-]\+/-/g' + echo "$*" | sed 's/[^A-Za-z0-9_-]\+/-/g' | \ + sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/' } title_to_name() { @@ -65,8 +67,8 @@ check_dir() { help_cmd() { echo ' -Note taker for the Command Line -=============================== +Notes Manager for the Command Line +================================== This is a bash script that lets you take notes which are maintained in a Git repository. You can run this script by typing the following command @@ -77,18 +79,23 @@ Usage: note Commands -------- - Command Usage - new Follow this with the note name to create a new note - edit Follow this with the note name to edit an existing - note - delete Follow this with the note name to delete a note - list Prints the list of available notes - hist Displays the note history - init Run this the very first time to set up the folders - help Prints this help message + Command Usage + ------- ----- + new Follow this with the note name to create a new note + edit Follow this with the note name to edit an existing note + delete Follow this with the note name to delete a note + list Prints the list of available notes + history Displays the note history + init Run this the very first time to set up the folders + help Prints this help message + version Prints the version information ' } +version_info() { + echo "Notes Manager version $NOTES_VER" +} + parse_args() { note_cmd=$1 shift @@ -191,7 +198,7 @@ parse_args() { ;; "init") - notes_init warn + notes_init ;; "list") @@ -200,10 +207,20 @@ parse_args() { ls -1 $note_arg ;; + "ver" | "version") + version_info + ;; + *) echo "Unrecognized command '$note_cmd'. Use help." ;; esac } -parse_args $* +if [[ $# -lt 1 ]] +then + echo "Usage: note " + echo "Type 'note help' for detailed help" +else + parse_args $* +fi