在 main.py 中添加获取最后登录信息的功能
This commit is contained in:
12
main.py
12
main.py
@@ -11,6 +11,16 @@ def completer(text, state):
|
|||||||
matches = [cmd for cmd in commands + local_files if cmd.startswith(text)]
|
matches = [cmd for cmd in commands + local_files if cmd.startswith(text)]
|
||||||
return matches[state] if state < len(matches) else None
|
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 终端
|
# 模拟一个简单的 zsh 终端
|
||||||
def pseudo_zsh():
|
def pseudo_zsh():
|
||||||
# 配置 readline 的自动补全功能
|
# 配置 readline 的自动补全功能
|
||||||
@@ -21,7 +31,7 @@ def pseudo_zsh():
|
|||||||
|
|
||||||
os.system("clear") # 清屏
|
os.system("clear") # 清屏
|
||||||
subprocess.run("cd /", shell=True) # 切换到用户目录
|
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:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user