2021-01-10 09:37:53 +01:00
|
|
|
#!usr//bin/env bash
|
2021-01-16 18:48:47 +01:00
|
|
|
#Change the first line if you don't use bash, in order for the code to work properly.
|
|
|
|
#Warning! If you don't have gedit(text editor) or nano installed, you may have to change the default text editor (lines 10, 25, 40).
|
|
|
|
|
|
|
|
#Change this path if you use another editor.
|
|
|
|
NOTES_EDITOR="$(which gedit)" #Change 'gedit' with your editor.
|
|
|
|
QUICK_NOTES_EDITOR="$(which nano)" #Or this one. (Suggested editors can be found in the Help Page)
|
|
|
|
#Change this path if you use another folder to save your notes.
|
|
|
|
DEFAULT_PATH=~/Notes #Change ~/Notes with your folder.
|
|
|
|
|
2020-12-11 10:27:59 +01:00
|
|
|
|
|
|
|
#Make a Notes folder for the user
|
|
|
|
cd ~
|
|
|
|
if [[ -d "Notes" ]]; then
|
2021-01-16 18:48:47 +01:00
|
|
|
exists=True
|
2020-12-11 10:27:59 +01:00
|
|
|
else
|
2021-01-16 18:48:47 +01:00
|
|
|
mkdir Notes
|
2020-12-11 10:27:59 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
#opening a note (It will create a new note if $notename is blank)
|
|
|
|
function readnote() {
|
2021-01-16 18:48:47 +01:00
|
|
|
dir="$(pwd)"
|
|
|
|
me="$(whoami)"
|
|
|
|
echo -n "Enter note name: " && read notename
|
|
|
|
cd $DEFAULT_PATH
|
|
|
|
if [ -e $notename ]; then
|
|
|
|
$NOTES_EDITOR $notename
|
2020-12-11 10:27:59 +01:00
|
|
|
|
|
|
|
else
|
2021-01-16 18:48:47 +01:00
|
|
|
clear
|
|
|
|
echo "No such note."
|
|
|
|
echo -n "Do you want to create one?[Y/N]: " && read create;
|
2020-12-11 10:27:59 +01:00
|
|
|
|
|
|
|
fi
|
2021-01-18 12:28:28 +01:00
|
|
|
case $create in Y|Yes|YES|Yes|y )
|
2020-12-11 10:27:59 +01:00
|
|
|
newnote
|
2021-01-18 12:28:28 +01:00
|
|
|
esac
|
2020-12-11 10:27:59 +01:00
|
|
|
|
2021-01-16 18:48:47 +01:00
|
|
|
clear
|
2020-12-11 10:27:59 +01:00
|
|
|
cd $dir
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#Read notes instantly via terminal
|
|
|
|
function quickread() {
|
2021-01-16 18:48:47 +01:00
|
|
|
dir="$(pwd)"
|
|
|
|
echo -n "Enter note name: " && read quicknotename
|
|
|
|
cd $DEFAULT_PATH
|
2020-12-11 10:27:59 +01:00
|
|
|
if [ -e $quicknotename ]; then
|
2021-01-16 18:48:47 +01:00
|
|
|
clear
|
2020-12-11 10:27:59 +01:00
|
|
|
cat $quicknotename
|
|
|
|
|
|
|
|
else
|
2021-01-16 18:48:47 +01:00
|
|
|
clear
|
|
|
|
echo "No such note."
|
2021-01-18 12:28:28 +01:00
|
|
|
cd
|
2020-12-11 10:27:59 +01:00
|
|
|
fi
|
|
|
|
cd $dir
|
|
|
|
}
|
|
|
|
|
|
|
|
#A quick solution to users who want keeping notes instantly via terminal.
|
|
|
|
function quicknote() {
|
2021-01-16 18:48:47 +01:00
|
|
|
dir="$(pwd)"
|
|
|
|
me="$(whoami)"
|
|
|
|
cd $DEFAULT_PATH
|
|
|
|
echo -n "Enter note name: " && read notename
|
2020-12-11 10:27:59 +01:00
|
|
|
if [ -e $notename ]; then
|
2021-01-16 18:48:47 +01:00
|
|
|
clear
|
|
|
|
echo "This note already exists."
|
2020-12-11 10:27:59 +01:00
|
|
|
cd ..
|
2021-01-16 18:48:47 +01:00
|
|
|
echo -n "Do you want to read it?[Y/N]: " && read readquicknote
|
2020-12-11 10:27:59 +01:00
|
|
|
|
|
|
|
else
|
2021-01-16 18:48:47 +01:00
|
|
|
touch $notename
|
2021-01-18 12:21:55 +01:00
|
|
|
$QUICK_NOTES_EDITOR $notename
|
2021-01-16 18:48:47 +01:00
|
|
|
cd $dir
|
|
|
|
clear
|
|
|
|
echo "Note created in Home/$me/Notes"
|
|
|
|
echo "-----------------------------------"
|
2020-12-11 10:27:59 +01:00
|
|
|
|
|
|
|
fi
|
|
|
|
|
2021-01-16 18:48:47 +01:00
|
|
|
case $readquicknote in y|Y|YES|Yes|yes )
|
|
|
|
clear
|
|
|
|
cd $DEFAULT_PATH
|
|
|
|
if [[ -s $notename ]]; then
|
|
|
|
echo "This note is blank."
|
|
|
|
else
|
|
|
|
cat $notename
|
|
|
|
fi
|
|
|
|
esac
|
2020-12-11 10:27:59 +01:00
|
|
|
cd $dir
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#writes notes using ubuntu's text-editor (gedit).
|
|
|
|
function newnote() {
|
2021-01-16 18:48:47 +01:00
|
|
|
dir="$(pwd)";
|
|
|
|
me="$(whoami)"
|
|
|
|
cd $DEFAULT_PATH
|
|
|
|
$NOTES_EDITOR
|
|
|
|
clear
|
|
|
|
cd $dir
|
2020-12-11 10:27:59 +01:00
|
|
|
echo "Note created in Home/$me/Notes";
|
|
|
|
echo "-----------------------------------";
|
|
|
|
}
|
|
|
|
|
|
|
|
#Delete notes from terminal
|
|
|
|
function delnote() {
|
2021-01-01 21:05:16 +01:00
|
|
|
if [[ $1 == "-all" ]]; then
|
2021-01-16 18:48:47 +01:00
|
|
|
dir="$(pwd)"
|
|
|
|
cd $DEFAULT_PATH
|
|
|
|
me="$(whoami)"
|
2021-01-01 21:05:16 +01:00
|
|
|
rm *
|
2021-01-16 18:48:47 +01:00
|
|
|
clear
|
|
|
|
cd $dir
|
2021-01-01 21:05:16 +01:00
|
|
|
echo "All files deleted from Home/$me/Notes";
|
|
|
|
echo "-------------------------------------";
|
2020-12-11 10:27:59 +01:00
|
|
|
else
|
2021-01-16 18:48:47 +01:00
|
|
|
dir="$(pwd)"
|
|
|
|
cd $DEFAULT_PATH
|
|
|
|
me="$(whoami)"
|
|
|
|
echo -n "Enter the name of the note you want to delete: " && read delete
|
2021-01-01 21:05:16 +01:00
|
|
|
if [ -e $delete ]; then
|
|
|
|
rm $delete
|
2021-01-16 18:48:47 +01:00
|
|
|
clear
|
|
|
|
cd $dir
|
2021-01-01 21:05:16 +01:00
|
|
|
echo "Note deleted from Home/$me/Notes";
|
|
|
|
echo "-----------------------------------";
|
|
|
|
else
|
|
|
|
echo "No such file."
|
2021-01-16 18:48:47 +01:00
|
|
|
cd $dir
|
2020-12-11 10:27:59 +01:00
|
|
|
fi
|
2021-01-01 21:05:16 +01:00
|
|
|
fi
|
2020-12-11 10:27:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#list your notes via terminal.
|
|
|
|
function listnotes() {
|
|
|
|
if [ -z "$(ls -A ~/Notes)" ]; then
|
|
|
|
echo "Your Notes folder is empty."
|
|
|
|
else
|
2021-01-16 18:48:47 +01:00
|
|
|
ls $DEFAULT_PATH -t
|
2020-12-11 10:27:59 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
#Help for new users
|
|
|
|
function shellnotes() {
|
2021-01-16 18:48:47 +01:00
|
|
|
dir="$(pwd)"
|
2020-12-11 10:27:59 +01:00
|
|
|
if [[ $1 == "-v" ]]; then
|
2021-01-16 18:48:47 +01:00
|
|
|
echo "Shellnotes version: 2.5"
|
2021-01-01 21:05:16 +01:00
|
|
|
|
2020-12-11 10:27:59 +01:00
|
|
|
elif [[ $1 == "-r" ]]; then
|
|
|
|
echo "Github repository: https://github.com/dmarakom6/shellnotes/blob/master/"
|
|
|
|
|
|
|
|
elif [[ $1 == "-h" ]]; then
|
2021-01-16 18:48:47 +01:00
|
|
|
less ~/.help
|
|
|
|
cd $dir
|
2020-12-11 10:27:59 +01:00
|
|
|
elif [[ $1 == "--help" ]]; then
|
2021-01-16 18:48:47 +01:00
|
|
|
less ~/.help
|
|
|
|
cd $dir
|
|
|
|
else
|
|
|
|
cd ~
|
|
|
|
if [ -e .shellnotes.sh ]; then
|
|
|
|
echo "Shellnotes is successfully installed. For help, type shellnotes --help."
|
|
|
|
cd $dir
|
|
|
|
else
|
|
|
|
echo "Shellnotes is not installed properly. Please repeat installation steps or try shellnotes --help."
|
|
|
|
cd $dir
|
|
|
|
fi
|
2020-12-11 10:27:59 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
#Take info about a note
|
|
|
|
function noteinfo() {
|
|
|
|
dir="$(pwd)"
|
2021-01-16 18:48:47 +01:00
|
|
|
cd $DEFAULT_PATH
|
|
|
|
echo -n "Enter note name: " && read notename
|
2020-12-11 10:27:59 +01:00
|
|
|
if [ -e $notename ]; then
|
2021-01-16 18:48:47 +01:00
|
|
|
wc $notename
|
2020-12-11 10:27:59 +01:00
|
|
|
echo "(lines/words/chars/name)"
|
|
|
|
else
|
|
|
|
echo "That note doesn't exist."
|
|
|
|
fi
|
|
|
|
cd $dir
|
|
|
|
}
|
|
|
|
|
2021-01-01 21:05:16 +01:00
|
|
|
#Help the user find a specific Note in his note folder. If it's not there, he must have misplaced it.
|
|
|
|
function findnote() {
|
|
|
|
dir="$(pwd)"
|
|
|
|
me="$(whoami)"
|
2021-01-16 18:48:47 +01:00
|
|
|
echo -n "Enter note name: " && read notename
|
|
|
|
cd $DEFAULT_PATH
|
2021-01-01 21:05:16 +01:00
|
|
|
if [ -e $notename ]; then
|
|
|
|
echo "File was found in your Notes folder."
|
|
|
|
else
|
|
|
|
echo "File was not found in your Notes folder, must be misplaced or renamed."
|
|
|
|
echo "Try 'findmisplacednote' to find the original file."
|
|
|
|
|
|
|
|
fi
|
|
|
|
cd $dir
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#Find a misplaced note, not in the Notes folder.
|
|
|
|
function findmisplacednote() {
|
2021-01-16 18:48:47 +01:00
|
|
|
echo -n "Enter note name: " && read notename
|
|
|
|
echo "Possible locations: "
|
|
|
|
find ~/ -iname $notename -print 2>/dev/null
|
2021-01-01 21:05:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#Rename a note.
|
|
|
|
function renamenote() {
|
|
|
|
dir="$(pwd)"
|
|
|
|
me="$(whoami)"
|
2021-01-16 18:48:47 +01:00
|
|
|
cd $DEFAULT_PATH
|
|
|
|
echo -n "Enter note name: " && read notename
|
2021-01-01 21:05:16 +01:00
|
|
|
if [ -e $notename ]; then
|
2021-01-16 18:48:47 +01:00
|
|
|
echo -n "Enter new name: " && read newnotename
|
2021-01-01 21:05:16 +01:00
|
|
|
if [ -e $newnotename ]; then
|
|
|
|
echo "There is another note named '$newnotename' in your Notes folder."
|
2021-01-16 18:48:47 +01:00
|
|
|
else
|
|
|
|
mv $notename $newnotename
|
2021-01-18 12:21:55 +01:00
|
|
|
clear;
|
2021-01-16 18:48:47 +01:00
|
|
|
echo "Note renamed from $notename to $newnotename in Home/$me/Notes"
|
|
|
|
echo "-------------------------------------------------------------"
|
2021-01-01 21:05:16 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
else
|
|
|
|
echo "This note does not exist."
|
|
|
|
fi
|
2021-01-16 18:48:47 +01:00
|
|
|
|
|
|
|
cd $dir
|
2021-01-01 21:05:16 +01:00
|
|
|
}
|
2021-01-16 18:48:47 +01:00
|
|
|
|