增强自动补全功能,支持当前目录文件与系统命令的合并
This commit is contained in:
12
main.py
12
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()
|
||||
Reference in New Issue
Block a user