lazygit icon indicating copy to clipboard operation
lazygit copied to clipboard

Run custom commands in interactive shell

Open felixschndr opened this issue 1 year ago • 6 comments

Is your feature request related to a problem? Please describe. When a custom command is specified in the config it runs it with bash -c "<command>". I'd like this shell to be interactive to be able to run shell aliases which lie in my .bashrc.

Describe the solution you'd like Run bash -ic "<command">

Describe alternatives you've considered Currently I am adding a layer of bash:

  - key: <c-d>
    context: "localBranches, remoteBranches"
    command: bash -ic "git_delete_old_branches"
    stream: true

which runs bash -c bash -ic "git_delete_old_branches"

Additional context Maybe make this a config variable?

I tried to go through the source code to check where the bash -c (without -i) is invoked but was a bit overwhelmed by the search results. If someone could show me where this is done I'd take a crack at creating a PR.

felixschndr avatar Nov 07 '24 20:11 felixschndr

NewShell() in the /oscommands/cmd_obj_builder.go

I just open up another pane, do work then hop back.

aaronjconway avatar Nov 08 '24 19:11 aaronjconway

There is also NewInteractiveShell() https://github.com/jesseduffield/lazygit/blob/b0a766cc9529dadde5e5bd51bb1cc5c503213f66/pkg/commands/oscommands/cmd_obj_builder.go#L54. We could just run this function instead, right?

felixschndr avatar Nov 11 '24 11:11 felixschndr

We could just run this function instead, right?

If so I am not able to find where this function call has to be changed

felixschndr avatar Nov 11 '24 13:11 felixschndr

There are some thoughts shared in https://github.com/jesseduffield/lazygit/pull/3299#issuecomment-2265269589. Using -i for custom commands is not ideal due to performance concerns.

Since custom commands are typically one-off configurations in config.yml, it should be fine to write the original command directly. However, for shell commands that you frequently type and reuse, using -i is reasonable so that you can reach your aliases etc..

yam-liu avatar Nov 15 '24 08:11 yam-liu

The ideal thing would be to allow custom flags for the shell. In nushell for instance there is a concept of env vs config. env is lightweight and only adds some path to modules etc, enough to import those modules in custom commands: use mymod.nu;mymod mycommand

Currently -c being hardcoded makes that impossible

melMass avatar Jun 07 '25 19:06 melMass

Also the parsing is inconsistent between macos and windows.

On macos this works fine:

command: "nu --env-config $nu.env-path -c 'use ensure.nu;ensure scope {{.Form.Type}}'"

But on windows it adds extra quotes around $nu.env-path:

Image

I tried various things, single quotes, escaping etc to no avail.

melMass avatar Jun 08 '25 13:06 melMass