GitBucket
4.20.0
Toggle navigation
Sign in
Files
Branches
1
Tags
Issues
Pull requests
Labels
Priorities
Milestones
Wiki
Forks
Jonathan
/
note
Browse code
Fixed bug in an if-statement.
master
1 parent
5cdd2d4
commit
040c9f72f0a6d9d537a36623cce45a70b21c420e
Jonathan Ström
authored
on 2 Apr 2017
Patch
Showing
1 changed file
note
Ignore Space
Show notes
View
note
#!/bin/bash author="Livila" version="2.0" filename=~/notefile filename_default=~/notefile nodate=0 para1="$1" para2="$2" 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 para1=$3 para2=$4 fi checkParameter() { # Check if there is any arguments, if there is an argument that # doesn't exist, append all of it to the notefile and exit. # However if it see it's left empty, go into adding multiple-line-mode. case "$1" in less | --less) less $filename exit 1 ;; edit | --edit) vi $filename exit 1 ;; vi | --vi) vi $filename exit 1 ;; gedit | --gedit) gedit $filename exit 1 ;; cat | --cat) cat $filename exit 1 ;; location | --location) echo "$filename"; exit 1 ;; author | --author) echo "The author of this program is $author."; exit 1 ;; version | --version) echo "Version $version"; exit 1 ;; help | ? | --help) echo -e 'Usage: note [--] [setfile <filepath>] [less|vi|gedit|help|author|version|nodate] Commands: [--]setfile|filename Set new temporary location of file [--]nodate Do not save the date for this note [--]less Show contents using "less" [--]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 [--]version Show current version Examples: note [leave empty or enter a command] Just like --setfile, but default value '$filename'. note This is a message that will be added to the notefile with date. You can create notes that are one line by directly typing it after note. note --setfile <filepath> [leave empty or enter a command] Will open note just as before, but using <filepath> instead.'; exit 1 ;; # Do not save the date. nodate | --nodate) nodate=1 ;; # If there are no parameters entered. "") echo 'Enter input or type :exit or :q to exit. :less to show contents.' read input saveDateOnce=0 # Loop until :exit or :q is entered. while [ "$input" != ":exit" ] && [ "$input" != ":q" ]; do # In case you want to have a quick overview of your text. if [ "$input" == ":less" ]; then less $filename else # Check if the date has been saved. if [ $saveDateOnce == 0 ] && [ $nodate == 0 ]; then date >> $filename saveDateOnce=1 fi echo "$input" >> $filename fi read input done exit 1 ;; # Save an instant note. *) 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. # Note: +1 parameter because of the function input. echo "${@:4}" >> $filename else # Write all parameters entered to the file. # 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}"
#!/bin/bash author="Livila" version="2.0" filename=~/notefile filename_default=~/notefile nodate=0 para1="$1" para2="$2" 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 para1=$3 para2=$4 fi checkParameter() { # Check if there is any arguments, if there is an argument that # doesn't exist, append all of it to the notefile and exit. # However if it see it's left empty, go into adding multiple-line-mode. case "$1" in less | --less) less $filename exit 1 ;; edit | --edit) vi $filename exit 1 ;; vi | --vi) vi $filename exit 1 ;; gedit | --gedit) gedit $filename exit 1 ;; cat | --cat) cat $filename exit 1 ;; location | --location) echo "$filename"; exit 1 ;; author | --author) echo "The author of this program is $author."; exit 1 ;; version | --version) echo "Version $version"; exit 1 ;; help | ? | --help) echo -e 'Usage: note [--] [setfile <filepath>] [less|vi|gedit|help|author|version|nodate] Commands: [--]setfile|filename Set new temporary location of file [--]nodate Do not save the date for this note [--]less Show contents using "less" [--]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 [--]version Show current version Examples: note [leave empty or enter a command] Just like --setfile, but default value '$filename'. note This is a message that will be added to the notefile with date. You can create notes that are one line by directly typing it after note. note --setfile <filepath> [leave empty or enter a command] Will open note just as before, but using <filepath> instead.'; exit 1 ;; # Do not save the date. nodate | --nodate) nodate=1 ;; # If there are no parameters entered. "") echo 'Enter input or type :exit or :q to exit. :less to show contents.' read input saveDateOnce=0 # Loop until :exit or :q is entered. while [ "$input" != ":exit" ] && [ "$input" != ":q" ]; do # In case you want to have a quick overview of your text. if [ "$input" == ":less" ]; then less $filename else # Check if the date has been saved. if [ $saveDateOnce == 0 ] && [$nodate == 0]; then date >> $filename saveDateOnce=1 fi echo "$input" >> $filename fi read input done exit 1 ;; # Save an instant note. *) 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. # Note: +1 parameter because of the function input. echo "${@:4}" >> $filename else # Write all parameters entered to the file. # 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}"
Show line notes below