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