1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-23 12:18:51 +02:00

Fix open link command in Windows

This commit is contained in:
Ryooooooga 2021-10-09 16:32:36 +09:00 committed by Jesse Duffield
parent a2108362de
commit 7b615e3186
4 changed files with 11 additions and 17 deletions

View File

@ -211,14 +211,14 @@ keybinding:
```yaml ```yaml
os: os:
openCommand: 'cmd /c "start "" {{filename}}"' openCommand: 'start "" {{filename}}'
``` ```
### Linux ### Linux
```yaml ```yaml
os: os:
openCommand: 'sh -c "xdg-open {{filename}} >/dev/null"' openCommand: 'xdg-open {{filename}} >/dev/null'
``` ```
### OSX ### OSX

View File

@ -202,7 +202,7 @@ func (c *OSCommand) ShellCommandFromString(commandStr string) *exec.Cmd {
quotedCommand := "" quotedCommand := ""
// Windows does not seem to like quotes around the command // Windows does not seem to like quotes around the command
if c.Platform.OS == "windows" { if c.Platform.OS == "windows" {
quotedCommand = commandStr quotedCommand = strings.Replace(commandStr, "&", "^&", -1)
} else { } else {
quotedCommand = c.Quote(commandStr) quotedCommand = c.Quote(commandStr)
} }
@ -252,7 +252,7 @@ func (c *OSCommand) RunCommand(formatString string, formatArgs ...interface{}) e
// RunShellCommand runs shell commands i.e. 'sh -c <command>'. Good for when you // RunShellCommand runs shell commands i.e. 'sh -c <command>'. Good for when you
// need access to the shell // need access to the shell
func (c *OSCommand) RunShellCommand(command string) error { func (c *OSCommand) RunShellCommand(command string) error {
cmd := c.Command(c.Platform.Shell, c.Platform.ShellArg, command) cmd := c.ShellCommandFromString(command)
c.LogExecCmd(cmd) c.LogExecCmd(cmd)
_, err := sanitisedCommandOutput(cmd.CombinedOutput()) _, err := sanitisedCommandOutput(cmd.CombinedOutput())
@ -288,17 +288,11 @@ func sanitisedCommandOutput(output []byte, err error) (string, error) {
// OpenFile opens a file with the given // OpenFile opens a file with the given
func (c *OSCommand) OpenFile(filename string) error { func (c *OSCommand) OpenFile(filename string) error {
commandTemplate := c.Config.GetUserConfig().OS.OpenCommand commandTemplate := c.Config.GetUserConfig().OS.OpenCommand
quoted := c.Quote(filename)
if c.Platform.OS == "linux" {
// Add extra quoting to avoid issues with shell command string
quoted = c.Quote(quoted)
quoted = quoted[1 : len(quoted)-1]
}
templateValues := map[string]string{ templateValues := map[string]string{
"filename": quoted, "filename": c.Quote(filename),
} }
command := utils.ResolvePlaceholderString(commandTemplate, templateValues) command := utils.ResolvePlaceholderString(commandTemplate, templateValues)
err := c.RunCommand(command) err := c.RunShellCommand(command)
return err return err
} }
@ -311,7 +305,7 @@ func (c *OSCommand) OpenLink(link string) error {
} }
command := utils.ResolvePlaceholderString(commandTemplate, templateValues) command := utils.ResolvePlaceholderString(commandTemplate, templateValues)
err := c.RunCommand(command) err := c.RunShellCommand(command)
return err return err
} }

View File

@ -5,7 +5,7 @@ func GetPlatformDefaultConfig() OSConfig {
return OSConfig{ return OSConfig{
EditCommand: ``, EditCommand: ``,
EditCommandTemplate: `{{editor}} {{filename}}`, EditCommandTemplate: `{{editor}} {{filename}}`,
OpenCommand: `sh -c "xdg-open {{filename}} >/dev/null"`, OpenCommand: `xdg-open {{filename}} >/dev/null`,
OpenLinkCommand: `sh -c "xdg-open {{link}} >/dev/null"`, OpenLinkCommand: `xdg-open {{link}} >/dev/null`,
} }
} }

View File

@ -5,7 +5,7 @@ func GetPlatformDefaultConfig() OSConfig {
return OSConfig{ return OSConfig{
EditCommand: ``, EditCommand: ``,
EditCommandTemplate: `{{editor}} {{filename}}`, EditCommandTemplate: `{{editor}} {{filename}}`,
OpenCommand: `cmd /c start "" {{filename}}`, OpenCommand: `start "" {{filename}}`,
OpenLinkCommand: `cmd /c start "" {{link}}`, OpenLinkCommand: `start "" {{link}}`,
} }
} }