
clear
只有當終端機中的輸入在 zsh shell 中為空時,我才嘗試將雙選項卡綁定到命令。
到目前為止,我所取得的成就始終是使用雙選項卡刪除,但如果可能的話,我想添加條件,將以下內容添加到 .zshrc 中:
bindkey -s '\t\t' 'clear^M'
也許,我是否需要使用鍵綁定呼叫自訂函數來檢查輸入是否為空?
有什麼想法可以解決這個問題嗎?
謝謝!
答案1
此行為可以透過以下程式碼實現:
if ! typeset -f magic-double-tab-cmd >/dev/null; then
function magic-double-tab-cmd {
echo 'clear'
}
fi
function magic-double-tab {
# Only run magic-double-tab commands when the command line is empty and
# when on the first line (PS1)
if ! (( $#BUFFER )) && [[ "$CONTEXT" == start ]]; then
BUFFER=$(magic-double-tab-cmd)
zle accept-line -w
fi
}
zle -N magic-double-tab
bindkey '\t\t' magic-double-tab
取自魔法輸入儲存庫。
這與 magic-enter 插件的做法類似,但用 tab 代替。