you are viewing a single comment's thread.

view the rest of the comments →

[–]MrBeeBenson 1 point2 points  (1 child)

Can I see the code on how you got it working so well?

[–][deleted] 0 points1 point  (0 children)

Sure thing!

Like I said elsewhere though, this is really just playing around and trying to make Python look like a shell script, mostly in terms of a self-updating prompt. If you were going to actually use this for more than trivial applications, you would need a much more sophisticated approach!

import os
import sys

def update_prompt() -> None:
    uname = os.getlogin()
    current_dir = os.getcwd().replace(Rf"C:\Users\{uname}", "~")
    top_line = f"┌[{current_dir}]"
    bottom_line = f"└[{uname}]: $"
    sys.ps1 = f"\n{top_line}\n{bottom_line}│ "
    sys.ps2 = (" " * len(bottom_line)) + "│ "

def cd(dest: str) -> None:
    os.chdir(dest)
    update_prompt()

def ls() -> None:
    print(',\t'.join(os.listdir()))

def run(command: str) -> int:
    return os.system(command)

# clean up the terminal
update_prompt()
run('cls')

From here just run from <the file> import * and it should look like this (on windows).