Add runCommand function to Go template syntax

This makes it possible to use date and time in initial values like this:

```yaml
initialValue: 'ruudk/{{ runCommand "date +\"%Y/%-m\"" }}/'
```

I want to use this to configure my BranchPrefix like this:

```yaml
git:
  branchPrefix: 'ruudk/{{ runCommand "date +\"%Y/%-m\"" }}/'
```
This commit is contained in:
Ruud Kamphuis 2025-03-31 15:21:44 +02:00 committed by Stefan Haller
parent c7feba9bb1
commit 12820481e6
8 changed files with 140 additions and 3 deletions

View file

@ -1027,6 +1027,15 @@ git:
branchPrefix: "firstlast/"
```
It's possible to use a dynamic prefix by using the `runCommand` function:
```yaml
git:
branchPrefix: "firstlast/{{ runCommand "date +\"%Y/%-m\"" }}/"
```
This would produce something like: `firstlast/2025/4/`
## Custom git log command
You can override the `git log` command that's used to render the log of the selected branch like so:

View file

@ -320,6 +320,24 @@ We don't support accessing all elements of a range selection yet. We might add t
command: "git format-patch {{.SelectedCommitRange.From}}^..{{.SelectedCommitRange.To}}"
```
We support the following functions:
### Quoting
Quote wraps a string in quotes with necessary escaping for the current platform.
```
git {{.SelectedFile.Name | quote}}
```
### Running a command
Runs a command and returns the output. If the command outputs more than a single line, it will produce an error.
```
initialValue: "username/{{ runCommand "date +\"%Y/%-m\"" }}/"
```
## Keybinding collisions
If your custom keybinding collides with an inbuilt keybinding that is defined for the same context, only the custom keybinding will be executed. This also applies to the global context. However, one caveat is that if you have a custom keybinding defined on the global context for some key, and there is an in-built keybinding defined for the same key and for a specific context (say the 'files' context), then the in-built keybinding will take precedence. See how to change in-built keybindings [here](https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#keybindings)