zsh function to put arbitrary string into the line editor

时间:2019-04-23 15:09:43

标签: zsh

I'd like to create a zsh-function that will put a computed string into the line editor, e.g.

insert_foo() {
  # Do something that will put the string "foo" in the line editor
}

$ insert_foo
$ foo # <- "foo" appears in the line editor, without actually executing it

I know this is possible within a zle-widget, but can it also be it's own command?

1 个答案:

答案 0 :(得分:0)

我们可以使用print -z

insert_foo() {
  print -z "foo"
}

这是print -z的zsh文档的副本:

  

print [ -abcDilmnNoOpPrsSz ] [ -u n ] [ -f format ] [ -C cols ]
  ...
  -z将参数推入编辑缓冲区堆栈中,并用空格分隔。

     

--- zshbuiltin(1), shell builtin commands, print