tmux:绑定键以使用预定义命令打开命令提示符

tmux: Bind key to open command prompt with predefined command

我想绑定一个键来在我的 tmux 会话中打开一个命令提示符,但是有一个准备好执行的预定义命令。

示例:按 <prefix> + p 应打开命令提示符:source-file ~/.tmux/ 光标位于行尾,准备写入要获取的文件名。

我知道如何使用快捷键打开命令提示符,但不知道如何使用预定义命令填充它。

有什么办法可以实现吗?

知道了!

bind p command-prompt -I "source-file ~/.tmux/"

-I 选项就是答案。

来自 tmux 手册页:

command-prompt [-I inputs] [-p prompts] [-t target-client] [template]

Open the command prompt in a client. This may be used from inside tmux to execute commands interactively.

If template is specified, it is used as the command. If present, -I is a comma-separated list of the initial text for each prompt. If -p is given, prompts is a comma-separated list of prompts which are displayed in order; otherwise a single prompt is displayed, constructed from template if it is present, or `:' if not.

Both inputs and prompts may contain the special character sequences supported by the status-left option.

Before the command is executed, the first occurrence of the string %%' and all occurrences of%1' are replaced by the response to the first prompt, the second %%' and all%2' are replaced with the response to the second prompt, and so on for further prompts. Up to nine prompt responses may be replaced Po %1' to%9' Pc .