1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-30 03:23:08 +03:00

Change direct access to Common.UserConfig to a getter

This will allow us to turn the field into an atomic.Value for safe concurrent
access.
This commit is contained in:
Stefan Haller
2024-08-01 12:20:05 +02:00
parent f114321322
commit f98b57aa5e
70 changed files with 204 additions and 193 deletions

View File

@ -80,10 +80,10 @@ func FileType(path string) string {
}
func (c *OSCommand) OpenFile(filename string) error {
commandTemplate := c.UserConfig.OS.Open
commandTemplate := c.UserConfig().OS.Open
if commandTemplate == "" {
// Legacy support
commandTemplate = c.UserConfig.OS.OpenCommand
commandTemplate = c.UserConfig().OS.OpenCommand
}
if commandTemplate == "" {
commandTemplate = config.GetPlatformDefaultConfig().Open
@ -96,10 +96,10 @@ func (c *OSCommand) OpenFile(filename string) error {
}
func (c *OSCommand) OpenLink(link string) error {
commandTemplate := c.UserConfig.OS.OpenLink
commandTemplate := c.UserConfig().OS.OpenLink
if commandTemplate == "" {
// Legacy support
commandTemplate = c.UserConfig.OS.OpenLinkCommand
commandTemplate = c.UserConfig().OS.OpenLinkCommand
}
if commandTemplate == "" {
commandTemplate = config.GetPlatformDefaultConfig().OpenLink
@ -294,8 +294,8 @@ func (c *OSCommand) CopyToClipboard(str string) error {
},
)
c.LogCommand(msg, false)
if c.UserConfig.OS.CopyToClipboardCmd != "" {
cmdStr := utils.ResolvePlaceholderString(c.UserConfig.OS.CopyToClipboardCmd, map[string]string{
if c.UserConfig().OS.CopyToClipboardCmd != "" {
cmdStr := utils.ResolvePlaceholderString(c.UserConfig().OS.CopyToClipboardCmd, map[string]string{
"text": c.Cmd.Quote(str),
})
return c.Cmd.NewShell(cmdStr).Run()
@ -307,8 +307,8 @@ func (c *OSCommand) CopyToClipboard(str string) error {
func (c *OSCommand) PasteFromClipboard() (string, error) {
var s string
var err error
if c.UserConfig.OS.CopyToClipboardCmd != "" {
cmdStr := c.UserConfig.OS.ReadFromClipboardCmd
if c.UserConfig().OS.CopyToClipboardCmd != "" {
cmdStr := c.UserConfig().OS.ReadFromClipboardCmd
s, err = c.Cmd.NewShell(cmdStr).RunWithOutput()
} else {
s, err = clipboard.ReadAll()

View File

@ -75,7 +75,7 @@ func TestOSCommandOpenFileDarwin(t *testing.T) {
for _, s := range scenarios {
oSCmd := NewDummyOSCommandWithRunner(s.runner)
oSCmd.Platform.OS = "darwin"
oSCmd.UserConfig.OS.Open = "open {{filename}}"
oSCmd.UserConfig().OS.Open = "open {{filename}}"
s.test(oSCmd.OpenFile(s.filename))
}
@ -135,7 +135,7 @@ func TestOSCommandOpenFileLinux(t *testing.T) {
for _, s := range scenarios {
oSCmd := NewDummyOSCommandWithRunner(s.runner)
oSCmd.Platform.OS = "linux"
oSCmd.UserConfig.OS.Open = `xdg-open {{filename}} > /dev/null`
oSCmd.UserConfig().OS.Open = `xdg-open {{filename}} > /dev/null`
s.test(oSCmd.OpenFile(s.filename))
}

View File

@ -71,7 +71,7 @@ func TestOSCommandOpenFileWindows(t *testing.T) {
}
oSCmd.Platform = platform
oSCmd.Cmd.platform = platform
oSCmd.UserConfig.OS.OpenCommand = `start "" {{filename}}`
oSCmd.UserConfig().OS.OpenCommand = `start "" {{filename}}`
s.test(oSCmd.OpenFile(s.filename))
}