Custom command and custom command
Topic
- Rename the 'Custom command' thing associated with
:to Execute Shell Command or Shell command. - Bring Custom command placeholders like `{{ .SelectedPath }} to Shell command.
Your thoughts
-
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.
-
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 }}
-
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.
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.
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
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 /.
@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
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.
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!
@yam-liu This was auto-closed because I mentioned it in #4324. I'm curious if this addresses your needs.