* Moved no editor warning to edit function

* Added message in create_sns_root showing SNS's environment was actually initialized
* Changed flag to create SNS's environment from -w to -i
This commit is contained in:
Jon-William Lewis
2016-01-31 21:30:39 -06:00
parent 77c3398c5f
commit ef1469762b
5 changed files with 29 additions and 17 deletions

22
sns.sh
View File

@@ -15,10 +15,10 @@ readonly CONFIG_FILE="$ROOT_DIR/sns.conf"
# Section: Functions # Section: Functions
function w_conf { function create_sns_root {
if [ ! -r "$ROOT_DIR" ]; then mkdir -p "$ROOT_DIR"; fi if [ ! -r "$ROOT_DIR" ]; then mkdir -p "$ROOT_DIR"; WILL_INIT="TRUE"; fi
if [ ! -d "$TMP_DIR" ]; then mkdir -p "$TMP_DIR" ; fi if [ ! -d "$TMP_DIR" ]; then mkdir -p "$TMP_DIR" ; WILL_INIT="TRUE"; fi
cat > "$CONFIG_FILE" << EOF cat > "$CONFIG_FILE" << EOF
@@ -45,6 +45,12 @@ PUBKEY=""
EOF EOF
chmod 600 "$CONFIG_FILE" 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 { function pause {
read -rp " Press [Enter] to continue." read -rp " Press [Enter] to continue."
@@ -123,7 +129,10 @@ function delete(){
fi fi
} }
function edit(){ 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." echo "ERROR: Note cannot be opened for editing."
exit 40; exit 40;
fi fi
@@ -207,10 +216,7 @@ fi
echo "$PROD_STR, $VER_STR" echo "$PROD_STR, $VER_STR"
if [ -z "$EDITOR" ]; then if [ -n "$ERR_NO_GPG" ]; then
>&2 echo "Error no editor specified in environment."
elif [ -n "$ERR_NO_GPG" ]; then
>&2 echo " Error: Encryption was specified, but GPG is not installed." >&2 echo " Error: Encryption was specified, but GPG is not installed."
exit 100 exit 100
elif [ -n "$ERR_NO_KEY" ]; then elif [ -n "$ERR_NO_KEY" ]; then

View File

@@ -1,7 +1,7 @@
function w_conf { function create_sns_root {
if [ ! -r "$ROOT_DIR" ]; then mkdir -p "$ROOT_DIR"; fi if [ ! -r "$ROOT_DIR" ]; then mkdir -p "$ROOT_DIR"; WILL_INIT="TRUE"; fi
if [ ! -d "$TMP_DIR" ]; then mkdir -p "$TMP_DIR" ; fi if [ ! -d "$TMP_DIR" ]; then mkdir -p "$TMP_DIR" ; WILL_INIT="TRUE"; fi
cat > "$CONFIG_FILE" << EOF cat > "$CONFIG_FILE" << EOF
@@ -28,4 +28,10 @@ PUBKEY=""
EOF EOF
chmod 600 "$CONFIG_FILE" 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
} }

View File

@@ -1,5 +1,8 @@
function edit(){ 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." echo "ERROR: Note cannot be opened for editing."
exit 40; exit 40;
fi fi

View File

@@ -27,10 +27,7 @@ fi
echo "$PROD_STR, $VER_STR" echo "$PROD_STR, $VER_STR"
if [ -z "$EDITOR" ]; then if [ -n "$ERR_NO_GPG" ]; then
>&2 echo "Error no editor specified in environment."
elif [ -n "$ERR_NO_GPG" ]; then
>&2 echo " Error: Encryption was specified, but GPG is not installed." >&2 echo " Error: Encryption was specified, but GPG is not installed."
exit 100 exit 100
elif [ -n "$ERR_NO_KEY" ]; then elif [ -n "$ERR_NO_KEY" ]; then

View File

@@ -16,7 +16,7 @@ else
elif [ "$ARG" = "-p" ] || [ "$ARG" = "--print" ]; then PRINT="TRUE" elif [ "$ARG" = "-p" ] || [ "$ARG" = "--print" ]; then PRINT="TRUE"
elif [ "$ARG" = "-l" ] || [ "$ARG" = "--list" ]; then LIST="TRUE" elif [ "$ARG" = "-l" ] || [ "$ARG" = "--list" ]; then LIST="TRUE"
elif [ "$ARG" = "-h" ] || [ "$ARG" == "--help" ]; then help; exit 0 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 else
if [ -z "$NAME" ] && [ -n "$ARG" ]; then NAME="$ARG" if [ -z "$NAME" ] && [ -n "$ARG" ]; then NAME="$ARG"
elif [ -z "$NOTEBOOK" ] && [ -n "$ARG" ]; then NOTEBOOK="$ARG" elif [ -z "$NOTEBOOK" ] && [ -n "$ARG" ]; then NOTEBOOK="$ARG"