Skip to content

Commit 6b1d388

Browse files
committed
Replace with runCommand function
1 parent da147b3 commit 6b1d388

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

Diff for: pkg/gui/controllers/helpers/refs_helper.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ package helpers
22

33
import (
44
"fmt"
5-
"strings"
6-
"text/template"
7-
"time"
8-
95
"github.com/jesseduffield/gocui"
106
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
117
"github.com/jesseduffield/lazygit/pkg/commands/models"
@@ -14,6 +10,8 @@ import (
1410
"github.com/jesseduffield/lazygit/pkg/gui/types"
1511
"github.com/jesseduffield/lazygit/pkg/utils"
1612
"github.com/samber/lo"
13+
"strings"
14+
"text/template"
1715
)
1816

1917
type IRefsHelper interface {
@@ -334,8 +332,12 @@ func (self *RefsHelper) NewBranch(from string, fromFormattedName string, suggest
334332
var err error
335333

336334
suggestedBranchName, err = utils.ResolveTemplate(self.c.UserConfig().Git.BranchPrefix, nil, template.FuncMap{
337-
"formatCurrentDate": func(layout string) string {
338-
return time.Now().Format(layout)
335+
"runCommand": func(command string) (string, error) {
336+
output, err := self.c.Git().Custom.RunWithOutput(command)
337+
if err != nil {
338+
return "", err
339+
}
340+
return strings.TrimRight(output, "\r\n"), nil
339341
},
340342
})
341343
if err != nil {

Diff for: pkg/gui/services/custom_commands/handler_creator.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@ package custom_commands
33
import (
44
"errors"
55
"fmt"
6-
"strings"
7-
"text/template"
8-
"time"
9-
106
"github.com/jesseduffield/gocui"
117
"github.com/jesseduffield/lazygit/pkg/config"
128
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
139
"github.com/jesseduffield/lazygit/pkg/gui/style"
1410
"github.com/jesseduffield/lazygit/pkg/gui/types"
1511
"github.com/jesseduffield/lazygit/pkg/utils"
1612
"github.com/samber/lo"
13+
"strings"
14+
"text/template"
1715
)
1816

1917
// takes a custom command and returns a function that will be called when the corresponding user-defined keybinding is pressed
@@ -248,8 +246,12 @@ func (self *HandlerCreator) getResolveTemplateFn(form map[string]string, promptR
248246

249247
funcs := template.FuncMap{
250248
"quote": self.c.OS().Quote,
251-
"formatCurrentDate": func(layout string) string {
252-
return time.Now().Format(layout)
249+
"runCommand": func(command string) (string, error) {
250+
output, err := self.c.Git().Custom.RunWithOutput(command)
251+
if err != nil {
252+
return "", err
253+
}
254+
return strings.TrimRight(output, "\r\n"), nil
253255
},
254256
}
255257

0 commit comments

Comments
 (0)