From e4e16fa38ea5d89fb139c5153338e32d1eeafede Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Tue, 28 Mar 2023 18:00:40 +0200 Subject: [PATCH] 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. --- pkg/commands/oscommands/os.go | 16 ++++++++++++---- pkg/commands/oscommands/os_default_test.go | 4 ++-- pkg/config/config_default_platform.go | 4 ++-- pkg/config/config_linux.go | 8 ++++---- pkg/config/config_windows.go | 4 ++-- pkg/config/user_config.go | 9 +++++++++ 6 files changed, 31 insertions(+), 14 deletions(-) diff --git a/pkg/commands/oscommands/os.go b/pkg/commands/oscommands/os.go index f66f25b72..c8f38843b 100644 --- a/pkg/commands/oscommands/os.go +++ b/pkg/commands/oscommands/os.go @@ -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), diff --git a/pkg/commands/oscommands/os_default_test.go b/pkg/commands/oscommands/os_default_test.go index 39a1226d2..1f534f6d3 100644 --- a/pkg/commands/oscommands/os_default_test.go +++ b/pkg/commands/oscommands/os_default_test.go @@ -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)) } diff --git a/pkg/config/config_default_platform.go b/pkg/config/config_default_platform.go index 1a66f9d9e..d05201454 100644 --- a/pkg/config/config_default_platform.go +++ b/pkg/config/config_default_platform.go @@ -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}}", } } diff --git a/pkg/config/config_linux.go b/pkg/config/config_linux.go index 3ed29ca6e..7f6187ee3 100644 --- a/pkg/config/config_linux.go +++ b/pkg/config/config_linux.go @@ -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`, } } diff --git a/pkg/config/config_windows.go b/pkg/config/config_windows.go index 21663c163..96a810b50 100644 --- a/pkg/config/config_windows.go +++ b/pkg/config/config_windows.go @@ -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}}`, } } diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index 0c227899e..fb0638e43 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -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"` }