Sends a sequence of keys to any tmux pane, based on the pane's current command.
key2pane
is a tmux plugin for sending a sequence of keys to a tmux pane, based
on the target pane's command that is running. Which keys are sent can be
configured in a json file:
{
// Other settings ...
"actions": [
{
"regex": "bash|zsh|fish",
"keys": ["echo 'Hello, World!'", "Enter"]
}
]
}
When the command of the target pane matches the regex, the keys are sent to the
pane. In this case, the command: echo 'Hello, World!'
is sent to the pane, and
then the Enter
key is sent.
** TODO: Add a demo gif here **
Install key2pane
using pip:
pip install key2pane
which panel will install the key2pane
command.
Expanding on the example in the introduction, consider the following configuration:
{
// Other settings ...
"session": "test",
"window": 0,
"index": 0,
"actions": [
{
"regex": "bash|zsh|fish",
"keys": ["echo '{0} {1}'", "Enter"]
}
]
}
When we run the key2pane foo bar
command, the following will happen:
- For the session
test
, window0
, and pane0
, the command is retrieved. - If this command matches the regex
bash|zsh|fish
, the keysecho '{0} {1}'
are selected. - The placeholders
{0}
and{1}
are replaced with the positional argumentsfoo
andbar
. - The formatted keys are send to the pane, using
tmux send-keys
. After that, theEnter
key is sent. - As a result, the command
echo 'foo bar'
is executed in the pane.
When you run the key2pane
command for the first time, no configuration file
is exists yet. You need to create a configuration file in the default location
~/.config/key2pane/config.json
, or specify a different location using the
--config
option. As a starting point, you can use the following example:
{
"session": null,
"window": null,
"index": null,
"reset": false,
"logfile": null,
"loglevel": null,
"actions": [
{
"regex": "bash|zsh|fish",
"keys": ["echo '{0}'", "Enter"]
},
{
"regex": "python[0-9]*",
"keys": ["print('{0}')", "Enter"]
}
]
}
Since comments are not allowed in JSON, notes are placed here:
- session: the session name. Default: current session.
- window: the window index. Default: current window.
- index: the pane index. Default: current pane.
- reset: send a Ctrl-C before sending the keys. Default: false
- logfile: the log file. Default: ~/.local/state/key2pane/key2pane.log
- loglevel: the log level. Default: WARNING
- actions: a list of actions, containing a
regex
, and akeys
property. Thekeys
are send to the target pane when theregex
matches the command of the target pane.
If you encounter any issues, please report them on the issue tracker at: tmux-key2pane issues
Contributions are welcome! Please see CONTRIBUTING for more information.
Distributed under the MIT License.