Skip to content

feat: --execute flag which runs the passed keymap before launch #13847

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 4 commits into
base: master
Choose a base branch
from

Conversation

nik-rev
Copy link
Contributor

@nik-rev nik-rev commented Jun 27, 2025

Adds a new flag -e/--execute which gets passed a command to execute before launching helix.

Why: Currently, when passing a directory to Helix like hx .. it will open a file finder <space>f.

What if instead of that, you want to open it with a file explorer <space>e? This PR allows you to do this by using hx .. --execute "<esc><space>e" which will open the file explorer instead

It allows for more versatility as well: you'll be able to start helix with whatever sequence of commands you want

@satoqz
Copy link
Contributor

satoqz commented Jun 28, 2025

Another use case I've thought of previously was setting the language for text that's piped into helix:

some-command | hx -x ':lang bash<ret>'

Edit: Yeah, this works great:

ghostty +show-config --docs --default | hx --execute ':lang ghostty<ret>'

@Axlefublr
Copy link
Contributor

this is incredible! my long standing usecase of “open file automatically in insert mode, at the end of the last line” can finally be solved 🚀

@Axlefublr
Copy link
Contributor

yay it works :D no merge conflict no errors nothing :D
my one recommendation is to change the short flag from -x to -e
a bit bikesheddy, sure, but various programs tend to use -e as their flag for various exec/eval behavior, so it'll be a bit more natural / memorable for most users

@DerSaidin
Copy link

DerSaidin commented Jul 4, 2025

Why take a keymap rather than the commands the keys are mapped to?

e.g.

hx .. --execute "<esc><space>e"

  • maybe easier to remember
  • maybe shorter

vs

hx .. --execute "file_explorer"

  • (equivalent command under default binding)
  • don't need to do mode changes to access the command you want to use
  • robust to any hx keybind config (e.g. custom; or if defaults change)
  • more readable if used in scripts

@Axlefublr
Copy link
Contributor

syntax would need to be introduced to chain commands, in that case 🤔 surrounding in [] probably

@nik-rev
Copy link
Contributor Author

nik-rev commented Jul 4, 2025

Why take a keymap rather than the commands the keys are mapped to?

e.g.

hx .. --execute "<esc><space>e"

  • maybe easier to remember
  • maybe shorter

vs

hx .. --execute "file_explorer"

  • (equivalent command under default binding)
  • don't need to do mode changes to access the command you want to use
  • robust to any hx keybind config (e.g. custom; or if defaults change)
  • more readable if used in scripts
  • if you want to name the commands explicitly you can just use the command picker: <esc><space>?file_explorer<enter>
  • people usually don't know names of commands, so its an extra step to look them up
  • helix isn't meant to be used from scripts. you'd be better off with a programming language for that. this feature is for enhancing interactive usage
  • series of commands is much less capable than an arbitrary key sequence. this would make the feature less useful. e.g. you won't be able to open a picker with some things typed in the prompt
  • it would make the feature more complex, which means its much less likely to be merged

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.

5 participants