Send keys to any tmux pane
Project description
key2pane
Sends a sequence of keys to any tmux pane, based on the pane's current command.
Contents
Introduction
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 **
Installation
Install key2pane
using pip:
pip install key2pane
which panel will install the key2pane
command.
Usage
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.
Configuration
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,
"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.
- 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.
Troubleshooting
If you encounter any issues, please report them on the issue tracker at: tmux-key2pane issues
Contributing
Contributions are welcome! Please see CONTRIBUTING for more information.
License
Distributed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.