1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-11-28 09:08:41 +02:00

Edit command as user OS config option

This commit is contained in:
caojoshua 2021-05-19 23:44:58 -07:00 committed by Jesse Duffield
parent cb78cf7de4
commit 60468d2e17
6 changed files with 37 additions and 1 deletions

View File

@ -318,7 +318,11 @@ func (c *GitCommand) ResetAndClean() error {
} }
func (c *GitCommand) EditFileCmdStr(filename string) (string, error) { func (c *GitCommand) EditFileCmdStr(filename string) (string, error) {
editor := c.GetConfigValue("core.editor") editor := c.Config.GetUserConfig().OS.EditCommand
if editor == "" {
editor = c.GetConfigValue("core.editor")
}
if editor == "" { if editor == "" {
editor = c.OSCommand.Getenv("GIT_EDITOR") editor = c.OSCommand.Getenv("GIT_EDITOR")

View File

@ -720,6 +720,7 @@ func TestGitCommandRemoveUntrackedFiles(t *testing.T) {
func TestEditFileCmdStr(t *testing.T) { func TestEditFileCmdStr(t *testing.T) {
type scenario struct { type scenario struct {
filename string filename string
configEditCommand string
command func(string, ...string) *exec.Cmd command func(string, ...string) *exec.Cmd
getenv func(string) string getenv func(string) string
getGitConfigValue func(string) (string, error) getGitConfigValue func(string) (string, error)
@ -729,6 +730,7 @@ func TestEditFileCmdStr(t *testing.T) {
scenarios := []scenario{ scenarios := []scenario{
{ {
"test", "test",
"",
func(name string, arg ...string) *exec.Cmd { func(name string, arg ...string) *exec.Cmd {
return secureexec.Command("exit", "1") return secureexec.Command("exit", "1")
}, },
@ -744,6 +746,25 @@ func TestEditFileCmdStr(t *testing.T) {
}, },
{ {
"test", "test",
"nano",
func(name string, args ...string) *exec.Cmd {
assert.Equal(t, "which", name)
return secureexec.Command("echo")
},
func(env string) string {
return ""
},
func(cf string) (string, error) {
return "", nil
},
func(cmdStr string, err error) {
assert.NoError(t, err)
assert.Equal(t, "nano \"test\"", cmdStr)
},
},
{
"test",
"",
func(name string, arg ...string) *exec.Cmd { func(name string, arg ...string) *exec.Cmd {
assert.Equal(t, "which", name) assert.Equal(t, "which", name)
return secureexec.Command("exit", "1") return secureexec.Command("exit", "1")
@ -761,6 +782,7 @@ func TestEditFileCmdStr(t *testing.T) {
}, },
{ {
"test", "test",
"",
func(name string, arg ...string) *exec.Cmd { func(name string, arg ...string) *exec.Cmd {
assert.Equal(t, "which", name) assert.Equal(t, "which", name)
return secureexec.Command("exit", "1") return secureexec.Command("exit", "1")
@ -781,6 +803,7 @@ func TestEditFileCmdStr(t *testing.T) {
}, },
{ {
"test", "test",
"",
func(name string, arg ...string) *exec.Cmd { func(name string, arg ...string) *exec.Cmd {
assert.Equal(t, "which", name) assert.Equal(t, "which", name)
return secureexec.Command("exit", "1") return secureexec.Command("exit", "1")
@ -802,6 +825,7 @@ func TestEditFileCmdStr(t *testing.T) {
}, },
{ {
"test", "test",
"",
func(name string, arg ...string) *exec.Cmd { func(name string, arg ...string) *exec.Cmd {
assert.Equal(t, "which", name) assert.Equal(t, "which", name)
return secureexec.Command("echo") return secureexec.Command("echo")
@ -819,6 +843,7 @@ func TestEditFileCmdStr(t *testing.T) {
}, },
{ {
"file/with space", "file/with space",
"",
func(name string, args ...string) *exec.Cmd { func(name string, args ...string) *exec.Cmd {
assert.Equal(t, "which", name) assert.Equal(t, "which", name)
return secureexec.Command("echo") return secureexec.Command("echo")
@ -838,6 +863,7 @@ func TestEditFileCmdStr(t *testing.T) {
for _, s := range scenarios { for _, s := range scenarios {
gitCmd := NewDummyGitCommand() gitCmd := NewDummyGitCommand()
gitCmd.Config.GetUserConfig().OS.EditCommand = s.configEditCommand
gitCmd.OSCommand.Command = s.command gitCmd.OSCommand.Command = s.command
gitCmd.OSCommand.Getenv = s.getenv gitCmd.OSCommand.Getenv = s.getenv
gitCmd.getGitConfigValue = s.getGitConfigValue gitCmd.getGitConfigValue = s.getGitConfigValue

View File

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

View File

@ -3,6 +3,7 @@ package config
// GetPlatformDefaultConfig gets the defaults for the platform // GetPlatformDefaultConfig gets the defaults for the platform
func GetPlatformDefaultConfig() OSConfig { func GetPlatformDefaultConfig() OSConfig {
return OSConfig{ return OSConfig{
EditCommand: ``,
OpenCommand: `sh -c "xdg-open {{filename}} >/dev/null"`, OpenCommand: `sh -c "xdg-open {{filename}} >/dev/null"`,
OpenLinkCommand: `sh -c "xdg-open {{link}} >/dev/null"`, OpenLinkCommand: `sh -c "xdg-open {{link}} >/dev/null"`,
} }

View File

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

View File

@ -248,6 +248,9 @@ type KeybindingSubmodulesConfig struct {
// OSConfig contains config on the level of the os // OSConfig contains config on the level of the os
type OSConfig struct { type OSConfig struct {
// EditCommand is the command for editing a file
EditCommand string `yaml:"editCommand,omitempty"`
// OpenCommand is the command for opening a file // OpenCommand is the command for opening a file
OpenCommand string `yaml:"openCommand,omitempty"` OpenCommand string `yaml:"openCommand,omitempty"`