%20%E4%B8%8D%E6%9C%83%E8%A7%B8%E7%99%BC%E5%8C%85%E5%90%AB%E7%A0%B4%E6%8A%98%E8%99%9F%E7%9A%84%E6%8C%87%E4%BB%A4%E5%90%8D%E7%A8%B1.png)
我一直在使用 zsh compctl(90 年代末或 00 年代初),但奇怪的是以前從未遇到過這個。今天我意識到,當我打算為update-alternatives
我的完成進行一些compctl 配置時根本沒有觸發,它只是使用了我的標準回退完成(文件)......所以一個非常精簡的簡單示例來顯示問題:
這工作正常:
zshprompt% compctl -k '(arg1 arg2 arg3)' nodash
# typing 'nodash ' and hitting [Tab] once:
zshprompt% nodash arg
# hitting [Tab again]
zshprompt% nodash arg
arg1 arg2 arg3
但這是完整的文件:
# just showing the current dir for reference:
zshprompt% ls .
file2.txt myfile1.txt
zshprompt% compctl -k '(arg1 arg2 arg3)' with-dash
# typing 'with-dash ' and hitting [Tab] once:
zshprompt% with-dash
file2.txt myfile1.txt
如圖所示,使用的是標準補全(列出當前目錄),而不是我用 compctl 添加的補全...
我在線上說明頁面(man zshcompctl)或在線上找不到任何有關此內容的資訊...那麼有人知道如何獲取名稱中帶有破折號的 compctl 匹配命令嗎?
TIA
答案1
已在中確認[電子郵件受保護]郵件列表指出這是一個錯誤並得到了建議的補丁:
--- zsh-5.9.orig/Src/Zle/zle_tricky.c
+++ zsh-5.9/Src/Zle/zle_tricky.c
@@ -1315,6 +1315,8 @@ get_comp_string(void)
ins = (tok == REPEAT ? 2 : (tok != STRING && tok != TYPESET));
zsfree(cmdstr);
cmdstr = ztrdup(tokstr);
+ untokenize(cmdstr);
+ remnulargs(cmdstr);
cmdtok = tok;
/*
* If everything before is a redirection, or anything
我已經通過將更改作為被子補丁應用到重建並安裝的 Debian zsh_5.9-4 原始碼包來測試它......它解決了我的問題。
我現在將繼續運行它,如果它似乎沒有破壞任何其他內容,我將確保它應用於 zsh 上游,期望它最終擴展到所有不同的發行版。
如果您現在遇到問題,並且迫不及待地想解決您的發行版問題,請下載 zsh 5.9.4 原始程式碼並使用上述補丁對其進行修補,然後在本地建立它。如果您希望將其整合到您的發行包中,請按照以下步驟在 Debian 上執行此操作(應該適用於大多數基於 deb 包的發行版):
sudo apt install devscripts libcap-dev libelf-dev libgdbm-dev cm-super-minimal texinfo yodl quilt
mkdir /tmp/zsh_5.9
cd /tmp/zsh_5.9
apt source zsh=5.9-4
/bin/echo -e "1317a1318,1319\n> \t untokenize(cmdstr);\n> \t remnulargs(cmdstr);" > compctl-dash.diff
cd zsh-5.9
export QUILT_PATCHES=debian/patches
export QUILT_REFRESH_ARGS="-p ab --no-timestamps --no-index"
quilt push -a
quilt new compctl-dash.diff
quilt add Src/Zle/zle_tricky.c
patch Src/Zle/zle_tricky.c ../compctl-dash.diff
quilt refresh
quilt pop -a
debuild -b -uc -us
sudo dpkg -i ../zsh_5.9-4_amd64.deb
希望這將在上游得到修復,並在接下來更新軟體包之前到達您的發行版,否則您將不得不重複它(或鎖定 zsh 軟體包版本)直到它:-)