mirror of https://github.com/nirenjan/dotfiles.git
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
parent
a5321078e4
commit
e2f3a1a7bd
51
note
51
note
|
@ -1,6 +1,7 @@
|
||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
# Note taking script
|
# Notes manager for the command line
|
||||||
|
|
||||||
|
NOTES_VER="0.1a"
|
||||||
NOTES_DIR="$HOME/.notes"
|
NOTES_DIR="$HOME/.notes"
|
||||||
|
|
||||||
# Initialize with the default editor
|
# Initialize with the default editor
|
||||||
|
@ -17,12 +18,13 @@ notes_init() {
|
||||||
|
|
||||||
git init .
|
git init .
|
||||||
else
|
else
|
||||||
[ ! -z $1 ] && echo "Notes has already been initialized."
|
echo "Notes has already been initialized."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
make_title() {
|
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() {
|
title_to_name() {
|
||||||
|
@ -65,8 +67,8 @@ check_dir() {
|
||||||
|
|
||||||
help_cmd() {
|
help_cmd() {
|
||||||
echo '
|
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
|
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
|
Git repository. You can run this script by typing the following command
|
||||||
|
@ -77,18 +79,23 @@ Usage: note <command> <arguments>
|
||||||
Commands
|
Commands
|
||||||
--------
|
--------
|
||||||
|
|
||||||
Command Usage
|
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
|
new Follow this with the note name to create a new note
|
||||||
note
|
edit Follow this with the note name to edit an existing note
|
||||||
delete Follow this with the note name to delete a note
|
delete Follow this with the note name to delete a note
|
||||||
list Prints the list of available notes
|
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
|
init Run this the very first time to set up the folders
|
||||||
help Prints this help message
|
help Prints this help message
|
||||||
|
version Prints the version information
|
||||||
'
|
'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
version_info() {
|
||||||
|
echo "Notes Manager version $NOTES_VER"
|
||||||
|
}
|
||||||
|
|
||||||
parse_args() {
|
parse_args() {
|
||||||
note_cmd=$1
|
note_cmd=$1
|
||||||
shift
|
shift
|
||||||
|
@ -191,7 +198,7 @@ parse_args() {
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"init")
|
"init")
|
||||||
notes_init warn
|
notes_init
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"list")
|
"list")
|
||||||
|
@ -200,10 +207,20 @@ parse_args() {
|
||||||
ls -1 $note_arg
|
ls -1 $note_arg
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
"ver" | "version")
|
||||||
|
version_info
|
||||||
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
echo "Unrecognized command '$note_cmd'. Use help."
|
echo "Unrecognized command '$note_cmd'. Use help."
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_args $*
|
if [[ $# -lt 1 ]]
|
||||||
|
then
|
||||||
|
echo "Usage: note <command> <arguments>"
|
||||||
|
echo "Type 'note help' for detailed help"
|
||||||
|
else
|
||||||
|
parse_args $*
|
||||||
|
fi
|
||||||
|
|
Loading…
Reference in New Issue