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

Enhancement: make a running helix instance open a file by path #6054

Closed
lukepighetti opened this issue Feb 19, 2023 · 5 comments
Closed

Enhancement: make a running helix instance open a file by path #6054

lukepighetti opened this issue Feb 19, 2023 · 5 comments
Labels
R-duplicate Duplicated issue: please refer to the linked issue

Comments

@lukepighetti
Copy link

Right now there is no file tree (#200) within helix, but there are plenty of file tree programs like nnn, lf, ranger, etc. There are also terminal composers/multiplexers like zellij that have the opportunity to launch hx, then on keybinding show an instance of nnn, take the picked result, and pass the path to the contained instance of hx to have it open that file

However, as it stands, I don't believe there is a way to ask an existing instance of hx to open a file by path

Originally posted in this comment: #200 (comment)

@lukepighetti lukepighetti changed the title Enhacement: make a running helix instance open a file by path Enhancement: make a running helix instance open a file by path Feb 19, 2023
@thomasgoulet
Copy link

To add to this, it would be nice if the option / flag would let you specify to open a new instance of helix if no instance is found and to open the file inside an existing instance if one is found.

One design issue that'd need to be figured out is that sometimes there might be multiple instances of helix.

@the-mikedavis
Copy link
Member

Duplicate of #2177

@the-mikedavis the-mikedavis marked this as a duplicate of #2177 Feb 19, 2023
@the-mikedavis the-mikedavis closed this as not planned Won't fix, can't repro, duplicate, stale Feb 19, 2023
@the-mikedavis the-mikedavis added the R-duplicate Duplicated issue: please refer to the linked issue label Feb 19, 2023
@goyalyashpal
Copy link
Contributor

hey both, please thumbs up that issue and share your input over there 😃

@quantonganh
Copy link
Contributor

However, as it stands, I don't believe there is a way to ask an existing instance of hx to open a file by path

I know that you may already be using the file explorer from #5768 but I still want to share how I integrated hx with WezTerm to solve this.

First, create a nnn-hx.sh script and add it to your $PATH:

#!/usr/bin/env sh

fpath="$1"

pane_id=$(wezterm cli get-pane-direction right)
if [ -z "${pane_id}" ]; then
  pane_id=$(wezterm cli split-pane --right --percent 80)
fi

program=$(wezterm cli list | awk -v pane_id="$pane_id" '$3==pane_id { print $6 }')
if [ "$program" = "hx" ]; then
  echo ":open ${fpath}\r" | wezterm cli send-text --pane-id $pane_id --no-paste
else
  echo "hx ${fpath}" | wezterm cli send-text --pane-id $pane_id --no-paste
fi

wezterm cli activate-pane-direction --pane-id $pane_id right

Next, call it as a custom opener:

$ export NNN_OPENER=nnn-hx.sh
$ nnn -c

This integration allows you to use nnn-hx.sh script as a custom opener in WezTerm to handle file paths and open them accordingly in the desired pane.

@gajdusek
Copy link
Contributor

gajdusek commented Oct 4, 2023

This is a python script I use for autokey that opens a file selected in ranger, assuming the helix lives in the last accessed tmux window.

keyboard.send_key("y")
time.sleep(0.1)
keyboard.send_key("p")
time.sleep(0.1)
keyboard.send_keys("<ctrl>+b")
keyboard.send_keys("l")

keyboard.send_keys("<escape>")
time.sleep(0.1)
keyboard.send_keys(":open <ctrl>+r*")
keyboard.press_key("<code36>")
keyboard.release_key("<code36>")

Note: Those small delays are required for me to prevent previous keypres being eaten.
keyboard.press_key("<enter>") does not work in my terminal so I worked-around this by pressing and releasing enter's key code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R-duplicate Duplicated issue: please refer to the linked issue
Projects
None yet
Development

No branches or pull requests

6 participants