-
Notifications
You must be signed in to change notification settings - Fork 9
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 files from yazi in a helix buffer instead of a zellij new pane #8
Comments
This is what I'm looking for |
This should be unblocked once helix's plugin system is first released (in six to 9 months), so someone could create a plugin that enables that but at the same time, we should be getting a file tree plugin, so it is not clear whether having a "yazi sidebar" would still be of value... Why would we not use helix's own file tree plugin? 🤔 |
if this is possible sooner, i shall implement it! |
zellij+helix+yazi.mp4Initially I show my config.toml to show the line that triggers the script, then the script and then I show the flow in action. Running this on a pi zero through ssh, hence why it's struggling. As seen in this github issue you can make it load in the current buffer, you can even select multiple files. I think the ideal workflow is:
That way the file-tree can be inspected easily with a keybind that you can easily close again, so you can use it both for having a view as well as selecting the files. I believe this is possible to do as of now, but I won't bother since my current workflow is good enough for me, and I rather work that continue tinkering atm :) ~/.config/helix/config.toml |
Awesome! Looks very cool. I will probably point to your solution in the readme, I bet it will help many people I might take a stab at doing this with nushell thank you for taking the time |
I give in, let's roll with a bash script |
this is the dumb version: open_file.sh #!/bin/sh
# Move focus to the next pane
zellij action focus-next-pane
zellij action write 27 # press esc
zellij action write-chars ":open $1"
zellij action write 13 # press enter yazi.toml # yazi.toml
[manager]
ratio = [0, 4, 0]
[opener]
# yazelix v4
edit = [
{ exec = '~/.config/zellij/yazi/open_file.sh $1', desc = "Open File in a new pane" },
]
# yazelix v3
# edit = [{ exec = 'zellij edit "$1"', desc = "Open File in a new pane" }] |
the limitation here is that it does not know whether helix is in the next pane or not. so if you hit enter on a file in yazi, it will try to open it anyway, it will move focus to the next pane, it will hit so hopefully it does not cause any accident |
this is the slightly less dumb version, and it can only check wheter helix is open if helix was opened from pane directly #!/bin/sh
# Move focus to the next pane
zellij action focus-next-pane
# Get the running command in the current pane
RUNNING_COMMAND=$(zellij action list-clients | awk 'NR==2 {print $3}')
# Check if the command running in the current pane is helix (hx)
if echo "$RUNNING_COMMAND" | grep -q "/hx$"; then
# The current pane is running helix, use zellij actions to open the file
zellij action write 27
zellij action write-chars ":open $1"
zellij action write 13
else
# The current pane is not running helix, open helix with the file
zellij action new-pane --name "WARNING" -- "echo" "please open helix in a pane right next to the sidebar (to the right of it) using 'hx path_to_file'"
# some other test
# zellij action new-pane --name "/hx running" -- "hx" $1
fi if it was opened from the sidebar (with
so in this case, another window would open, otherwise it would be possible opening helix either from yazi or from the terminal, which would be ideal but for now, that will do, I believe |
yazelix v4 will probably be shipping with the slightly less dumb version unless a truly smart one gets developed... 👀 |
ok, I fixed it. list-clients now works on both cases because if helix is not open, it will open helix step by step, first creating the new pane, then typing "hx $1", then sleeping for 0.3 seconds, and pressing enter this way the #!/bin/sh
# Move focus to the next pane
zellij action focus-next-pane
# Get the running command in the current pane
RUNNING_COMMAND=$(zellij action list-clients | awk 'NR==2 {print $3}')
# Check if the command running in the current pane is helix (hx)
if echo "$RUNNING_COMMAND" | grep -q "/hx$"; then
# The current pane is running helix, use zellij actions to open the file
zellij action write 27
zellij action write-chars ":open $1"
zellij action write 13
else
# The current pane is not running helix, so open helix in a new pane
zellij action new-pane
sleep 0.3
zellij action write-chars "hx $1"
zellij action write 13
# warning from before I got it working
# zellij action new-pane --name "WARNING" -- "echo" "please open helix in a pane right next to the sidebar (to the right of it) using 'hx path_to_file'"
fi this will detect the helix pane next to the sidebar, whether it was opened from the pane or from the sidebar so this is the smart version |
I should probably merge this tomorrow, possibly in a v4 branch |
solved by #16 |
No idea how to do that, but things I think of, I'll document here
The text was updated successfully, but these errors were encountered: