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.
master
nirenjan 2013-01-23 22:20:06 -08:00
parent a5321078e4
commit e2f3a1a7bd
1 changed files with 34 additions and 17 deletions

37
note
View File

@ -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
@ -78,17 +80,22 @@ 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
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
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
}
if [[ $# -lt 1 ]]
then
echo "Usage: note <command> <arguments>"
echo "Type 'note help' for detailed help"
else
parse_args $*
fi