diff --git a/src/header.src.sh b/src/header.src.sh index 47ba0f7..c83804f 100644 --- a/src/header.src.sh +++ b/src/header.src.sh @@ -16,6 +16,10 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# On advice from http://redsymbol.net/articles/unofficial-bash-strict-mode/ +set -euo pipefail +IFS=$'\n\t' + # Prevent freak accidents involving the root directory if [ -z "$HOME" ]; then HOME=/home/"$(whoami)"; fi @@ -32,6 +36,15 @@ readonly RED_COLOR='\033[1;31m' readonly YELLOW_COLOR='\033[1;33m' readonly RESET_COLOR='\033[0m' +# Config variables +EXT="" +EDITOR="" +DATE_FMT="" +ENCRYPTION="" +PUBKEY="" +VCTL="" + + # Signals NO_HEADER="" diff --git a/src/libEncryption.src.sh b/src/libEncryption.src.sh index 8c4c7d4..ac9df71 100644 --- a/src/libEncryption.src.sh +++ b/src/libEncryption.src.sh @@ -27,7 +27,7 @@ function decrypt(){ # This function, given a file to decrypt, will attempt to decrypt the file # against the specified recipient's private key, and print the result to # stdout. - read -s -p "Please enter GPG passphrase for id $PUBKEY: " PASSPHRASE + read -s -rp "Please enter GPG passphrase for id $PUBKEY: " PASSPHRASE gpg\ --passphrase "$PASSPHRASE"\ --decrypt "$FILE"\ diff --git a/src/libSNS.src.sh b/src/libSNS.src.sh index e29419e..de3be27 100644 --- a/src/libSNS.src.sh +++ b/src/libSNS.src.sh @@ -31,8 +31,8 @@ function create(){ # If the note's notebook/section does not exist, # create the appropriate folders. - if [ ! -d "$(dirname $FILE)" ]; then - mkdir -p "$(dirname $FILE)" + if [ ! -d "$(dirname "$FILE")" ]; then + mkdir -p "$(dirname "$FILE")" fi # Write the standard note header @@ -58,7 +58,7 @@ function delete(){ if [ -e "$FILE" ]; then printf "$RED_COLOR!!$RESET_COLOR %s%s" "Delete " "${NOTE%.*}" - read -p " (y/N) " YN + read -rp " (y/N) " YN case "$YN" in Y|y) rm "$FILE" diff --git a/src/libStore.src.sh b/src/libStore.src.sh index 4fe89ff..89d2713 100644 --- a/src/libStore.src.sh +++ b/src/libStore.src.sh @@ -71,8 +71,8 @@ function verify_store { done } function verctl { - "$@" - if [ $2 == "init" ]; then + ARGS=("$@") + if [ "${ARGS[1]}" == "init" ]; then "$VCTL" add . "$VCTL" commit -m "Initial Commit" fi diff --git a/src/sns.src.sh b/src/sns.src.sh index 4a479e3..b5f4e49 100644 --- a/src/sns.src.sh +++ b/src/sns.src.sh @@ -46,7 +46,7 @@ if [ "$ENCRYPTION" == "TRUE" ]; then # All is good. If any previously unencrypted notes exist, encrypt them. # No harm in extra security. else - find . -type f -name "*.$EXT" | grep -v "gpg" | while read TMP_NOTE; do + find . -type f -name "*.$EXT" | grep -v "gpg" | while read -r TMP_NOTE; do NOTE="${TMP_NOTE%.$EXT}.gpg.$EXT" encrypt if [ -r "$NOTE" ]; then @@ -65,10 +65,10 @@ else if [ ! -r "$NOTES_DIR"/.do_not_decrypt ]; then if [ -n "$(find "$NOTES_DIR" -type f -name "*.gpg.$EXT" > /dev/null)" ]; then while true; do - read -p "Would you like to de-encrypt previously encrypted notes? " YN + read -rp "Would you like to de-encrypt previously encrypted notes? " YN case $YN in [Yy]* ) - read -s -p "Please enter your passphrase: " PASSPHRASE + read -s -rp "Please enter your passphrase: " PASSPHRASE cd "$NOTES_DIR" find . -type f -name "*.gpg.$EXT" | while read -r NOTE; do gpg\ @@ -101,9 +101,9 @@ fi #============================================================================== # Stage 2: Argument Parsing #============================================================================== -if [ -z "$1" ]; then help; exit 20 +if [ ! "$@" ]; then help; exit 20 else - ARGS=("${@}") + ARGS=("$@") declare -i INDEX INDEX=0 for ARG in "$@"; do