实时搜索前 10 场比赛作为 zsh-history 的预览?

实时搜索前 10 场比赛作为 zsh-history 的预览?

我看到过带有预览的历史记录实时搜索,它在 BUFFER 行下方的列表中显示了历史记录中的前 10 个匹配项,该列表在每次击键时都会更新,并且在其余时间的行为类似于标准的 ctrl+r 搜索。 (但是拥有该功能的用户已经消失 3 周且无法联系)

tl;dr:有谁知道这个插件/脚本并可以将其链接到我

或者帮我编程并正确更新列表?

我当前的代码看起来像这样,但没有更新(只是从一开始的静态列表,搜索看起来并不完全自然)

zle -N search

bindkey "^R" search

search () {
echo "";
fc -ln -30 | grep $(printf "%q\n" "$BUFFER");
<standard-history-backwards-search-widget>; #not on linux atm
}

答案1

你可能已经知道zsh-history-substring-search

据我所知,它没有进行您所看到的预览,但除此之外它似乎非常相似。

如果您不知道,值得尝试。

zsh-history-substring-search紧密基于fishshell 的历史搜索。fish在交互方面有一些相当先进的功能,当然值得学习。不幸的是,它不适合作为通用 shell,因为它的语法与bash或 之类的 shell 有很大不同zsh


也不是解决方案,但密切相关:

zsh 发行版包含 widget history-beginning-search-menu,它正在执行您所寻找的部分功能 - 但不具有可用性:

autoload -Uz history-beginning-search-menu
zle -N history-beginning-search-menu
bindkey '^P' history-beginning-search-menu

它列出了从当前输入开始的历史记录行,并在列表中按编号进行选择。

在以下位置按Control+ :P|

$ dialog  -| 
Enter digit:
1 dialog  --infobox text 5 15| sed 's/...104..//'
2 dialog  --yesno SomeText 0 0
3 dialog  --yesno text 0 0
4 dialog  --yesno text 5 15

答案2

回答您问题的替代部分,
“...帮助我对其进行编程并正确更新列表”:

您可以直接使用列出完成项、更新列表或清除列表的功能;那是zle -R
要写出您自己的“非托管”文本,可以使用zle -M.
pinfo zsh

zle -R [ -c ] [ DISPLAY-STRING ] [ STRING ... ]
zle -M STRING
[ ... ]

    -R [ -c ] [ DISPLAY-STRING ] [ STRING ... ]
          Redisplay the command line; this is to be called from within
          a user-defined widget to allow changes to become visible.  If
          a DISPLAY-STRING is given and not empty, this is shown in the
          status line (immediately below the line being edited).

          If the optional STRINGs are given they are listed below the
          prompt in the same way as completion lists are printed. If no
          STRINGs are given but the -c option is used such a list is
          cleared.

          Note that this option is only useful for widgets that do not
          exit immediately after using it because the strings displayed
          will be erased immediately after return from the widget.

          This command can safely be called outside user defined
          widgets; if zle is active, the display will be refreshed,
          while if zle is not active, the command has no effect.  In
          this case there will usually be no other arguments. [...]

    -M STRING
          As with the -R option, the STRING will be displayed below the
          command line; unlike the -R option, the string will not be
          put into the status line but will instead be printed normally
          below the prompt.  This means that the STRING will still be
          displayed after the widget returns (until it is overwritten
          by subsequent commands).

zstyle ':completion:*' ...我确信布局的细节是通过某种方式配置的。

shell 内置的一些选项print本身可以提供帮助,或者通过创建一个字符串,然后使用以下命令在命令行下打印该 字符串zle -M
pinfo zsh

print [ -abcDilmnNoOpPrsSz ] [ -u N ] [ -f FORMAT ] [ -C COLS ]
[ -R [ -en ]] [ ARG ... ]
     With the '-f' option the arguments are printed as described by
     printf.  With no flags or with the flag '-', the arguments are
     printed on the standard output as described by echo, with the
     following differences: the escape sequence '\M-X' metafies the
     character X (sets the highest bit), '\C-X' produces a control
     character ('\C-@' and '\C-?' give the characters NUL and delete),
     and '\E' is a synonym for '\e'.  Finally, if not in an escape
     sequence, '\' escapes the following character and is not printed.

    [  ...  ]
    -a
          Print arguments with the column incrementing first.  Only
          useful with the -c and -C options.

    -b
          Recognize all the escape sequences defined for the bindkey
          command, see *note Zle Builtins::.

    -c
          Print the arguments in columns.  Unless -a is also given,
          arguments are printed with the row incrementing first.

    -C COLS
          Print the arguments in COLS columns.  Unless -a is also given,
          arguments are printed with the row incrementing first.

    -l
          Print the arguments separated by newlines instead of spaces.

    -m
          Take the first argument as a pattern (should be quoted), and
          remove it from the argument list together with subsequent
          arguments that do not match this pattern.

    -n
          Do not add a newline to the output.

    -o
          Print the arguments sorted in ascending order.

    -p
          Print the arguments to the input of the coprocess.

    -P
          Perform prompt expansion (see *note Prompt Expansion::).

    -s
          Place the results in the history list instead of on the
          standard output.  Each argument to the print command is
          treated as a single word in the history, regardless of its
          content.

    -S
          Place the results in the history list instead of on the
          standard output.  In this case only a single argument is
          allowed; it will be split into words as if it were a full
          shell command line.  The effect is similar to reading the
          line from a history file with the HIST_LEX_WORDS option
          active.

    -u N
          Print the arguments to file descriptor N.

    -z
          Push the arguments onto the editing buffer stack, separated
          by spaces.

    [  ...  ]

我记得当完成值包含空格时有一个难以克服的障碍:大多数完成机制都适用于空格分隔的单词。因此,这可能需要小心、解决方法或技巧来解决。
但我不介意交互式实时十行历史预览中的空间是否是不同类型的空间字符......或者非常小的中心点,或者黑底黑字......

相关内容