2020-06-16 18:11:56 +02:00
|
|
|
#!/bin/bash
|
2020-12-07 12:55:20 +01:00
|
|
|
#Change the first line if you don't use bash, in order for the code to work properly.
|
2020-06-16 18:11:56 +02:00
|
|
|
#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).
|
2020-12-07 12:55:20 +01:00
|
|
|
#remember to write this line into your terminal
|
|
|
|
#chmod +x shellnotes.sh
|
|
|
|
|
|
|
|
|
|
|
|
#Make a Notes folder for the user
|
|
|
|
cd ~
|
|
|
|
if [[ -d "Notes" ]]; then
|
|
|
|
exists=True;
|
|
|
|
else
|
|
|
|
mkdir Notes;
|
|
|
|
fi
|
|
|
|
|
2020-06-16 18:11:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
#opening a note (newnote will work as well, but this is a simpler one, and will create a new note if $notename doesn't exist)
|
|
|
|
function readnote() {
|
2020-12-07 12:55:20 +01:00
|
|
|
dir="$(pwd)";
|
|
|
|
me="$(whoami)";
|
|
|
|
read -p "Enter note name: " opennote;
|
|
|
|
cd ~/Notes;
|
|
|
|
if [ -e $opennote ]; then
|
|
|
|
gedit $opennote;
|
|
|
|
|
|
|
|
else
|
|
|
|
clear;
|
|
|
|
echo "No such note.";
|
|
|
|
cd ~
|
|
|
|
read -p "Do you want to create one?[Y/N]: " create;
|
|
|
|
|
|
|
|
fi
|
|
|
|
if [ $create == "y" ] || [ $create == "Y" ] || [ $create == "yes" ] || [ $create == "YES" ] || [ $create == "Yes" ]; then
|
|
|
|
newnote
|
|
|
|
fi
|
|
|
|
|
|
|
|
clear;
|
|
|
|
cd $dir
|
2020-06-16 18:11:56 +02:00
|
|
|
|
2020-12-07 12:55:20 +01:00
|
|
|
}
|
2020-06-16 18:11:56 +02:00
|
|
|
|
2020-12-07 12:55:20 +01:00
|
|
|
#Read notes instantly via terminal
|
|
|
|
function quickread() {
|
|
|
|
dir="$(pwd)";
|
|
|
|
read -p "Enter note name: " quicknotename;
|
|
|
|
cd ~/Notes
|
|
|
|
if [ -e $quicknotename ]; then
|
|
|
|
clear;
|
|
|
|
cat $quicknotename
|
|
|
|
|
|
|
|
else
|
|
|
|
clear;
|
|
|
|
echo "No such note.";
|
|
|
|
cd ~
|
|
|
|
|
|
|
|
fi
|
2020-06-16 18:11:56 +02:00
|
|
|
|
2020-12-07 12:55:20 +01:00
|
|
|
cd $dir
|
2020-06-16 18:11:56 +02:00
|
|
|
|
2020-12-07 12:55:20 +01:00
|
|
|
}
|
2020-06-16 18:11:56 +02:00
|
|
|
|
|
|
|
#A quick solution to users who want keeping notes instantly via terminal.
|
2020-12-07 12:55:20 +01:00
|
|
|
function quicknote() {
|
|
|
|
dir="$(pwd)";
|
|
|
|
me="$(whoami)";
|
|
|
|
cd ~/Notes;
|
|
|
|
read -p "Enter note name: " notename;
|
|
|
|
if [ -e $notename ]; then
|
|
|
|
clear;
|
|
|
|
echo "This note already exists.";
|
|
|
|
cd ..
|
|
|
|
read -p "Do you want to read it?[Y/N]: " readquicknote;
|
|
|
|
|
|
|
|
else
|
2020-06-16 18:11:56 +02:00
|
|
|
touch $notename;
|
|
|
|
nano $notename;
|
2020-12-07 12:55:20 +01:00
|
|
|
cd $dir;
|
|
|
|
clear;
|
|
|
|
echo "Note created in Home/$me/Notes";
|
2020-06-16 18:11:56 +02:00
|
|
|
echo "-----------------------------------";
|
2020-12-07 12:55:20 +01:00
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $readquicknote == "y" ] || [ $readquicknote == "Y" ] || [ $readquicknote == "yes" ] || [ $readquicknote == "YES" ] || [ $readquicknote == "Yes" ]; then
|
|
|
|
clear;
|
|
|
|
cd ~/Notes
|
|
|
|
cat $notename;
|
|
|
|
cd $dir
|
|
|
|
fi
|
2020-06-16 18:11:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-07 12:55:20 +01:00
|
|
|
#like quicknote(), but it opens ubuntu's text-editor (gedit).
|
|
|
|
function newnote() {
|
|
|
|
cd ~/Notes;
|
|
|
|
dir="$(pwd)";
|
|
|
|
me="$(whoami)";
|
|
|
|
gedit;
|
|
|
|
clear;
|
|
|
|
cd $dir;
|
|
|
|
echo "Note created in Home/$me/Notes";
|
|
|
|
echo "-----------------------------------";
|
|
|
|
}
|
2020-06-16 18:11:56 +02:00
|
|
|
|
2020-12-07 12:55:20 +01:00
|
|
|
#Delete notes from terminal
|
|
|
|
function delnote() {
|
|
|
|
cd ~/Notes
|
|
|
|
me="$(whoami)";
|
|
|
|
dir="$(pwd)";
|
|
|
|
read -p "Enter the name of the note you want to delete: " delete
|
|
|
|
if [ -e $delete ]; then
|
|
|
|
rm $delete
|
|
|
|
clear;
|
|
|
|
cd $dir;
|
|
|
|
echo "Note deleted from Home/$me/Notes";
|
|
|
|
echo "-----------------------------------";
|
|
|
|
else
|
|
|
|
echo "No such file."
|
|
|
|
cd ~;
|
|
|
|
fi
|
2020-06-16 18:11:56 +02:00
|
|
|
|
2020-12-07 12:55:20 +01:00
|
|
|
}
|
2020-06-16 18:11:56 +02:00
|
|
|
|
2020-12-07 12:55:20 +01:00
|
|
|
#list your notes via terminal.
|
|
|
|
function listnotes() {
|
|
|
|
ls ~/Notes -t
|
2020-06-16 18:11:56 +02:00
|
|
|
}
|
|
|
|
|
2020-12-07 12:55:20 +01:00
|
|
|
#Help for new users
|
|
|
|
function shellnotes() {
|
|
|
|
if [[ $1 == "-v" ]]; then
|
|
|
|
echo "Shellnotes version: 1.0"
|
|
|
|
|
|
|
|
elif [[ $1 == "-r" ]]; then
|
|
|
|
echo "Github repository: https://github.com/dmarakom6/shellnotes/blob/master/"
|
2020-06-16 18:11:56 +02:00
|
|
|
|
2020-12-07 12:55:20 +01:00
|
|
|
elif [[ $1 == "-h" ]]; then
|
|
|
|
less ~/.help;
|
|
|
|
cd $dir;
|
|
|
|
elif [[ $1 == "--help" ]]; then
|
|
|
|
less ~/.help;
|
|
|
|
cd $dir;
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
#Shellnotes made by dmarakom6.
|