-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcarrot
216 lines (197 loc) · 8.56 KB
/
carrot
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/bin/sh
HEADER='\033[95m'
BLUE='\033[94m'
CYAN='\033[96m'
GREEN='\033[92m'
RED1='\033[93m'
RED2='\033[91m'
WHITE='\033[0m'
UNDERLINE='\033[4m'
ver1="34"
ver="$ver1 ~ colored text not showing & invalid texts bug fixed"
upd=0
cu="\n${HEADER}Commands usage:\n\ncarrot -cpp <path>\nExecute C++ program\n\ncarrot -c <path>\nExecute C program\n\ncarrot -repeat <string>\nRepeats the string you wrote\n\ncarrot -carrotedit\nOpens the Carrotshell program for you to edit\n\ncarrot -remove <file path>\nRemoves specified file\n\ncarrot -pi <package>\nInstalls the specified package\n\ncarrot -pr <package>\nRemoves the specified package\n\ncarrot -pu <package>\nUpdates apt and upgrades all packages\n\ncarrot -deb [-i/-r] <path>\nInstalls[-i]/Removes[-r] .deb package\n\ncarrot -update\nUpdates Carrotshell\n\ncarrot -rustdir <path>\nSets Rust Cargo directory (usually ~/.cargo/bin)\n\ncarrot -rust <path>\nExecute Rust program\n\n${GREEN}Carrotshell V${ver}$WHITE\n"
if [ ! -f ~/.Carrotshell/ini ]; then
printf "\nInitialization...\n"
if [ ! -d ~/.Carrotshell ]; then
mkdir ~/.Carrotshell
fi
echo "Delete this file to re-inizialize Carrotshell!" >> ~/.Carrotshell/ini
printf "\n${RED1}Super User powers needed to install required packages$WHITE\n"
sudo apt install build-essential gedit xfce4-terminal w3m gcc
fi
if [ "$1" = '-cpp' ]; then
if [ "$2" = '' ]; then
printf "\nYou haven't write nothing!\nUsage: carrot -cpp <path>\n\n"
else
if [ ! -f $2 ]; then
printf "\n${RED2}ERROR: This file doesn't exist!\n${RED1}Directory Example: /home/<username>/Documents/File.cpp\n$WHITE\n"
else
printf "\n${RED1}Compiling...$WHITE\n"
g++ $2 -o carrotprogbash
printf "${BLUE}Executing...$WHITE\n\n"
if [ ! -f carrotprogbash ]; then
printf "${RED2}ERROR: Compiled file not found. If you got this error after a compiling error, ignore this line.$WHITE\n\n"
else
./carrotprogbash
rm carrotprogbash
printf "\n${GREEN}Executed!$WHITE\n\n"
fi
fi
fi
elif [ "$1" = '-c' ]; then
if [ "$2" = '' ]; then
printf "\nYou haven't write nothing!\nUsage: carrot -c <path>\n\n"
else
if [ ! -f $2 ]; then
printf "\n${RED2}ERROR: This file doesn't exist!\n${RED1}Directory Example: /home/<username>/Documents/File.c\n$WHITE\n"
else
printf "\n${RED1}Compiling...$WHITE\n"
gcc $2 -o carrotprogbash
printf "${BLUE}Executing...$WHITE\n\n"
if [ ! -f carrotprogbash ]; then
printf "${RED2}ERROR: Compiled file not found. If you got this error after a compiling error, ignore this line.$WHITE\n\n"
else
./carrotprogbash
rm carrotprogbash
printf "\n${GREEN}Executed!$WHITE\n\n"
fi
fi
fi
elif [ "$1" = '-deb' ]; then
if [ "$2" = '' ]; then
printf "\nYou haven't write the option!\nUsage: carrot -deb [-i/-r] <path>\n\n"
elif [ "$2" = '-i' ]; then
if [ "$3" = '' ]; then
printf "\nYou haven't write the path!\nUsage: carrot -deb [-i/-r] <path>\n\n"
else
printf "\n${RED1}Super User powers needed to install packages$WHITE\n"
sudo dpkg -i $3
fi
elif [ "$2" = '-r' ]; then
if [ "$3" = '' ]; then
printf "\nYou haven't write the path!\nUsage: carrot -deb [-i/-r] <path>\n\n"
else
printf "\n${RED1}Super User powers needed to install packages$WHITE\n"
sudo dpkg -r $3
fi
else
printf "\nInvalid option!\nUsage: carrot -deb [-i/-r] <path>\n\n"
fi
elif [ "$1" = '-repeat' ]; then
if [ "$2" = '' ]; then
printf "\nYou haven't wrote nothing!\nUsage: carrot -repeat <string>\n\n"
else
printf "\n$2\n\n"
fi
elif [ "$1" = '-carrotedit' ]; then
printf "\n${RED2}WARNING! You are about to edit the Carrotshell program!$WHITE\n"
printf "Are you still sure about editing it? [y/n] >> "
read sas
if [ "$sas" = 'y' ]; then
printf "\n${RED1}Opening gedit...$WHITE\n"
sudo gedit /usr/bin/carrot
else
printf "\n${GREEN}Aborted.$WHITE\n\n"
fi
elif [ "$1" = '-remove' ]; then
if [ "$2" = '' ]; then
printf "\nYou haven't wrote nothing!\nUsage: carrot -remove <file path>\n${HEADER}Want to remove a directory (folder)?\nType 'carrot -remove ${RED1}-r${HEADER} <directory>'$WHITE\n\n"
else
rm $2 $3
fi
elif [ "$1" = '-pi' ]; then
if [ "$2" = '' ]; then
printf "\nYou haven't wrote nothing!\nUsage: carrot -pi <package>\n\n"
else
printf "\n${RED1}Super User powers needed to install packages$WHITE\n"
sudo apt install $2
fi
elif [ "$1" = '-pr' ]; then
if [ "$2" = '' ]; then
printf "\nYou haven't wrote nothing!\nUsage: carrot -pr <package>\n\n"
else
printf "\n${RED1}Super User powers needed to remove packages$WHITE\n"
sudo apt remove $2
fi
elif [ "$1" = '-pu' ]; then
printf "\n${RED1}Super User powers needed to update apt & upgrade packages$WHITE\n"
sudo apt update && sudo apt upgrade
elif [ "$1" = '-update' ]; then
if [ ! -d ~/.Carrotshell ]; then
mkdir ~/.Carrotshell
fi
cd ~/.Carrotshell/
wget https://raw.githubusercontent.com/SpheLC/Carrotshell/main/carrot
printf "\n${RED1}Super User powers needed to update Carrotshell$WHITE\n"
printf "${RED1}Press Enter if I ask you a question to confirm moving some files (~/.Carrotshell/carrot to /usr/bin/carrot)$WHITE\n"
sudo mv ~/.Carrotshell/carrot /usr/bin
sudo chmod +x /usr/bin/carrot
printf "${UNDERLINE}${GREEN}Done!$WHITE\n\n"
upd=1
elif [ "$1" = '-help' ]; then
printf "$cu\n"
elif [ "$1" = '' ]; then
printf "$cu\n"
elif [ "$1" = '-rustdir' ]; then
if [ "$2" = '' ]; then
printf "\n${RED2}You haven't wrote nothing!\n${RED1}Usage: carrot -rustdir <directory>\n(usually it is in ~/.cargo/bin)$WHITE\n\n"
else
if [ ! -d $2 ]; then
printf "\n${RED2}ERROR: This directory doesn't exist!\n${RED1}Directory Example: /home/<username>/Documents\n$WHITE\n"
else
printf "\nWriting...\n"
if [ ! -f ~/.Carrotshell/rust ]; then
echo $2 >> ~/.Carrotshell/rust
else
rm ~/.Carrotshell/rust
echo $2 >> ~/.Carrotshell/rust
fi
if [ ! -f $2/rustc ]; then
printf "${RED2}Invalid directory! This directory that you wrote doesn't have the 'rustc' file inside!$WHITE\n\n"
else
printf "${GREEN}Done!$WHITE\n\n"
fi
fi
fi
elif [ "$1" = '-rust' ]; then
if [ "$2" = '' ]; then
printf "\n${RED2}You haven't write nothing!\n${RED1}Usage: carrot -rust <path>\n\n"
else
if [ ! -f $2 ]; then
printf "\n${RED2}ERROR: This file doesn't exist!\n${RED1}Directory Example: /home/<username>/Documents/File.rs\n$WHITE\n"
else
b=$(basename $2)
c=${b%.*}
if [ ! -f ~/.Carrotshell/rust ]; then
printf "\n${RED2}ERROR: Rust Cargo directory it hasn't been set yet! Fix this by doing:\n${RED1}carrot -rustdir <path>$WHITE\n\n"
else
printf "\n${RED1}Compiling...$WHITE\n"
$(cat ~/.Carrotshell/rust)/rustc $2
printf "${BLUE}Executing...$WHITE\n\n"
if [ ! -f $c ]; then
printf "\n${RED2}ERROR: Compiled file not found. If you got this error after a compiling error, ignore this line.$WHITE\n\n"
else
./$c
rm $c
printf "\n${GREEN}Executed!$WHITE\n\n"
fi
fi
fi
fi
#if command not found...
else
printf "\n'$1' is an unexpected command\n"
printf "$cu\n"
fi
#Check the version
veronline=$(w3m -dump https://raw.githubusercontent.com/SpheLC/Carrotshell/main/version_dontmindme)
if [ $veronline -gt $ver1 -a $upd -eq 0 ]; then
printf "${RED2} .$WHITE\n"
printf "${RED2} / \ $WHITE\n"
printf "${RED2} / ${RED1}! ${RED2}\ ${BLUE}New version ${GREEN}avaiable${BLUE}! ${RED1}(V${veronline})$WHITE\n"
printf "${RED2}+-----+\n\n${RED1}'carrot -update' to update!$WHITE\n\n"
elif [ $veronline -lt $ver1 ]; then
printf "${RED1}ERROR: Your version is newer than the original release.\nTry to update Carrotshell to fix this error or just wait some minutes.\nYour version: $ver1 | Current version: $veronline$WHITE\n\n"
fi
#Carrotshell By Sphe