Skip to main content

Send keys to any tmux pane

Project description

key2pane

Tests

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, window 0, and pane 0, the command is retrieved.
  • If this command matches the regex bash|zsh|fish, the keys echo '{0} {1}' are selected.
  • The placeholders {0} and {1} are replaced with the positional arguments foo and bar.
  • The formatted keys are send to the pane, using tmux send-keys. After that, the Enter 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,
  "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 a keys property. The keys are send to the target pane when the regex 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

key2pane-0.0.1.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

key2pane-0.0.1-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file key2pane-0.0.1.tar.gz.

File metadata

  • Download URL: key2pane-0.0.1.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for key2pane-0.0.1.tar.gz
Algorithm Hash digest
SHA256 0fb526f33ac5536b3f4d63f78f34bc2dfef3b35688527c66be076b36713f7adf
MD5 92c59e240de2df4a25816bd793b6f924
BLAKE2b-256 01b8e7c401f9831d7d818b261d1bfc2fa84ff7b2bbffe4df25eb4c3358b25cf5

See more details on using hashes here.

File details

Details for the file key2pane-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: key2pane-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for key2pane-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3100c2babaf61008b2c1e5f80ec5bb51da0a8f45a2de8208f2c574867405664c
MD5 a534f1afc989c5a4d6cc4355b5a41041
BLAKE2b-256 b232e05684e600d9574eac4a1cd56c0c90646b47f98e5585713cda5ad08a4118

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page