Skip to content
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

Improve File tree picker in Helix with Zellij #144

Closed
TheAwiteb opened this issue Oct 4, 2024 · 4 comments · Fixed by #146
Closed

Improve File tree picker in Helix with Zellij #144

TheAwiteb opened this issue Oct 4, 2024 · 4 comments · Fixed by #146

Comments

@TheAwiteb
Copy link
Contributor

TheAwiteb commented Oct 4, 2024

Hi, I would like to improve https://yazi-rs.github.io/docs/tips/#helix-with-zellij, what do you think?

The current method is as follows:

~/.config/helix/config.toml
[keys.normal]
C-y = ":sh zellij run -f -x 10% -y 10% --width 80% --height 80% -- bash ~/.config/helix/yazi-picker.sh"
~/.config/helix/yazi-picker.sh
#!/usr/bin/env bash

paths=$(yazi --chooser-file=/dev/stdout | while read -r; do printf "%q " "$REPLY"; done)

if [[ -n "$paths" ]]; then
	zellij action toggle-floating-panes
	zellij action write 27 # send <Escape> key
	zellij action write-chars ":open $paths"
	zellij action write 13 # send <Enter> key
	zellij action toggle-floating-panes
fi

zellij action close-pane

Is good, but the problem is if you have already opened floating pane, after opening the file you will stay on the floating pane. Also forcing the user to open the file in the window they is working in is not good, so we must make it flexible.


Video shows the issue

tip_issue.mp4

As you can see, The first time I used Yazi it was without a floating window already open, then I opened one and typed in it echo hi and moved to Helix, then I opened Yazi and as you can see after opening the file in Helix I was in the floating window.

My solution is

~/.config/helix/config.toml
-[keys.normal]
-C-y = ":sh zellij run -f -x 10% -y 10% --width 80% --height 80% -- bash ~/.config/helix/yazi-picker.sh"
+[keys.normal."A-y"]
+"c" = ":sh zellij run -c -f -x 10% -y 10% --width 80% --height 80% -- bash ~/.config/helix/yazi-picker.sh open"
+"v" = ":sh zellij run -c -f -x 10% -y 10% --width 80% --height 80% -- bash ~/.config/helix/yazi-picker.sh vsplit"
+"h" = ":sh zellij run -c -f -x 10% -y 10% --width 80% --height 80% -- bash ~/.config/helix/yazi-picker.sh hsplit"

Adding -c flag, which is will close the command pane after execute the command (open the file in Helix)

~/.config/helix/yazi-picker.sh
#!/usr/bin/env bash

+command=$1
paths=$(yazi --chooser-file=/dev/stdout | while read -r; do printf "%q " "$REPLY"; done)

if [[ -n "$paths" ]]; then
	zellij action toggle-floating-panes
	zellij action write 27 # send <Escape> key
-	zellij action write-chars ":open $paths"
+       zellij action write-chars ":$command $paths"
	zellij action write 13 # send <Enter> key
-	zellij action toggle-floating-panes
+else
+	zellij action toggle-floating-panes
fi

-zellij action close-pane

After fixing the issue, it will looks like this Awesome!!

fix_tip_issue.mp4
@sxyazi
Copy link
Member

sxyazi commented Oct 6, 2024

This looks great, thanks for sharing it!

Would you like to raise a PR? (Click the bottom link on docs to edit)

@TheAwiteb
Copy link
Contributor Author

Would you like to raise a PR?

Yes of course, I thought it's better to discuss it before creating it.

@TheAwiteb
Copy link
Contributor Author

TheAwiteb commented Oct 6, 2024

@sxyazi, as you can see in the second video, there is a custom description for the new key bindings, helix doesn't support this but I have patched it, what do you think about sharing my patch?

I think it's good, but I don't know if it's ok to share it here.

Girl in a jacket

Copy link
Contributor

I'm going to lock this issue because it has been closed for 30 days. ⏳ This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants