Simple Note System v2.0a2
Changes: Split script into several different files for easier editting Added build.sh to compile Simple Note System from tree Changed config file to config folder; $HOME/.sns now contains configuration and notes Testing: Script runs and produces help screen; no further testing done.
This commit is contained in:
33
functions/create.sns.sh
Normal file
33
functions/create.sns.sh
Normal file
@@ -0,0 +1,33 @@
|
||||
#==========================================================================
|
||||
# Subection: Create
|
||||
#==========================================================================
|
||||
if [ -z "$CREATE" -a -z "$EDIT" -a -z "$PRINT" ]; then #If no action specified, print help and exit
|
||||
help
|
||||
exit
|
||||
else
|
||||
|
||||
|
||||
if [ "$CREATE" == "TRUE" ]; then
|
||||
if [ -e $NOTE -o -e ${NOTE%.*} ]; then
|
||||
|
||||
echo ""
|
||||
echo "ERROR: Note already exists"
|
||||
echo "Hint: use -e to edit the note."
|
||||
echo ""
|
||||
exit
|
||||
else
|
||||
#Create any necessary folders
|
||||
mkdir -p $NOTEDIR
|
||||
|
||||
#Fill in title
|
||||
echo "TITLE: $NAME" > $NOTE
|
||||
#Fill the second line with the date
|
||||
echo "DATE: $(date)" >> $NOTE
|
||||
|
||||
if [ "$ENCRYPTION" == "TRUE" ]; then
|
||||
if [ $EDIT == "FALSE" ]; then
|
||||
openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
20
functions/delete.sns.sh
Normal file
20
functions/delete.sns.sh
Normal file
@@ -0,0 +1,20 @@
|
||||
# delete.sns.sh
|
||||
|
||||
if [ "$DELETE" == "TRUE" ]; then
|
||||
if [ -e $NOTE -o -e ${NOTE%.*} ]; then
|
||||
if [ "$ENCRYPTION" == "TRUE" ]; then
|
||||
rm ${NOTE%.*}
|
||||
else
|
||||
rm $NOTE
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Deleted note: $NOTEBOOK/$SECTION$NAME."
|
||||
exit
|
||||
else
|
||||
|
||||
echo ""
|
||||
echo "ERROR: Note $NOTEBOOK/$SECTION$NAME does not exist."
|
||||
exit
|
||||
fi
|
||||
fi
|
||||
30
functions/edit.sns.sh
Normal file
30
functions/edit.sns.sh
Normal file
@@ -0,0 +1,30 @@
|
||||
#==========================================================================
|
||||
# Subection: Edit
|
||||
#==========================================================================
|
||||
if [ "$EDIT" == "TRUE" ]; then
|
||||
if [ -r "$NOTE" -o -r ${NOTE%.*} ]; then
|
||||
if [ -z "$CREATE" ]; then
|
||||
if [ "$ENCRYPTION" == "TRUE" ]; then
|
||||
TMP_NAME=$ROOTDIR/tmp/$RANDOM
|
||||
openssl enc -d -aes-256-cbc -in ${NOTE%.*} -pass pass:$ENC_KEY > $TMP_NAME
|
||||
echo "" >> $TMP_NAME
|
||||
echo "EDIT $(date)" >> $TMP_NAME
|
||||
else
|
||||
echo "" >> $NOTE
|
||||
echo "EDIT $(date)" >> $NOTE
|
||||
fi
|
||||
fi
|
||||
$EDITOR $NOTE
|
||||
if [ "$ENCRYPTION" == "TRUE" ]; then
|
||||
openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY
|
||||
rm $NOTE
|
||||
fi
|
||||
|
||||
else
|
||||
echo ""
|
||||
echo "ERROR: Note cannot be opened for editting."
|
||||
echo ""
|
||||
fi
|
||||
fi
|
||||
|
||||
fi
|
||||
20
functions/help.sns.sh
Normal file
20
functions/help.sns.sh
Normal file
@@ -0,0 +1,20 @@
|
||||
function help {
|
||||
echo ""
|
||||
echo "usage: sns [-ce] NAME NOTEBOOK SECTION"
|
||||
echo " sns [-d ] NAME NOTEBOOK SECTION"
|
||||
echo " sns [-l ] NOTEBOOK"
|
||||
echo " sns [-w ]"
|
||||
|
||||
echo ""
|
||||
echo " -c | --create : Create note"
|
||||
echo " -d | --delete : Delete note"
|
||||
echo " -e | --edit : Open note for editing"
|
||||
echo " -p | --print : Print note to console"
|
||||
echo " -l | --list : List all notes in NOTEBOOK"
|
||||
echo " -w | --wconf : Write default configuration to ~/.sns (useful for Encryption)"
|
||||
echo ""
|
||||
}
|
||||
|
||||
#==============================================================================
|
||||
# End Section: Helper Functions
|
||||
#==============================================================================
|
||||
39
functions/list.sns.sh
Normal file
39
functions/list.sns.sh
Normal file
@@ -0,0 +1,39 @@
|
||||
# list.sns.sh
|
||||
|
||||
if [ -n "$LIST" ]; then
|
||||
NOTEBOOK="$NAME" #In case of a list command, arg parsing fails.
|
||||
if [ -z "$NOTEBOOK" ]; then
|
||||
echo " ERROR: Insufficient arguments"
|
||||
help
|
||||
exit
|
||||
else
|
||||
if [ -d "$BASEDIR"/"$NOTEBOOK" ]; then
|
||||
|
||||
echo ""
|
||||
printf "Notes in $(basename $NOTEBOOK):"
|
||||
echo ""
|
||||
NOTES=( $(find $BASEDIR/$NOTEBOOK -name "*.$EXT" -print0 | sed s:$BASEDIR/$NOTEBOOK/:" ":g | sed -e s:".$EXT"::g | tr "/" " ") )
|
||||
let i=0
|
||||
for NOTE in ${NOTES[@]}; do
|
||||
if [ -d $BASEDIR/$NOTEBOOK/$NOTE ]; then
|
||||
if [ "$LAST_SECTION" != "$NOTE" ]; then
|
||||
printf " Section: $NOTE\n"
|
||||
fi
|
||||
LAST_SECTION=$NOTE
|
||||
else
|
||||
#if [ $(($i % 1)) -eq 0 ]; then
|
||||
# printf "\n "
|
||||
#fi
|
||||
printf " $NOTE\n"
|
||||
fi
|
||||
let i++
|
||||
done
|
||||
printf "\n"
|
||||
else
|
||||
echo ""
|
||||
echo "ERROR: Notebook $NOTEBOOK does not exist."
|
||||
echo ""
|
||||
fi
|
||||
fi
|
||||
exit
|
||||
fi
|
||||
22
functions/print.sns.sh
Normal file
22
functions/print.sns.sh
Normal file
@@ -0,0 +1,22 @@
|
||||
#==========================================================================
|
||||
# Subection: Print
|
||||
#==========================================================================
|
||||
if [ "$PRINT" == "TRUE" ]; then
|
||||
if [ -r "$NOTE" -o -r ${NOTE%.*} ]; then
|
||||
if [ -z "$CREATE" ]; then
|
||||
if [ "$ENCRYPTION" == "TRUE" ]; then
|
||||
openssl enc -d -aes-256-cbc -in ${NOTE%.*} -pass pass:$ENC_KEY
|
||||
else
|
||||
cat $NOTE
|
||||
echo "" >> $NOTE
|
||||
fi
|
||||
else
|
||||
|
||||
echo ""
|
||||
echo "ERROR: Note cannot be found."
|
||||
echo ""
|
||||
|
||||
fi
|
||||
fi
|
||||
|
||||
fi
|
||||
35
functions/wconf.sns.sh
Normal file
35
functions/wconf.sns.sh
Normal file
@@ -0,0 +1,35 @@
|
||||
#==============================================================================
|
||||
# Section: Helper Functions
|
||||
#==============================================================================
|
||||
function writeconf {
|
||||
cat > $HOME/.sns/sns.conf << EOF
|
||||
#==========================================================
|
||||
# Simple Note System Config, v2.0a1
|
||||
# Copyright 2014, Xenese Labs/Sicron-Perion XNF
|
||||
#==========================================================
|
||||
|
||||
#Directory where notes will be stored
|
||||
ROOTDIR=$HOME/.sns
|
||||
BASEDIR=$ROOTDIR/notes
|
||||
|
||||
#File extension to use (for listing notes)
|
||||
EXT=note
|
||||
|
||||
#Preferred Editor
|
||||
EDITOR=vim
|
||||
|
||||
#Encryption
|
||||
#WARNING: ANY PREVIOUSLY UNENCRYPTED NOTES WILL BE LOST
|
||||
ENCRYPTION="FALSE"
|
||||
ENC_KEY=""
|
||||
EOF
|
||||
|
||||
chmod 600 $ROOTDIR/sns.conf
|
||||
}
|
||||
|
||||
|
||||
function pause {
|
||||
read -p " Press [Enter] to continue."
|
||||
echo ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user