diff --git a/sns.sh b/sns.sh index 4bbfa8c..a2be9c9 100755 --- a/sns.sh +++ b/sns.sh @@ -15,10 +15,10 @@ readonly CONFIG_FILE="$ROOT_DIR/sns.conf" # Section: Functions -function w_conf { +function create_sns_root { -if [ ! -r "$ROOT_DIR" ]; then mkdir -p "$ROOT_DIR"; fi -if [ ! -d "$TMP_DIR" ]; then mkdir -p "$TMP_DIR" ; fi +if [ ! -r "$ROOT_DIR" ]; then mkdir -p "$ROOT_DIR"; WILL_INIT="TRUE"; fi +if [ ! -d "$TMP_DIR" ]; then mkdir -p "$TMP_DIR" ; WILL_INIT="TRUE"; fi cat > "$CONFIG_FILE" << EOF @@ -45,6 +45,12 @@ PUBKEY="" EOF chmod 600 "$CONFIG_FILE" + +if [ "$WILL_INIT" == "TRUE" ]; then + printf "%s %s\n" "Environment initialized in" "$ROOT_DIR" +else + printf "%s\n" "Environment already initialized." +fi } function pause { read -rp " Press [Enter] to continue." @@ -123,7 +129,10 @@ function delete(){ fi } function edit(){ -if [ ! -r "$NOTE" ]; then +if [ -z "$EDITOR" ]; then + >&2 echo "Error no editor specified in environment." + exit +elif [ ! -r "$NOTE" ]; then echo "ERROR: Note cannot be opened for editing." exit 40; fi @@ -207,10 +216,7 @@ fi echo "$PROD_STR, $VER_STR" -if [ -z "$EDITOR" ]; then - >&2 echo "Error no editor specified in environment." - -elif [ -n "$ERR_NO_GPG" ]; then +if [ -n "$ERR_NO_GPG" ]; then >&2 echo " Error: Encryption was specified, but GPG is not installed." exit 100 elif [ -n "$ERR_NO_KEY" ]; then diff --git a/src/includes/create_sns_root.sns.sh b/src/includes/create_sns_root.sns.sh index 81cfb01..d3b8bf9 100644 --- a/src/includes/create_sns_root.sns.sh +++ b/src/includes/create_sns_root.sns.sh @@ -1,7 +1,7 @@ -function w_conf { +function create_sns_root { -if [ ! -r "$ROOT_DIR" ]; then mkdir -p "$ROOT_DIR"; fi -if [ ! -d "$TMP_DIR" ]; then mkdir -p "$TMP_DIR" ; fi +if [ ! -r "$ROOT_DIR" ]; then mkdir -p "$ROOT_DIR"; WILL_INIT="TRUE"; fi +if [ ! -d "$TMP_DIR" ]; then mkdir -p "$TMP_DIR" ; WILL_INIT="TRUE"; fi cat > "$CONFIG_FILE" << EOF @@ -28,4 +28,10 @@ PUBKEY="" EOF chmod 600 "$CONFIG_FILE" + +if [ "$WILL_INIT" == "TRUE" ]; then + printf "%s %s\n" "Environment initialized in" "$ROOT_DIR" +else + printf "%s\n" "Environment already initialized." +fi } diff --git a/src/includes/edit.sns.sh b/src/includes/edit.sns.sh index e63c412..91f0e7f 100644 --- a/src/includes/edit.sns.sh +++ b/src/includes/edit.sns.sh @@ -1,5 +1,8 @@ function edit(){ -if [ ! -r "$NOTE" ]; then +if [ -z "$EDITOR" ]; then + >&2 echo "Error no editor specified in environment." + exit +elif [ ! -r "$NOTE" ]; then echo "ERROR: Note cannot be opened for editing." exit 40; fi diff --git a/src/main/stage1.sns.sh b/src/main/stage1.sns.sh index af57da1..d0eadd1 100644 --- a/src/main/stage1.sns.sh +++ b/src/main/stage1.sns.sh @@ -27,10 +27,7 @@ fi echo "$PROD_STR, $VER_STR" -if [ -z "$EDITOR" ]; then - >&2 echo "Error no editor specified in environment." - -elif [ -n "$ERR_NO_GPG" ]; then +if [ -n "$ERR_NO_GPG" ]; then >&2 echo " Error: Encryption was specified, but GPG is not installed." exit 100 elif [ -n "$ERR_NO_KEY" ]; then diff --git a/src/main/stage2.sns.sh b/src/main/stage2.sns.sh index 97c0392..b62b775 100644 --- a/src/main/stage2.sns.sh +++ b/src/main/stage2.sns.sh @@ -16,7 +16,7 @@ else elif [ "$ARG" = "-p" ] || [ "$ARG" = "--print" ]; then PRINT="TRUE" elif [ "$ARG" = "-l" ] || [ "$ARG" = "--list" ]; then LIST="TRUE" elif [ "$ARG" = "-h" ] || [ "$ARG" == "--help" ]; then help; exit 0 - elif [ "$ARG" = "-w" ] || [ "$ARG" == "--wconf" ]; then create_sns_root; exit 0 + elif [ "$ARG" = "-i" ] || [ "$ARG" == "--init" ]; then create_sns_root; exit 0 else if [ -z "$NAME" ] && [ -n "$ARG" ]; then NAME="$ARG" elif [ -z "$NOTEBOOK" ] && [ -n "$ARG" ]; then NOTEBOOK="$ARG"