From dff6df9dad7037835242d078d45621df7a55bf59 Mon Sep 17 00:00:00 2001 From: HeXiangLong <3234374354@qq.com> Date: Thu, 3 Apr 2025 07:18:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=20main.py=20=E4=B8=AD=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=8E=B7=E5=8F=96=E6=9C=80=E5=90=8E=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index a7ee0fe..3cfdd51 100644 --- a/main.py +++ b/main.py @@ -11,6 +11,16 @@ def completer(text, state): matches = [cmd for cmd in commands + local_files if cmd.startswith(text)] return matches[state] if state < len(matches) else None +# 获取真正的 Last login 信息 +def get_last_login(): + try: + # 使用 `last` 命令获取登录信息 + result = subprocess.run(['last', '-1'], stdout=subprocess.PIPE, text=True) + last_login_line = result.stdout.splitlines()[0] # 获取第一行 + return last_login_line + except Exception as e: + return "Last login: unknown" # 如果出错,返回默认值 + # 模拟一个简单的 zsh 终端 def pseudo_zsh(): # 配置 readline 的自动补全功能 @@ -21,7 +31,7 @@ def pseudo_zsh(): os.system("clear") # 清屏 subprocess.run("cd /", shell=True) # 切换到用户目录 - print(f"Last login: {datetime.now().strftime('%a %b %d %H:%M:%S %Y')} on ttys000") + print(f"{get_last_login()} on ttys000") while True: try: