使用zsh中的预定义命令字符串启动下一个提示

时间:2016-12-07 08:59:40

标签: zsh

我有一个以字符串形式返回命令的函数。如何将此命令作为字符串传递给下一个提示而不执行它。

例如:

函数commandGeneratorcd ~/some_dir/作为字符串返回。现在我在终端中执行commandGenerator

> commandGenerator
> cd ~/some_dir/
                ^
                Cursor position after execution of commandGenerator.
                I can now edit the command or hit enter to execute it.

1 个答案:

答案 0 :(得分:2)

内置-z命令的print选项将文本写入命令缓冲区。

% print -z "cd ~/some_dir/"
% cd ~/some_dir

您可以在commandGenerator功能中拨打此电话。当函数退出时,下一个命令行将填充print -z打印的文本。