"Встраивание" функции zsh

С этим можно справиться с помощью сценария AWK:

#!/usr/bin/awk -f
BEGIN { FS = "," }
NR == 1 { value = $1 }
NR == 2 {
    if ($1 == value) print $2
    else print "The value is different"
    exit
}

Это сохраняет первое значение в первой строке, затем сравнивает его с первым значением во второй строке и печатает второе значение, если они равны, или «Значение отличается» в противном случае.Затем он явно завершает работу, чтобы не тратить время на чтение дальнейших строк.

2
11.02.2021, 13:34
1 ответ

См. документ(info zsh widgets):

User-defined widgets, being implemented as shell functions, can execute any normal shell command. They can also run other widgets (whether built-in or user-defined) using the zle builtin command. The standard input of the function is redirected from /dev/null to prevent external commands from unintentionally blocking ZLE by reading from the terminal, but read -k or read -q can be used to read characters. Finally, they can examine and edit the ZLE buffer being edited by reading and setting the special parameters described below.

Здесь вы можете отменить это, выполнив:

vim_hist() {
    n=$(sed -n "s|~|$HOME|;s|^> \(.*\)|\1|p" ~/.vim/viminfo | fzf)
    if [ "$n" != "" ] && [ -f "$n" ]; then
        vim < /dev/tty $n
        zle -I
    fi
}

(также вызывает zle -I, чтобы аннулировать приглашение, чтобы оно было перерисовано после возвратаvim)

3
18.03.2021, 22:31

Теги

Похожие вопросы