更新终端窗口标题显示,切换目录时自动更新标题

This commit is contained in:
2025-04-02 13:00:12 +08:00
Unverified
parent 49b827503a
commit 88c00aa274

View File

@@ -29,6 +29,11 @@ def pseudo_zsh():
CmdDir = '~'
else:
CmdDir = dir.split('/')[-1]
# 修改终端窗口标题
sys.stdout.write(f"\033]0;20250910553@何相龙 {CmdDir}\007")
sys.stdout.flush()
# 显示提示符并获取用户输入
cmd = input(f"20250910553@何相龙 {CmdDir} % ")
@@ -46,6 +51,10 @@ def pseudo_zsh():
if args[0] == 'cd':
try:
os.chdir(args[1]) # 切换到指定目录
# 更新终端窗口标题
CmdDir = os.getcwd().split('/')[-1]
sys.stdout.write(f"\033]0;20250910553@何相龙 {CmdDir}\007")
sys.stdout.flush()
except IndexError:
print("cd: missing argument") # 缺少参数
except FileNotFoundError: