Skip to content

Commit ffa54bf

Browse files
add scripts
1 parent d823795 commit ffa54bf

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

LICENSE renamed to LICENSE.md

File renamed without changes.

src/lib_hack.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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)

src/shell_hack,py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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

src/shell_hack_lite.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from subprocess import run
2+
while True: run(input("$ "), shell=True)

0 commit comments

Comments
 (0)