File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import os
2+ import importlib
3+
4+ #This file ensures that all files from the bin folder are correctly identified by main.
5+ __all__ = []
6+ current_dir = os .path .dirname (__file__ )
7+
8+ for filename in os .listdir (current_dir ):
9+ if filename .endswith (".py" ) and filename != "__init__.py" :
10+ module_name = filename [:- 3 ]
11+ __all__ .append (module_name )
12+ module = importlib .import_module (f"bin.{ module_name } " )
13+ globals ().update (vars (module ))
Original file line number Diff line number Diff line change 1+ from bin .mode import mode
2+ import os
3+
4+ def cl (args = []):
5+ osName = mode ()
6+
7+ if osName == "dos" :
8+ clear = os .system ("cls" )
9+ else :
10+ clear = os .system ("clear" )
11+
12+ return clear
13+
14+ def man (args = []):
15+ output = "Clears the screen. Has no positional arguments, providing them will have no effect."
16+ return output
17+
Original file line number Diff line number Diff line change 1+ import os
2+
3+ def cwd (args = []):
4+ cwd = os .getcwd ()
5+ return cwd
6+
7+ def man (args = []):
8+ output = "Prints the current working directory to the screen. This command supports no positional arguments. Providing them will have no effect."
9+ return output
Original file line number Diff line number Diff line change 1+ import os
2+
3+ def echo (args = []):
4+ combined = ""
5+ for item in args :
6+ combined += item
7+
8+ output = combined
9+
10+ return combined
11+
12+ def man (args = []):
13+ output = "Returns any text typed where positional arguments would usually be present as raw text.\n Sometimes useful for piping."
14+ return output
Original file line number Diff line number Diff line change 1+ import subprocess
2+
3+ def kern (args = []):
4+ kernCmd = subprocess .run (args , capture_output = True , text = True )
5+ output = kernCmd .stdout .strip ("\n " )
6+
7+ return output
8+
9+ def man (args = []):
10+ output = "Runs commands through your system's terminal.\n You can perform most basic and some advanced actions through here, but some access is restricted by the subprocess module's limitations.\n A good way to get things done that CoreShell can't do."
11+ return output
12+
Original file line number Diff line number Diff line change 1+ import os
2+ from bin .sz import sz
3+ import colours
4+
5+ def ls (args = []):
6+ validArgs = ["--pretty" ,"--bare" ]
7+ dirCont = os .listdir ()
8+ #args --pretty, --bare, --sep - [SEP]
9+ if len (args ) == 0 :
10+ response = ""
11+ for item in dirCont :
12+ if item != dirCont [- 1 ]:
13+ if os .path .isfile (item ):
14+ response += item + "\n "
15+ else :
16+ response += "\x1B [1m" + item + colours .reset ()+ "\n "
17+ else :
18+ response += item
19+ dirCont = response
20+
21+ if len (args ) > 0 :
22+ if "--pretty" in args :
23+ response = ""
24+ response += "------\n "
25+
26+ for item in dirCont :
27+ if os .path .isfile (item ):
28+ response += "🗎 - " + item + " " + str (sz ([item ,"--unit" ])) + "\n "
29+ else :
30+ response += "🗀 - \x1B [1m" + item + colours .reset () + " " + str (sz ([item ,"--unit" ])) + "\n "
31+
32+ response += "------"
33+ dirCont = response
34+ elif "--bare" in args :
35+ pass
36+ elif args [0 ] not in validArgs :
37+ dirCont = "ls: invalid positional arguments were given."
38+ elif len (args ) > 1 :
39+ dirCont = "ls: too many positional arguments were provided."
40+
41+
42+
43+ return dirCont
44+
45+ def man (args = []):
46+ output = "Lists all of the files and directories in the current working directory.\n Use arguments such as --pretty to print the list in a more human readable format, or --bare to print the list in a more managable format for piping."
47+ return output
48+
Original file line number Diff line number Diff line change 1+ import importlib
2+
3+ def man (args = []):
4+ if not args :
5+ output = "man: no command specified.\n Usage: man [cmdname]"
6+
7+ if args [0 ] != "man" :
8+ try :
9+ command_func = globals ().get (args [0 ])
10+
11+ if not command_func :
12+ command_module = importlib .import_module (f"bin.{ args [0 ]} " )
13+ command_func = getattr (command_module , "man" , None )
14+
15+ if not command_func :
16+ output = f"man: command '{ args [0 ]} ' does not exist or lacks a manual."
17+
18+ output = command_func ()
19+ except ImportError :
20+ output = f"man: command '{ args [0 ]} ' not found in 'bin'."
21+ except Exception as e :
22+ output = f"man: an error occurred while accessing the manual for '{ args [0 ]} ': { e } "
23+ else :
24+ output = "Provides you with a manual for a command.\n Usage: man [cmdname]"
25+
26+ return output
Original file line number Diff line number Diff line change 1+ import os
2+ #Returns the type of operating system shell is being run within.
3+ def mode (args = []):
4+ if str (os .name ).lower () in ["nt" ,"dos" ]:
5+ mode = "dos"
6+ elif str (os .name ).lower () in ["posix" ,"linux" ]:
7+ mode = "linux"
8+ else :
9+ mode = "name"
10+
11+ return mode
12+
13+ def man (args = []):
14+ output = "Provides you with the name of your host OS. This command supports no positional arguments. Providing them will have no effect."
15+ return output
Original file line number Diff line number Diff line change 1+ import os
2+
3+ def sz (args = []):
4+ sizeByte = 0
5+
6+ if len (args ) > 0 :
7+ if os .path .isfile (args [0 ]):
8+ sizeByte = os .path .getsize (args [0 ])
9+ else :
10+ for path , dirs , files in os .walk (args [0 ]):
11+ try :
12+ for f in files :
13+ fp = os .path .join (path , f )
14+ sizeByte += os .path .getsize (fp )
15+ except :
16+ pass
17+
18+ if "--unit" in args :
19+ if sizeByte < 1000 :
20+ size = str (sizeByte ) + "B"
21+ elif sizeByte >= 1000 and sizeByte < 1000000 :
22+ size = str (round (sizeByte / 1000 , 2 )) + "KB"
23+ elif sizeByte >= 1000000 and sizeByte < 1000000000 :
24+ size = str (round (sizeByte / 1000000 , 2 )) + "MB"
25+ elif sizeByte >= 1000000000 and sizeByte < 1000000000000 :
26+ size = str (round (sizeByte / 1000000000 , 2 )) + "GB"
27+ elif sizeByte >= 1000000000000 and sizeByte < 1000000000000000 :
28+ size = str (round (sizeByte / 1000000000000 , 2 )) + "TB"
29+
30+ sizeFormat = size
31+ else :
32+ sizeFormat = sizeByte
33+ else :
34+ sizeFormat = "sz: no such file or directory was given."
35+
36+ if sizeFormat == 0 or sizeFormat == "0" or sizeFormat == "0B" :
37+ if os .path .exists (args [0 ]):
38+ if "--unit" in args :
39+ sizeFormat = "0B"
40+ else :
41+ sizeFormat = 0
42+ else :
43+ sizeFormat = f"sz: '{ args [0 ]} ' - the file or directory does not exist."
44+
45+ return sizeFormat
46+
47+ def man (args = []):
48+ output = "Provides you with the size of a given file/directory.\n Takes positional arguments:\n --unit: prints the size in a more human readable fashion with the unit.\n By default this command provides you the size of the file in bytes."
49+ return output
Original file line number Diff line number Diff line change 1+ from datetime import datetime
2+
3+ def time (args = []):
4+ currentTime = datetime .now ()
5+ #args: --date, --bare, --pretty, --12
6+ validArgs = ["--date" ,"--dateus" ,"--bare" ,"--pretty" ]
7+ if len (args ) == 1 :
8+ if "--date" in args :
9+ output = currentTime .strftime ("%d/%m/%y" )
10+ if "--dateus" in args :
11+ output = currentTime .strftime ("%x" )
12+ if "--bare" in args :
13+ output = currentTime
14+ if "--pretty" in args :
15+ output = currentTime .strftime ("%H:%M:%S, %d %b %Y" )
16+ elif len (args ) > 1 :
17+ output = "time: too many positional arguments were provided."
18+ else :
19+ output = currentTime .strftime ("%H:%M:%S" )
20+
21+ if len (args ) > 0 and args [0 ] not in validArgs :
22+ output = f"time: positional argument '{ args [0 ]} ' not recognised."
23+
24+ return output
25+
26+ def man (args = []):
27+ output = "Prints the time/date to the screen.\n Supports positional arguments:\n --date: provides the date.\n --dateus: provides the date in US format.\n --bare: provides the date in the standard way that datetime provides the data.\n --pretty: prints the time and the date at the same time in a human readable format."
28+ return output
29+
You can’t perform that action at this time.
0 commit comments