Reworked print function

This commit is contained in:
Jon-William Lewis
2016-01-25 21:00:43 -06:00
parent 8fc731aaa0
commit 2d8db83c3c
6 changed files with 29 additions and 95 deletions

View File

@@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
PROD_STR="Simple Note System" PROD_STR="Simple Note System"
VER_STR="v2.0a6" VER_STR="v2.0a7"
cat << EOF cat << EOF
#!/bin/bash #!/bin/bash

51
sns.sh
View File

@@ -85,9 +85,7 @@ function decrypt(){
# output file, "$NOTE", will decrpyt $TARGET to $NOTE against $PUBKEY's private # output file, "$NOTE", will decrpyt $TARGET to $NOTE against $PUBKEY's private
# GPG key. # GPG key.
if [ ! -d "$ROOT_DIR"/tmp ]; then mkdir "$ROOT_DIR"/tmp; fi gpg -d "$NOTE"
TARGET="$TMP_DIR/$RANDOM"
gpg -d "$NOTE" > "$TARGET"
} }
function create(){ function create(){
if [ -e "$NOTE" ]; then if [ -e "$NOTE" ]; then
@@ -133,7 +131,8 @@ fi
if [ "$ENCRYPTION" == "TRUE" ]; then if [ "$ENCRYPTION" == "TRUE" ]; then
cp "$NOTE" "$NOTE".bk cp "$NOTE" "$NOTE".bk
decrypt if [ ! -d "$ROOT_DIR"/tmp ]; then mkdir "$ROOT_DIR"/tmp; fi
decrypt > "$TMP_DIR/$RANDOM"
else TARGET="$NOTE"; fi else TARGET="$NOTE"; fi
@@ -146,58 +145,26 @@ if [ "$ENCRYPTION" == "TRUE" ]; then
encrypt; encrypt;
if [ -r "$NOTE" ]; then rm "$NOTE".bk; fi if [ -r "$NOTE" ]; then rm "$NOTE".bk; fi
fi fi
} }
function print(){ function print(){
if [ "$PRINT" == "TRUE" ]; then if [ -r "$NOTE" ]; then
if [ -r "$NOTE" ] || [ -r "${NOTE%.*}" ]; then
if [ -z "$CREATE" ]; then if [ -z "$CREATE" ]; then
if [ "$ENCRYPTION" == "TRUE" ]; then if [ "$ENCRYPTION" == "TRUE" ]; then
openssl enc -d -aes-256-cbc -in "${NOTE%.*}" -pass pass:"$ENC_KEY" decrypt
else else
cat "$NOTE" cat "$NOTE"
echo "" >> "$NOTE"
fi fi
else else
echo "" printf "\nERROR: Note cannot be found.\n"
echo "ERROR: Note cannot be found."
echo ""
fi
fi fi
fi fi
} }
function list(){ function list(){
if [ -d "$BASE_DIR"/"$NOTEBOOK" ]; then if [ -d "$BASE_DIR"/"$NOTEBOOK" ]; then
printf "\nNotes in %s:\n" "$(basename "$NOTEBOOK")" printf "+%s\n" "$NOTEBOOK"
find "$BASE_DIR"/"$NOTEBOOK" -type f | while read NOTE; do
NOTES=( printf " -%s\n" "$(basename $NOTE | cut -d . -f 1)"
$(find "$BASE_DIR"/"$NOTEBOOK" -name "*.$EXT" -print0 |\
sed s:"$BASE_DIR"/"$NOTEBOOK"/: " " :g |\
sed -e s:".$EXT"::g | tr "/" " ")
)
let i=0
for NOTE in "${NOTES[@]}"; do
if [ -d "$BASE_DIR"/"$NOTEBOOK"/"$NOTE" ]; then
if [ "$LAST_SECTION" != "$NOTE" ]; then
printf " Section: %s\n" "$NOTE"
fi
LAST_SECTION="$NOTE"
else
#if [ $(($i % 1)) -eq 0 ]; then
# printf "\n "
#fi
printf " %s\n" "$NOTE"
fi
let i++
done done
printf "\n"
else
echo ""
echo "ERROR: Notebook $NOTEBOOK does not exist."
echo ""
fi fi
} }
# End Section: Functions # End Section: Functions

View File

@@ -6,7 +6,8 @@ fi
if [ "$ENCRYPTION" == "TRUE" ]; then if [ "$ENCRYPTION" == "TRUE" ]; then
cp "$NOTE" "$NOTE".bk cp "$NOTE" "$NOTE".bk
decrypt if [ ! -d "$ROOT_DIR"/tmp ]; then mkdir "$ROOT_DIR"/tmp; fi
decrypt > "$TMP_DIR/$RANDOM"
else TARGET="$NOTE"; fi else TARGET="$NOTE"; fi
@@ -19,7 +20,4 @@ if [ "$ENCRYPTION" == "TRUE" ]; then
encrypt; encrypt;
if [ -r "$NOTE" ]; then rm "$NOTE".bk; fi if [ -r "$NOTE" ]; then rm "$NOTE".bk; fi
fi fi
} }

View File

@@ -12,7 +12,5 @@ function decrypt(){
# output file, "$NOTE", will decrpyt $TARGET to $NOTE against $PUBKEY's private # output file, "$NOTE", will decrpyt $TARGET to $NOTE against $PUBKEY's private
# GPG key. # GPG key.
if [ ! -d "$ROOT_DIR"/tmp ]; then mkdir "$ROOT_DIR"/tmp; fi gpg -d "$NOTE"
TARGET="$TMP_DIR/$RANDOM"
gpg -d "$NOTE" > "$TARGET"
} }

View File

@@ -1,31 +1,8 @@
function list(){ function list(){
if [ -d "$BASE_DIR"/"$NOTEBOOK" ]; then if [ -d "$BASE_DIR"/"$NOTEBOOK" ]; then
printf "\nNotes in %s:\n" "$(basename "$NOTEBOOK")" printf "+%s\n" "$NOTEBOOK"
find "$BASE_DIR"/"$NOTEBOOK" -type f | while read NOTE; do
NOTES=( printf " -%s\n" "$(basename $NOTE | cut -d . -f 1)"
$(find "$BASE_DIR"/"$NOTEBOOK" -name "*.$EXT" -print0 |\
sed s:"$BASE_DIR"/"$NOTEBOOK"/: " " :g |\
sed -e s:".$EXT"::g | tr "/" " ")
)
let i=0
for NOTE in "${NOTES[@]}"; do
if [ -d "$BASE_DIR"/"$NOTEBOOK"/"$NOTE" ]; then
if [ "$LAST_SECTION" != "$NOTE" ]; then
printf " Section: %s\n" "$NOTE"
fi
LAST_SECTION="$NOTE"
else
#if [ $(($i % 1)) -eq 0 ]; then
# printf "\n "
#fi
printf " %s\n" "$NOTE"
fi
let i++
done done
printf "\n"
else
echo ""
echo "ERROR: Notebook $NOTEBOOK does not exist."
echo ""
fi fi
} }

View File

@@ -1,19 +1,13 @@
function print(){ function print(){
if [ "$PRINT" == "TRUE" ]; then if [ -r "$NOTE" ]; then
if [ -r "$NOTE" ] || [ -r "${NOTE%.*}" ]; then
if [ -z "$CREATE" ]; then if [ -z "$CREATE" ]; then
if [ "$ENCRYPTION" == "TRUE" ]; then if [ "$ENCRYPTION" == "TRUE" ]; then
openssl enc -d -aes-256-cbc -in "${NOTE%.*}" -pass pass:"$ENC_KEY" decrypt
else else
cat "$NOTE" cat "$NOTE"
echo "" >> "$NOTE"
fi fi
else else
echo "" printf "\nERROR: Note cannot be found.\n"
echo "ERROR: Note cannot be found."
echo ""
fi
fi fi
fi fi
} }