diff --git a/note b/note index c684541..bfed245 100644 --- a/note +++ b/note @@ -3,20 +3,26 @@ author="Livila" version="2.0" filename=~/notefile -para="$1" +filename_default=~/notefile +nodate=0 +para1="$1" +para2="$2" -if [ "$1" == "--setfile" ]; then +if [[ $1 == "--setfile" || $1 == "setfile" || $1 == "--filename" || $1 == "--filename" ]]; then # Check if the file location is entered, exit if not. if [[ -z $2 ]]; then exit 1 fi filename=$2 - para=$3 + para1=$3 + para2=$4 fi -# Check if there is any arguments, if there is append all of it. -case "$para" in +checkParameter() { + +# Check if there is any arguments, if there isn't append all of it to the notefile. +case "$1" in less | --less) less $filename @@ -60,14 +66,14 @@ help | ? | --help) echo -e 'Usage: - note [[--]setfile ] [[--][less|vi|gedit|help|author|version]] + note [--] [setfile ] [less|vi|gedit|help|author|version|nodate] Commands: [--]setfile: Set new temporary location of file + [--]nodate: Do not save the date for this note [--]less Show contents using "less" - [--]vi Edit contents using "vi" - [--]gedit Edit contents using "gedit" - [--]cat Print info using "cat". + [--]vi|gedit Edit contents using "vi" or "gedit" + [--]cat Print info using "cat" [--]location Show file location [--]help Show this help message [--]author Show the author @@ -86,6 +92,12 @@ ;; +# Do not save the date. +nodate | --nodate) + nodate=1 +;; + + # If there are no parameters entered. "") @@ -102,7 +114,7 @@ less $filename else # Check if the date has been saved. - if [ $saveDateOnce == 0 ]; then + if [ $saveDateOnce == 0 ] && [$nodate == 0]; then date >> $filename saveDateOnce=1 fi @@ -111,22 +123,38 @@ read input done + + exit 1 ;; # Save an instant note. *) - date >> $filename - if [ "$1" == "--setfile" ]; then + if [ $nodate == 0 ]; then + date >> $filename + fi + + # Since this is a function with 1 parameter and then all other + # paramters, the normal parameters starts at $2. + if [ $filename != $filename_default ]; then # Start from the third input parameter and write to the file. - echo "${@:3}" >> $filename + # Note: +1 parameter because of the function input. + echo "${@:4}" >> $filename else # Write all parameters entered to the file. - echo "$@" >> $filename - fi - exit 1 + # Note: Start from 1 extra because of the function input. + echo "${@:2}" >> $filename + fi + + exit 1 ;; esac +} #end of checkParameter() + + +checkParameter $para1 $@ +checkParameter $para2 "${@:2}" +