File tree 4 files changed +54
-0
lines changed
4 files changed +54
-0
lines changed File renamed without changes.
Original file line number Diff line number Diff line change
1
+ from subprocess import run
2
+ from importlib import import_module
3
+ from types import ModuleType
4
+
5
+ def install_lib (libname : str ) -> ModuleType :
6
+ while True :
7
+ try :
8
+ return import_module (libname )
9
+ except ModuleNotFoundError :
10
+ run (f"python3 -m pip install { libname } " , shell = True )
Original file line number Diff line number Diff line change
1
+ import os
2
+ import readline
3
+ from subprocess import run
4
+ from socket import gethostname
5
+ from getpass import getuser
6
+
7
+
8
+ # Settings
9
+ # ---------------
10
+ UNAME = "imjamnotjelly"
11
+ STARTING_DIR = ""
12
+ HOSTNAME = "codehs"
13
+ # ---------------
14
+
15
+ def set_default(var, default):
16
+ return var or default
17
+
18
+ def dash_to_space(text):
19
+ return text.strip(" ").replace(" ", "-")
20
+
21
+ UNAME = dash_to_space(set_default(UNAME, getuser()))
22
+ STARTING_DIR = set_default(STARTING_DIR, ".")
23
+ HOSTNAME = dash_to_space(set_default(HOSTNAME, gethostname()))
24
+
25
+ FILE_ERRS = (
26
+ PermissionError,
27
+ FileNotFoundError
28
+ )
29
+
30
+ run(f"cd {STARTING_DIR}", shell=True)
31
+ os.chdir(STARTING_DIR)
32
+ run("clear", shell=True)
33
+ while True:
34
+ cmd = input(f"{UNAME}@{HOSTNAME}:{os.getcwd() if os.getcwd() != '/' else '~'} $ ")
35
+
36
+ run(cmd, shell=True)
37
+
38
+ try:
39
+ if (cmd:=cmd.strip(" ")).startswith("cd"):
40
+ os.chdir(cmd[3:])
41
+ except FILE_ERRS:
42
+ pass
Original file line number Diff line number Diff line change
1
+ from subprocess import run
2
+ while True : run (input ("$ " ), shell = True )
You can’t perform that action at this time.
0 commit comments