lazygit icon indicating copy to clipboard operation
lazygit copied to clipboard

Custom command and custom command

Open yam-liu opened this issue 1 year ago • 6 comments

Topic

  1. Rename the 'Custom command' thing associated with : to Execute Shell Command or Shell command.
  2. Bring Custom command placeholders like `{{ .SelectedPath }} to Shell command.

Your thoughts

  1. We have two features named Custom command. It's hard to refer clearly to which one when we use the 'custom command' keyword. Like this context. I propose to use:

    • Custom command: for custom command defined in config.yml.
    • Shell command: execute the shell command that user inputs.
  2. Another thought, we cannot use placeholders in Shell command. But it is convenient to provide this feature.

    • Use case 1: To execute a git command over the current selected file, what I want is:

      git --update-index --skip-worktree {{ .SelectedPath }}
      

      The file is modified and selected in Files tab, I hope I can pass the selected file path to execute arbitrary commands.

    • Use case 2: To change file attribute, add execute permission. Example command:

      chmod +x {{ .SelectedPath }}
      

yam-liu avatar Aug 06 '24 07:08 yam-liu

I very much like the first suggestion; the double use of the term "Custom Command" has often bothered me. Here's a PR: #3800.

I'm not so sure about the value of the second suggestion, but I wouldn't be opposed; seems like it shouldn't be too hard to implement it.

stefanhaller avatar Aug 06 '24 08:08 stefanhaller

The first issue is fixed by #3800.

For the second, I have the feeling that what you really want is something else. The : command prompt is for typing ad-hoc commands, and you wouldn't want to type something like {{ .SelectedPath }} at that prompt, this is too cumbersome. It would be faster to select the file, hit y p to copy its path, and then type : chmod +x <Command-V>.

So it seems that you want to "abuse" the : command prompt for something more permanent; you want to use the : history for preconfiguring a command for later re-use. Normally you could just configure a custom command for these, but probably you don't want to sacrifice a keybinding for them, or you may have a hard time remembering the keybindings for those commands that you don't use daily.

I feel it might be worth adding a configuration that allows configuring a key binding for a list of custom commands instead of just one. Pressing the key would bring up a menu that lists all the configured commands for that key, with filtering, very similar to the : dialog.

This would be very similar to what you are suggesting, but it would clearly separate those pre-configured commands from the commands that you really type ad-hoc.

But it may well be easier to do what you suggested; just wanted to bring up this thought for discussion.

stefanhaller avatar Aug 17 '24 09:08 stefanhaller

FWIW - I think the ability to search for custom commands by name without needing to bind them to a key would be a great enhancement.

I think it would be nice if there was a single command search functionality that suggested results from various sources (built-in, custom command, unbound custom command, recent ad-hoc, etc). But, I'd take the functionality however it comes. If this is something that could be a good fit for a PR from the community, I could take a stab at it

a-jentleman avatar Aug 20 '24 04:08 a-jentleman

FWIW - I think the ability to search for custom commands by name without needing to bind them to a key would be a great enhancement.

@a-jentleman that's already possible, you can search in the help (?) menu with /.

image

mark2185 avatar Aug 20 '24 04:08 mark2185

@a-jentleman that's already possible, you can search in the help (?) menu with /.

Oh, sweet. Wish I tried this earlier.

Is this a known & supported setup? If so, perhaps my contribution would be small doc changes to Custom_Command_Keybindings.md and/or Custom-Commands-Compendium to demonstrate it

a-jentleman avatar Aug 20 '24 05:08 a-jentleman

If so, perhaps my contribution would be small doc changes to Custom_Command_Keybindings.md and/or Custom-Commands-Compendium to demonstrate it

Huh, it looks like the docs state key as required which it obviously isn't, so I guess that needs changing, yeah.

mark2185 avatar Aug 20 '24 05:08 mark2185

I feel it might be worth adding a configuration that allows configuring a key binding for a list of custom commands instead of just one. Pressing the key would bring up a menu that lists all the configured commands for that key, with filtering, very similar to the : dialog.

I finally got around to making a PR for this, because I want it myself: #4276. @yam-liu Please test!

stefanhaller avatar Feb 16 '25 17:02 stefanhaller

@yam-liu This was auto-closed because I mentioned it in #4324. I'm curious if this addresses your needs.

stefanhaller avatar Feb 28 '25 09:02 stefanhaller