-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotes
More file actions
executable file
·62 lines (56 loc) · 1.64 KB
/
Copy pathnotes
File metadata and controls
executable file
·62 lines (56 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Check if the '.notes' folder does already exists
if [ ! -d $HOME/.notes ]
# If not, create it and warn the user
then
mkdir ~/.notes
echo A new directory .notes has been created at the home directory.
fi
# Check if there is no first argument
if [ -z $1 ]
# If not, print the help output
then
echo Type \'notes name\' with the name of the note to be opened/created
echo Type \'notes -remove name\' with the name of the note to be removed
echo Available notes:
ls $HOME/.notes
exit 1
fi
# If the first argument is '-remove' we remove the note specified in the second argument
if [ $1 = "-remove" ]
then
# If there is no second argument return help
if [ -z $2 ]
then
echo Specify the note to be deleted. e.g. \'notes -remove my_note\'
exit 1
fi
# If specified note does not exist return all note names
if [ ! -f $HOME/.notes/$2 ]
then
echo Note \'$2\' does not exist
echo Available notes:
ls $HOME/.notes
exit 1
fi
# Otherwise all is correct. Remove the specified note and print the confirmation
rm $HOME/.notes/$2
echo Note \'$2\' has been removed
exit 0
fi
# Check if the provided option name matches any existing text file
if [ ! -f $HOME/.notes/$1 ]
# Ask user to confirm the creation of the new note
then
while true; do
read -p "'$1' does not match any note. Would you like to create a new note? (y/n)`echo $'\n> '`" yn
case $yn in
# If confirmed, create the new note
[Yy]* ) > $HOME/.notes/$1; echo "A new note has been created: $1"; gedit $HOME/.notes/$1; exit 0;;
[Nn]* ) echo 'Aborted'; exit 0;;
* ) echo "Please answer yes or no.";;
esac
done
fi
# Open the text file
gedit $HOME/.notes/$1 &
exit 0