Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

CLI option to run arbitrary command #10020

Closed
kanashimia opened this issue Mar 27, 2024 · 0 comments
Closed

CLI option to run arbitrary command #10020

kanashimia opened this issue Mar 27, 2024 · 0 comments
Labels
C-enhancement Category: Improvements

Comments

@kanashimia
Copy link

#8521 added +N number handling to helix, but in vim +N actually executes command N.
Helix already handles :N so it would be possible to generalise the behaviour.

Possible flag names are: --cmd -C -x -e --run --exec
Possible description:

    -C, --cmd <command>            Specifies a command to run at startup, can be passed multiple times

This flag will be useful for scripting. Another one could be added later to source commands from

There are two ways it could work:

  1. It could either allow only named commands, as in helix-term/src/commands.rs static_commands!
  2. It could could work like a key sequence input.

Exiting immediately using these two approaches:

  1. hx --cmd quit
  2. hx --cmd ':quit<ret>'

It is also possible to keep + for the first approach and and add --cmd for the second one.


I tried to implement the second approach like this:

for command in args.commands {
    for key_event in helix_view::input::parse_macro(&command).unwrap() {
        app.compositor.handle_event(
            &Event::Key(key_event),
            &mut cx
        );
    }
}

That code is in Application::new just after let app =, but it seems to break on :quit<ret>

› cargo run -- -C ':quit<ret>'  
thread 'main' panicked at helix-view/src/tree.rs:278:29:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I believe it requires view or something to be already created, couldn't figure out how to do that without adding a new event type, as that seemed too complicated for no reason, so for now will just keep this issue here.
I also didn't find an API to implement the first approach.

@kanashimia kanashimia added the C-enhancement Category: Improvements label Mar 27, 2024
@helix-editor helix-editor locked and limited conversation to collaborators Mar 27, 2024
@the-mikedavis the-mikedavis converted this issue into discussion #10021 Mar 27, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
C-enhancement Category: Improvements
Projects
None yet
Development

No branches or pull requests

1 participant