更新 main.py,注释掉获取最后登录信息的函数,并修改输出为当前时间

This commit is contained in:
2025-04-03 07:22:29 +08:00
Unverified
parent 7d1f0cde8f
commit f0def1ff3b

20
main.py
View File

@@ -11,15 +11,15 @@ 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" # 如果出错,返回默认值
# # 获取真正的 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():
@@ -31,7 +31,7 @@ def pseudo_zsh():
os.system("clear") # 清屏
subprocess.run("cd /", shell=True) # 切换到用户目录
print(f"{get_last_login()} on ttys000")
print(f"Last login: {datetime.now().strftime('%a %b %d %H:%M:%S %Y')} on ttys000")
while True:
try: