From e750f645ab14b363c77496be466fda7a4f35014f Mon Sep 17 00:00:00 2001 From: HeXiangLong <3234374354@qq.com> Date: Wed, 2 Apr 2025 13:56:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=BC=BA=E8=87=AA=E5=8A=A8=E8=A1=A5?= =?UTF-8?q?=E5=85=A8=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=94=AF=E6=8C=81=E5=BD=93?= =?UTF-8?q?=E5=89=8D=E7=9B=AE=E5=BD=95=E6=96=87=E4=BB=B6=E4=B8=8E=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E5=91=BD=E4=BB=A4=E7=9A=84=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index e07f275..80fafce 100644 --- a/main.py +++ b/main.py @@ -1,9 +1,13 @@ import os, readline, time, getpass, sys, re, shlex, subprocess -# 自动补全功能,基于系统命令 +# 自动补全功能,基于系统命令和当前目录的文件 def completer(text, state): + # 获取系统命令 commands = os.listdir('/bin') + os.listdir('/usr/bin') + os.listdir('/usr/local/bin') - matches = [cmd for cmd in commands if cmd.startswith(text)] + # 获取当前目录的文件和文件夹 + local_files = os.listdir(os.getcwd()) + # 合并系统命令和当前目录的文件 + matches = [cmd for cmd in commands + local_files if cmd.startswith(text)] return matches[state] if state < len(matches) else None # 模拟一个简单的 zsh 终端 @@ -69,9 +73,9 @@ def pseudo_zsh(): except FileNotFoundError: print(f"zsh: command not found: {args[0]}") except KeyboardInterrupt: - pass # 忽略 Ctrl+C + print("\nUse 'hxl' to exit.") except EOFError: - pass # 忽略 Ctrl+D + break if __name__ == "__main__": pseudo_zsh() \ No newline at end of file