Skip to content

Commit

Permalink
Introduce PS1 configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
bill88t committed May 22, 2024
1 parent f1f7d46 commit d48bc3d
Showing 1 changed file with 37 additions and 19 deletions.
56 changes: 37 additions & 19 deletions source/be.py
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,9 @@ class based:
"history-file": "/home/board/.history",
"history-size": "10",
"return": "0",
"PSA": "1",
"PS1": "{white_t}[{cyan_t}{user}{white_t}@{cyan_t}{hostname}{white_t} | {yellow_t}{path}{white_t}]{blue_t}> {endc}",
"PS2": "{white_t}{path_short} {bang} {endc}",
}

from os import uname
Expand Down Expand Up @@ -1348,6 +1351,39 @@ def process_failure(err) -> None:
gc.collect()
gc.collect()

def getPS() -> str:
cPS = be.api.getvar("PSA")
res = be.api.getvar("PS" + cPS)
del cPS
for i in [["{user}", "USER"], ["{hostname}", "HOSTNAME"]]:
res = res.replace(i[0], be.api.getvar(i[1]))
cwdp = be.api.fs.resolve()
res = res.replace("{path}", cwdp)
if "{path_short}" in res:
if cwdp != "&/":
cwds = cwdp[cwdp.rfind("/") :]
else:
cwds = "&"
if len(cwds) - 1:
cwds = cwds.replace("/", "")
res = res.replace("{path_short}", cwds)
for i in [
"{underline}",
"{bold}",
"{endc}",
"{black_t}",
"{red_t}",
"{green_t}",
"{yellow_t}",
"{blue_t}",
"{magenta_t}",
"{cyan_t}",
"{white_t}",
]:
res = res.replace(i, getattr(colors, i[1:-1]))
res = res.replace("{bang}", "#" if be.api.getvar("USER") == "root" else "$")
return res

def autorun() -> int:
launch_process("autorun")
be.io.ledset(3) # act
Expand Down Expand Up @@ -1814,25 +1850,7 @@ def shell(led: bool = True, nalias: bool = False) -> int:
while ((command_input == None) or (command_input == "\n")) and not pv[
0
]["Exit"]:
term.trigger_dict["prefix"] = (
colors.white_t
+ "["
+ colors.cyan_t
+ be.based.system_vars["USER"]
+ colors.white_t
+ "@"
+ colors.cyan_t
+ be.based.system_vars["HOSTNAME"]
+ colors.white_t
+ " | "
+ colors.yellow_t
+ be.api.fs.resolve()
+ colors.white_t
+ "]"
+ colors.blue_t
+ "> "
+ colors.endc
)
term.trigger_dict["prefix"] = be.based.getPS()
if term.trigger_dict != vr("trigger_dict_bck"):
# Update backup
vr("trigger_dict_bck", term.trigger_dict.copy())
Expand Down

0 comments on commit d48bc3d

Please sign in to comment.