jesseduffield / jesseduffield/lazygit
Enable templating in the `runCommand` argument
- Dominant language
- Go
- Stars
- 82.4k
- Forks
- 3k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 19
Description
### Is your feature request related to a problem? Please describe.
I want to create a custom command to push a commit, as in the [Custom Commands Compendium](https://github.com/jesseduffield/lazygit/wiki/Custom-Commands-Compendium#pushing-a-specific-commit). However, the command shall also ask for confirmation if the push has to be forced. I deem a force-push to be required if the output of the following script is empty:
```bash
git branch --no-merged
git branch --contains
```
I attempted to set a prompt condition that constructs this script with Go templates and executes it via `runCommand`:
```yaml
condition: '{{runCommand "git branch --no-merged {{.SelectedLocalCommit.Hash}} {{.SelectedLocalBranch.UpstreamRemote}}/{{.SelectedLocalBranch.UpstreamBranch}}; git branch --contains {{.SelectedLocalCommit.Hash}} {{.SelectedLocalBranch.UpstreamRemote}}/{{.SelectedLocalBranch.UpstreamBranch}}"}}'
```
However, running this custom command fails with:
### Describe the solution you'd like
I would like the script passed to `runCommand` to be subject to templating. This would allow the construction of dynamic, flexible conditions.
### Describe alternatives you've considered
Adding blocks of pre-computed scripts per custom command or per prompt:
```yaml
customCommands:
- description: Push commits
context: commits
key: P
prompts:
- title: Force push
type: confirm
values:
IsAncestor: git branch --no-merged {{.SelectedLocalCommit.Hash}} {{.SelectedLocalBranch.UpstreamRemote}}/{{.SelectedLocalBranch.UpstreamBranch}}
IsDiverged: git branch --contains {{.SelectedLocalCommit.Hash}} {{.SelectedLocalBranch.UpstreamRemote}}/{{.SelectedLocalBranch.UpstreamBranch}}"}}
condition: {{ or .IsAncestor .IsDiverged }}
```
### Additional context
None.
Contributor guide
Research direction
Locate the runCommand implementation and the custom-command condition evaluation, then reproduce the YAML example with the dynamic Git branch commands. Trace how Go templates are currently handled inside runCommand arguments. Done means the nested templates are evaluated and the resulting command can drive the force-push confirmation condition.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git, go
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100