-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 file in already running Helix (like EmacsClient) #2177
Comments
Depends #312 |
I want this for one specific reason. I find that I have occasionally (frequently!) made the mistake of two instances of helix in different terminals editing the same file. This causes me a problem, because I will then have changes in one of the instances overwrite changes that are made in another. The worst case is when I accidentally switch back to an instance that has an older version of the file open. I suppose what I'd really to do is open one instance of helix, perhaps with a workspace-specific configuration (e.g. one color theme for work projects, and a different one for personal projects), and then just send commands to that instance. |
That would be lovely to get this feature. I'm also a long term Vim and emacs user, and I really enjoy |
I want this for a different reason then the one stated above. I use File Browser/Explorer a lot while coding. Because there is no file tree/browser in helix I use a terminal file manager (joshuto) in a vertical pane in same terminal window and I want to open file from the file manager in the same current helix instance. With this feature I'll be able to have File Browser like experience without helix having one natively. |
Hi @Hasnayeen . #!/bin/bash
# $1 = relative file path
# $2 = session name
tabName="Helix"
sessionName="Helix"
if test -z "$1"
then
echo "File name not provided"
exit 1
fi
fileName=$(readlink -f $1) # full path to file
if ! test -z "$2"
then
sessionName="$2"
fi
if ! pgrep -x helix > /dev/null
then
zellij -s "$sessionName" action go-to-tab-name $tabName --create
sleep 0.5
zellij -s "$sessionName" action write-chars "helix"
sleep 0.5
zellij -s "$sessionName" action write 13 # send enter-key
fi
zellij -s "$sessionName" action go-to-tab-name $tabName --create
zellij -s "$sessionName" action write 27 # send escape-key
zellij -s "$sessionName" action write-chars ":open $fileName"
zellij -s "$sessionName" action write 13 # send enter-key
I use |
I would also like this feature. I've changed my main editor from a combination of VSCode and Geany (linux) / Notepad++ (windows) to helix. Sometimes I have scripts that should open a certain file in an editor. Of course it doesn't matter that much because helix is so lean and my machine so beefy, but it would still be great if I could e.g. edit git commits in helix without a new instance. |
Please shoot me down if im completly off the chart here. But i was thinking this could be done in a more simple way with a combination of a tmpfile and a signal, eg call SIGHUB or SIGUSR1. So in short if you eg pass a parameter to helix it would create a tmp file with either a shared name or a specific pid and then send a signal (SIGHUB or SIGUSR1) to either the specific pid or the first pid that matches helix. The helix that gets the signal will then load the tmpfile with the new filepaths in and open the files in new buffers. This means i would not require a server/client implementaiton of helix, and could work with a server/client instance. |
nice idea @j3ka !!! I did something similar: A zellij layout:
and broot-ide is a special command line for broot that adds config to open on helix on zellij using the following bin:
So now I have a tabs: [git manager] [helix editor and side file manager using broot] and broot opens the file on helix. One notice though: the helix editor pane on zellij must not be borderless, or screen artifacts happen! |
Following my solution.
kitty-hx-server.ts
kitty-hx-open.sh
|
@Hasnayeen If you are using WezTerm:
|
@gdamore You can solve this issue by integrating
Here's the implementation: #!/usr/bin/env sh
tty=$(tty)
hostname=$(hostname | tr '[:upper:]' '[:lower:]')
pwd=$(pwd)
file_path=$1
pane_id=$(wezterm cli list --format json | jq --arg tty "$tty" --arg opening_cwd "file://$hostname$pwd" --arg file_path "file://$hostname$file_path" -r '.[] | .cwd as $running_cwd | select((.tty_name != $tty) and (.title | startswith("hx")) and (($opening_cwd | contains($running_cwd)) or ($file_path | contains($running_cwd)))) | .pane_id')
if [ -z "$pane_id" ]; then
~/.cargo/bin/hx $1
else
if [ -n "$file_path" ]; then
echo ":open ${file_path}\r" | wezterm cli send-text --pane-id $pane_id --no-paste
else
echo ":open ${pwd}\r" | wezterm cli send-text --pane-id $pane_id --no-paste
fi
wezterm cli activate-pane --pane-id $pane_id
fi |
If you're using nushell, the following works well for me. (Tested on windows) First configure broot as a filepicker: (enter prints the path to stdout) [[verbs]]
# print path and exit broot
invocation = "print_path"
keys = ["enter"]
shortcut = "pp"
apply_to = "file"
leave_broot = true
internal = ":print_path" Then configure space-e as opening the file picker (in helix conf): [keys.normal.space]
e = """
:sh echo `echo $':open "(broot)"\r' | wezterm cli send-text --pane-id (wezterm cli get-pane-direction left); exit\r`
| wezterm cli send-text --pane-id (wezterm cli split-pane --right --percent 33) --no-paste
""" What this does is open a terminal pane to the right with broot, you pick any file/folder and on pressing enter it closes the pane and loads the file into helix. |
@quantonganh I am always getting a I do not know where the The zellij solution involving writing 27 and 13, however, seems to work. Replacing the echo pipe with passing the argument directly avoids the extra |
@chriselrod Could you please try this:
|
I've done something similar with Here is the configurations: https://github.com/vifm/vifm/tree/master/data/plugins/editor |
@chriselrod I am having the same issue with the |
No, I discovered kakoune shortly after making that comment and have been using it since. |
this script can be combined with |
Based on other people's comments on this issue, I wrote the little Rust tool "Zelix" for stitching together Helix and a file tree, using the Zellij terminal emulator: https://github.com/cfuehrmann/zelix I use it as a daily driver on small Rust projects and markdown wikis. Nonetheless, the approach of having some external process write ":open filename" or " f filename" to Helix does not scale to big file trees. Because the Helix finder, and even ":open", seem to build the list of available files asynchronously. For example, if you write " f filename" to Helix fast, it might open the wrong file because the filtered list of files has not yet stabilized. Having experienced the benefit (mostly due to improved situational awareness) of having Broot next to Helix, I'd really love it if Helix came up with a good way to open a file in an existing instance. |
Suggestion: If you add a pause (eg. sleep 0.3) before the enter key press, this gives more time for the tree to stabilise.
|
@robrecord My thoughts exactly. Just before you mentioned this, I had made myself this issue: cfuehrmann/zelix#2 |
Don't know if this has been discussed already but I couldn't find any issue about it.
I'm a heavy user of Emacs in server mode and emacsclient to open files in an already running Emacs instance (also being able to specify what line to open the file at (for example:
hx-client file.rs:55
)). I would love to see this feature in Helix.Thanks!
The text was updated successfully, but these errors were encountered: