forked from oprifine/flash_shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflash.py
More file actions
377 lines (355 loc) · 19.5 KB
/
Copy pathflash.py
File metadata and controls
377 lines (355 loc) · 19.5 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
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
import os
from base64 import standard_b64decode
import subprocess as sp
import sys
import datetime as dt
import time as ti
import psutil
import random as r
import shutil
import requests
from bs4 import BeautifulSoup, SoupStrainer
import webbrowser
import http.server
import socketserver
import socket
import matplotlib.pyplot as plt
print("Setting shell....")
set()
print("Optimizing...")
set()
print("Done loading!")
print("Welcome to flash!")
base_dir = os.getcwd()
def run_script(script_name, *flags):
script_path = os.path.join(base_dir, script_name)
if os.path.exists(script_path):
command = [sys.executable, script_path, *flags]
try:
sp.run(command)
except FileNotFoundError:
print(f"Command not found. Please install the necessary tool or check the command.")
else:
print(f"Script not found: {script_name}")
def set():
ti.sleep(0.9)
return
def exefun():
print(f"Executing {function}...")
return
def create_graph():
# Get user input for the graph title
graph_title = input("Enter graph title: ")
# Get user input for x and y coordinates
x_values = list(map(float, input("Enter x values (comma-separated): ").split(',')))
y_values = list(map(float, input("Enter y values (comma-separated): ").split(',')))
# Plot the graph
plt.plot(x_values, y_values, marker='o')
plt.title(graph_title)
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.grid(True)
def display_system_info():
print("CPU Information:")
print(f" CPU Cores: {psutil.cpu_count(logical=False)} physical, {psutil.cpu_count(logical=True)} logical")
print(f" CPU Usage: {psutil.cpu_percent()}%")
def ansh():
symbols = ['/', '-', '\\', '|']
for i in range(20): # Change the range to control the number of rotations
for symbol in symbols:
print(symbol, end='\r') # Print the symbol and move the cursor back to the start of the line
ti.sleep(0.1) # Adjust the sleep duration to control the speed of rotation
def c():
disk_usage = psutil.disk_usage(base_dir)
print("\nDisk Usage Information:")
print(f" Total Disk Space: {disk_usage.total / (1024 ** 3):.2f} GB")
print(f" Used Disk Space: {disk_usage.used / (1024 ** 3):.2f} GB")
print(f" Free Disk Space: {disk_usage.free / (1024 ** 3):.2f} GB")
print(f" Disk Usage Percentage: {disk_usage.percent}%")
while True:
cmd = input(f"{base_dir}|flash ")
try:
if cmd == "version" or cmd == "ver" or cmd == "v":
run_script('databases/version.py', "--upgrade", "--flag1", "--flag2", "--flag3")
elif cmd == "get" or cmd == "g" or cmd == "fetch" or cmd.startswith("pip") or cmd.startswith("apt" or "sudo" or "yum"):
run_script('databases/installer.py', "--upgrade", "--flag1", "--flag2", "--flag3")
elif cmd.startswith("cd ") or cmd.startswith("changedir "):
new_path = cmd.split(" ", 1)[1].strip()
full_path = os.path.join(base_dir, new_path)
try:
os.chdir(full_path)
base_dir = os.getcwd()
print(f"Changed directory to: {base_dir}")
except (FileNotFoundError, PermissionError) as e:
print(f"Error: {e}")
elif cmd == "setbase" or cmd == "setbasedir" or cmd == "setdir":
new_base_dir = input("Enter the new base directory: ").strip()
if os.path.exists(new_base_dir) and os.path.isdir(new_base_dir):
base_dir = os.path.abspath(new_base_dir)
print(f"Base directory set to: {base_dir}")
else:
print(f"Invalid directory: {new_base_dir}")
elif cmd == "pyfunct":
try:
function = input("What Python function do you want to use?")
except EOFError:
print("The function didn't work..")
if function.strip() == "":
print("No function specified")
elif function.lower() == "import":
try:
module = input("What module would you like to import?")
imported_module = __import__(module)
print(f"Module '{module}' imported successfully.")
exefun() # Call the function here
except ImportError as e:
print(f"Error importing module '{module}': {e}")
else:
print(f"Executing {function}...")
if cmd == "ls" or cmd == "list" or cmd == "dirlist":
files = os.listdir(base_dir)
print("\n".join(files))
elif cmd == "malloc" or cmd == "memoryallocate":
if cmd == "therapist":
print(f"you'll be fine")
elif cmd == "bf" or cmd == "brainfuck":
sp.run(['python', f'C:/Users/{os.getlogin()}/.flash/flash_shell/dep/bf.py'])
elif cmd == "time" or cmd == "currenttime" or cmd == "showtime":
current_time = dt.datetime.now().strftime("%H:%M:%S")
print(f"Current time: {current_time}")
elif cmd == "place" or cmd == "plot":
create_graph()
plt.show()
elif cmd == "!number" or cmd == "randomnumber" or cmd == "randnum":
random_number = r.randint(0, 100)
print(random_number)
elif cmd == "anislash" or cmd == "animatedslash":
ansh()
elif cmd == "date" or cmd == "currentdate" or cmd == "showdate":
current_date = dt.datetime.now().strftime("%Y-%m-%d")
print(f"Current date: {current_date}")
elif cmd == "whoami" or cmd == "myname" or cmd == "username":
print(os.getlogin())
elif cmd == "!info" or cmd == "flashinfo" or cmd == "information":
run_script('dep/flashinfo.py')
elif cmd == "weather" or cmd == "forecast" or cmd == "getweather":
city = input("Enter the city for weather information: ")
sp.run(['curl', f'wttr.in/{city}'])
elif cmd == "randomword" or cmd == "randword" or cmd == "randomtext":
response = requests.get('https://randomword.com/')
if response.status_code == 200:
soup = BeautifulSoup(response.text, 'html.parser')
random_word = soup.find('div', {'id': 'random_word'}).text
print(random_word)
else:
print(f"Failed to fetch a random word. Status code: {response.status_code}")
elif cmd == "download" or cmd == "fetchfile" or cmd == "getfile":
url = input("Enter the URL to download: ")
try:
sp.run(['wget', url])
print(f"Downloaded successfully from {url}.")
except FileNotFoundError:
print("Command 'wget' not found. Please install it to use this command.")
elif cmd == "hawks":
print("WE ARE THE BEST SCHOOL EVER!!!")
elif cmd.startswith("search "):
try:
query = cmd.split(" ", 1)[1].strip()
search_url = f'https://www.google.com/search?q={query}'
webbrowser.open(search_url)
except requests.RequestException as e:
print(f"Error during the search: {e}")
if cmd.startswith("translate "):
text_to_translate = cmd.split(" ", 1)[1].strip()
sp.run(['trans', text_to_translate])
elif cmd.startswith("calculate "):
expression = cmd.split(" ", 1)[1].strip()
sp.run(['python', '-c', f'print({expression})'])
elif cmd == "checkinternet" or cmd == "internetstatus" or cmd == "pinggoogle":
sp.run(['ping', '-c', '4', '8.8.8.8'])
elif cmd == "calendar" or cmd == "showcalendar" or cmd == "viewcalendar":
sp.run(['cal'])
elif cmd == "rolladice" or cmd == "dice" or cmd == "rolldice":
sp.run(['shuf', '-i', '1-6', '-n', '1'])
if cmd.startswith("quote "):
author = cmd.split(" ", 1)[1].strip()
sp.run(['curl', f'https://api.quotable.io/random?author={author}'])
elif cmd == "info" or cmd == "flashiinfo" or cmd == "information":
run_script('dep/flashiinfo.py')
elif cmd == "twister" or cmd == "switchshell" or cmd == "changesystem":
twistos = input("What variant do you want to switch to? (Just input 'flash' if you want to go back to the original shell.) ")
if twistos in ('zsh', 'bash', 'csh', 'powershell', 'fish', 'pufferfish'):
sp.run(['python', f'flash{twistos}.py'])
else:
sp.run(['python', 'flash.py'])
elif cmd == "cal" or cmd == "calculator" or cmd == "math":
run_script('dep/calcshell.py')
elif cmd == "webs" or cmd == "websource":
# Open a local HTML file in the default web browser
webbrowser.open('http://127.0.0.1:5500/gratitudepay.org/website.html') # Adjust the URL as needed
elif cmd == "greet" or cmd == "sayhello" or cmd == "hellomessage":
print("Hello,", f"{os.getlogin()}!",)
elif cmd == "echo" or cmd == "repeat" or cmd == "say":
message = input("Enter a message to echo: ")
print(f"Echo: {message}")
elif cmd == "infinite" or cmd == "repeattext" or cmd == "infiniteprint":
while_text = input("Enter text: ")
while True:
print(while_text)
elif cmd == "uptime" or cmd == "systemuptime" or cmd == "showuptime":
uptime_seconds = int(ti.time() - psutil.boot_time())
uptime_string = str(dt.timedelta(seconds=uptime_seconds))
print(f"System Uptime: {uptime_string}")
elif cmd == "clear" or cmd == "cls" or cmd == "cleanscreen":
os.system('cls' if os.name == 'nt' else 'clear')
elif cmd == "listusb" or cmd == "usblist" or cmd == "showusbdevices":
sp.run(['wmic', 'diskdrive', 'list', 'brief'])
elif cmd == "systeminfo" or cmd == "info" or cmd == "showinfo":
sp.run(['systeminfo'])
elif cmd == "h" or cmd == "hist" or cmd == "history":
sp.run(['h']) or sp.run(['history'])
elif cmd == "netstat" or cmd == "networkstatus" or cmd == "shownetwork":
sp.run(['netstat', '-a'])
elif cmd.startswith("chmod "):
try:
permission, file_name = cmd.split(" ", 2)[1:]
permission = int(permission, 8)
os.chmod(os.path.join(base_dir, file_name), permission)
print(f"Permissions for '{file_name}' changed successfully.")
except (ValueError, FileNotFoundError) as e:
print(f"Error: {e}")
elif cmd == "tasklist" or cmd == "processlist" or cmd == "showtasks":
sp.run(['tasklist'])
# Check if the command starts with 'git'
if cmd == "git" or cmd == "gitcmd" or cmd == "gitcommand":
gitc = input("Enter Git command (and a URL if necessary.)")
sp.run(['git', f'{gitc}'])
if cmd == "shutdown" or cmd == "turnoff" or cmd == "poweroff":
sp.run(['shutdown', '/s'])
elif cmd == "restart" or cmd == "reboot" or cmd == "softrestart":
sp.run(['shutdown', '/r'])
elif cmd == "inst" or cmd == "instantshutdown":
sp.run(['shutdown', '/s', '00'])
elif cmd == "insrs" or cmd == "instantrestart":
sp.run(['shutdown', '/r' '00'])
elif cmd == "winrecov" or cmd == "recovery":
sp.run(['shutdown', '/r', '/o', '/f', '/t', '00'])
elif cmd == "cpuinfo" or cmd == "processorinfo" or cmd == "showcpuinfo":
print("CPU Information:")
print(f" CPU Cores: {psutil.cpu_count(logical=False)} physical, {psutil.cpu_count(logical=True)} logical")
print(f" CPU Usage: {psutil.cpu_percent()}%")
elif cmd.startswith("mkdir "):
dir_name = cmd.split(" ", 1)[1].strip()
try:
os.mkdir(os.path.join(base_dir, dir_name))
print(f"Directory '{dir_name}' created successfully.")
except FileExistsError:
print(f"Directory '{dir_name}' already exists.")
elif cmd.startswith("rmdir "):
dir_name = cmd.split(" ", 1)[1].strip()
try:
os.rmdir(os.path.join(base_dir, dir_name))
print(f"Directory '{dir_name}' removed successfully.")
except FileNotFoundError:
print(f"Directory '{dir_name}' not found.")
elif cmd.startswith("rm ") or cmd.startswith("remove "):
file_name = cmd.split(" ", 1)[1].strip()
try:
os.remove(os.path.join(base_dir, file_name))
print(f"File '{file_name}' removed successfully.")
except FileNotFoundError:
print(f"File '{file_name}' not found.")
elif cmd.startswith("copy "):
file_source, file_destination = map(str.strip, cmd.split(" ", 2)[1:])
try:
shutil.copyfile(os.path.join(base_dir, file_source), os.path.join(base_dir, file_destination))
print(f"File '{file_source}' copied to '{file_destination}' successfully.")
except FileNotFoundError:
print(f"File '{file_source}' not found.")
except PermissionError:
print(f"Permission denied to copy '{file_source}'.")
elif cmd.startswith("rename "):
old_name, new_name = map(str.strip, cmd.split(" ", 2)[1:])
try:
os.rename(os.path.join(base_dir, old_name), os.path.join(base_dir, new_name))
print(f"Renamed '{old_name}' to '{new_name}' successfully.")
except FileNotFoundError:
print(f"File or directory '{old_name}' not found.")
elif cmd == "listprocesses" or cmd == "showprocesses" or cmd == "processlist":
processes = psutil.process_iter(['pid', 'name'])
print("Running Processes:")
for process in processes:
print(f" {process.info['pid']}: {process.info['name']}")
elif cmd.startswith("kill ") or cmd.startswith("terminate ") or cmd.startswith("endprocess "):
pid_to_kill = cmd.split(" ", 1)[1].strip()
try:
process = psutil.Process(int(pid_to_kill))
process.terminate()
print(f"Process with PID {pid_to_kill} terminated successfully.")
except psutil.NoSuchProcess:
print(f"No process found with PID {pid_to_kill}.")
elif cmd == "diskusage" or cmd == "showdiskusage" or cmd == "storageinfo":
disk_usage = psutil.disk_usage(base_dir)
print("Disk Usage Information:")
print(f" Total Disk Space: {disk_usage.total / (1024 ** 3):.2f} GB")
print(f" Used Disk Space: {disk_usage.used / (1024 ** 3):.2f} GB")
print(f" Free Disk Space: {disk_usage.free / (1024 ** 3):.2f} GB")
print(f" Disk Usage Percentage: {disk_usage.percent}%")
elif cmd == "help" or cmd == "?":
print("Available commands:")
print(" version (ver, v) - Check flash version")
print(" get (g, fetch) - Update flash")
print(" cd [directory] (changedir) - Change current directory")
print(" setbase (setbasedir, setdir) - Set base directory")
print(" ls (list, dirlist) - List files in the current directory")
print(" time (currenttime, showtime) - Display current time")
print(" !number (randomnumber, randnum) - Generate a random number")
print(" date (currentdate, showdate) - Display current date")
print(" whoami (myname, username) - Display current username")
print(" !info (flashinfo, information) - Display flash information (NETWORK)")
print(" weather (forecast, getweather) - Check weather")
print(" randomword (randword, randomtext) - Display a random word")
print(" download (fetchfile, getfile) - Download a file")
print(" search [query] - Search Google")
print(" translate [text] - Translate text")
print(" calculate [expression] - Calculate a math expression")
print(" checkinternet (internetstatus, pinggoogle) - Check internet status")
print(" calendar (showcalendar, viewcalendar) - Display calendar")
print(" rolladice (dice, rolldice) - Roll a six-sided dice")
print(" wiki [topic] - Search Wikipedia")
print(" quote [author] - Get a random quote by the author")
print(" info (flashiinfo, information) - Display flash information")
print(" twister (switchshell, changesystem) - Switch to another shell variant")
print(" cal (calculator, math) - Open calculator shell")
print(" greet (sayhello, hellomessage) - Greet the user")
print(" echo (repeat, say) - Repeat a message")
print(" infinite (repeattext, infiniteprint) - Print a message infinitely")
print(" uptime (systemuptime, showuptime) - Display system uptime")
print(" clear (cls, cleanscreen) - Clear the screen")
print(" listusb (usblist, showusbdevices) - List connected USB devices")
print(" systeminfo (info, showinfo) - Display system information")
print(" netstat (networkstatus, shownetwork) - Display network status")
print(" chmod [permission] [file] - Change file permissions")
print(" tasklist (processlist, showtasks) - List running processes")
print(" git (rungit, gitcommand) - Run a Git command")
print(" shutdown (turnoff, poweroff) - Shutdown the system")
print(" restart (reboot, softrestart) - Restart the system")
print(" cpuinfo (processorinfo, showcpuinfo) - Display CPU information")
print(" mkdir [directory] - Create a new directory")
print(" rmdir [directory] - Remove an empty directory")
print(" rm [file] (remove) - Remove a file")
print(" copy [source] [destination] - Copy a file")
print(" rename [old_name] [new_name] - Rename a file or directory")
print(" listprocesses (showprocesses, processlist) - List running processes")
print(" kill [pid] (terminate, endprocess) - Terminate a process")
print(" diskusage (showdiskusage, storageinfo) - Display disk usage")
print(" help (?) - Display this help message")
print(" exit (quit) - Exit flash")
print(" graph (plan) - Create a graph")
elif cmd == "exit" or cmd == "quit":
print("Exiting flash. Goodbye!")
sys.exit()
else:
print(f"Command not recognized / executed successfully: {cmd}")
except FileNotFoundError:
print("No file found. You may need to install it.")