Skip to content

Added socket listening #13896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Added socket listening #13896

wants to merge 10 commits into from

Conversation

shitohana
Copy link

@shitohana shitohana commented Jul 6, 2025

Description

This PR implements Unix socket support for the Helix editor, addressing #387. It enables external processes to send commands to a running Helix instance via a Unix socket, improving automation and integration capabilities. Since a plugin system is not planned for near-term addition, this feature provides a practical way to communicate with Helix from other processes (e.g., opening files from tools like Yazi or Broot).

Changes

  1. Added Unix socket listener at /tmp/helix.sock to receive commands.
  2. Integrated socket handling into the event loop to process incoming messages as MappableCommands.
  3. Included error handling for socket binding, reading, and command parsing, with user feedback via editor status messages.
  4. Updated Application struct to include a socket_rx channel for receiving socket messages.
  5. Used tokio::net::UnixListener and tokio::sync::mpsc for asynchronous socket communication.

Why Merge

  • Resolves Support RPC through a socket. #387, enabling external command integration.
  • Enhances editor extensibility for scripting and automation.
  • Maintains stability with robust error handling and minimal changes to existing code.
  • Unix-only implementation ensures compatibility without affecting other platforms.

Potential Improvements

  • The socket path (/tmp/helix.sock) is currently hardcoded. Making it configurable via the Helix config file would improve flexibility and avoid potential conflicts.
  • Currently this works only on unix systems.
  • Add tests

Diff Summary

  • Modified helix-term/src/application.rs to include Unix socket setup, listener, and command handling.
  • Added socket_rx to Application struct and integrated it into the event loop.
  • Implemented handle_socket_command to parse and execute commands with error reporting.

@shitohana
Copy link
Author

Demo:
ezgif-7f059265da2370

Now socket is created with mode 'o600'
Socket path is configurable with env variable HELIX_SOCKET_PATH
@idealseal
Copy link
Contributor

idealseal commented Jul 7, 2025

I think this should use XDG_RUNTIME_DIR as the socket path by default, see https://man.archlinux.org/man/file-hierarchy.7.en#RUNTIME_DATA and https://specifications.freedesktop.org/basedir-spec/latest/#variables.

Added XDG_RUNTIME_DIR as the first environment variable to
lookup on no HELIX_SOCKET_PATH. If XDG_RUNTIME_DIR is not set
falling back to /tmp.

Added checking, if parent of HELIX_SOCKET_PATH exists or
error otherwise. If using XDG_RUNTIME_DIR or /tmp, `helix`
folder is created there.

For security reasons added list of forbidden commands, which
can be used to inject unwanted data into editor or execute
shell command. I suppose, macros validation should also be added.
Currently forbidden commands are write* and run-shell-command.
If forbidden command is received - error message is shown.
@shitohana shitohana force-pushed the master branch 2 times, most recently from 329715d to 1a18170 Compare July 8, 2025 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support RPC through a socket.
7 participants