1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-03 13:21:56 +02:00

Change OpenCommand to Open and OpenLinkCommand to OpenLink

We do this for consistency with the edit settings. The old names are kept as a
fallback for now.
This commit is contained in:
Stefan Haller 2023-03-28 18:00:40 +02:00
parent b7e029adc7
commit e4e16fa38e
6 changed files with 31 additions and 14 deletions

View File

@ -78,9 +78,13 @@ func FileType(path string) string {
}
func (c *OSCommand) OpenFile(filename string) error {
commandTemplate := c.UserConfig.OS.OpenCommand
commandTemplate := c.UserConfig.OS.Open
if commandTemplate == "" {
commandTemplate = config.GetPlatformDefaultConfig().OpenCommand
// Legacy support
commandTemplate = c.UserConfig.OS.OpenCommand
}
if commandTemplate == "" {
commandTemplate = config.GetPlatformDefaultConfig().Open
}
templateValues := map[string]string{
"filename": c.Quote(filename),
@ -90,9 +94,13 @@ func (c *OSCommand) OpenFile(filename string) error {
}
func (c *OSCommand) OpenLink(link string) error {
commandTemplate := c.UserConfig.OS.OpenLinkCommand
commandTemplate := c.UserConfig.OS.OpenLink
if commandTemplate == "" {
commandTemplate = config.GetPlatformDefaultConfig().OpenLinkCommand
// Legacy support
commandTemplate = c.UserConfig.OS.OpenLinkCommand
}
if commandTemplate == "" {
commandTemplate = config.GetPlatformDefaultConfig().OpenLink
}
templateValues := map[string]string{
"link": c.Quote(link),

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.OpenCommand = "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.OpenCommand = `xdg-open {{filename}} > /dev/null`
oSCmd.UserConfig.OS.Open = `xdg-open {{filename}} > /dev/null`
s.test(oSCmd.OpenFile(s.filename))
}

View File

@ -6,7 +6,7 @@ package config
// GetPlatformDefaultConfig gets the defaults for the platform
func GetPlatformDefaultConfig() OSConfig {
return OSConfig{
OpenCommand: "open -- {{filename}}",
OpenLinkCommand: "open {{link}}",
Open: "open -- {{filename}}",
OpenLink: "open {{link}}",
}
}

View File

@ -29,13 +29,13 @@ func isContainer() bool {
func GetPlatformDefaultConfig() OSConfig {
if isWSL() && !isContainer() {
return OSConfig{
OpenCommand: `powershell.exe start explorer.exe {{filename}} >/dev/null`,
OpenLinkCommand: `powershell.exe start {{link}} >/dev/null`,
Open: `powershell.exe start explorer.exe {{filename}} >/dev/null`,
OpenLink: `powershell.exe start {{link}} >/dev/null`,
}
}
return OSConfig{
OpenCommand: `xdg-open {{filename}} >/dev/null`,
OpenLinkCommand: `xdg-open {{link}} >/dev/null`,
Open: `xdg-open {{filename}} >/dev/null`,
OpenLink: `xdg-open {{link}} >/dev/null`,
}
}

View File

@ -3,7 +3,7 @@ package config
// GetPlatformDefaultConfig gets the defaults for the platform
func GetPlatformDefaultConfig() OSConfig {
return OSConfig{
OpenCommand: `start "" {{filename}}`,
OpenLinkCommand: `start "" {{link}}`,
Open: `start "" {{filename}}`,
OpenLink: `start "" {{link}}`,
}
}

View File

@ -311,6 +311,13 @@ type OSConfig struct {
// are defined in the getPreset function in editor_presets.go.
EditPreset string `yaml:"editPreset,omitempty"`
// Command for opening a file, as if the file is double-clicked. Should
// contain "{{filename}}", but doesn't support "{{line}}".
Open string `yaml:"open,omitempty"`
// Command for opening a link. Should contain "{{link}}".
OpenLink string `yaml:"openLink,omitempty"`
// --------
// The following configs are all deprecated and kept for backward
@ -327,9 +334,11 @@ type OSConfig struct {
EditCommandTemplate string `yaml:"editCommandTemplate,omitempty"`
// OpenCommand is the command for opening a file
// Deprecated: use Open instead.
OpenCommand string `yaml:"openCommand,omitempty"`
// OpenLinkCommand is the command for opening a link
// Deprecated: use OpenLink instead.
OpenLinkCommand string `yaml:"openLinkCommand,omitempty"`
}