mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-19 12:12:42 +02:00
Merge pull request #1891 from Ryooooooga/feature/improve-default-edit-command-template
This commit is contained in:
commit
babb9d8656
@ -83,7 +83,7 @@ git:
|
|||||||
diffContextSize: 3 # how many lines of context are shown around a change in diffs
|
diffContextSize: 3 # how many lines of context are shown around a change in diffs
|
||||||
os:
|
os:
|
||||||
editCommand: '' # see 'Configuring File Editing' section
|
editCommand: '' # see 'Configuring File Editing' section
|
||||||
editCommandTemplate: '{{editor}} {{filename}}'
|
editCommandTemplate: ''
|
||||||
openCommand: ''
|
openCommand: ''
|
||||||
refresher:
|
refresher:
|
||||||
refreshInterval: 10 # File/submodule refresh interval in seconds. Auto-refresh can be disabled via option 'git.autoRefresh'.
|
refreshInterval: 10 # File/submodule refresh interval in seconds. Auto-refresh can be disabled via option 'git.autoRefresh'.
|
||||||
@ -273,7 +273,7 @@ You can specify a line number you are currently at when in the line-by-line mode
|
|||||||
```yaml
|
```yaml
|
||||||
os:
|
os:
|
||||||
editCommand: 'vim'
|
editCommand: 'vim'
|
||||||
editCommandTemplate: '{{editor}} +{{line}} {{filename}}'
|
editCommandTemplate: '{{editor}} +{{line}} -- {{filename}}'
|
||||||
```
|
```
|
||||||
|
|
||||||
or
|
or
|
||||||
@ -281,7 +281,7 @@ or
|
|||||||
```yaml
|
```yaml
|
||||||
os:
|
os:
|
||||||
editCommand: 'code'
|
editCommand: 'code'
|
||||||
editCommandTemplate: '{{editor}} --goto {{filename}}:{{line}}'
|
editCommandTemplate: '{{editor}} --goto -- {{filename}}:{{line}}'
|
||||||
```
|
```
|
||||||
|
|
||||||
`{{editor}}` in `editCommandTemplate` is replaced with the value of `editCommand`.
|
`{{editor}}` in `editCommandTemplate` is replaced with the value of `editCommand`.
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
"github.com/jesseduffield/lazygit/pkg/config"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -59,14 +58,16 @@ func (self *FileCommands) GetEditCmdStr(filename string, lineNumber int) (string
|
|||||||
}
|
}
|
||||||
|
|
||||||
editCmdTemplate := self.UserConfig.OS.EditCommandTemplate
|
editCmdTemplate := self.UserConfig.OS.EditCommandTemplate
|
||||||
if editCmdTemplate == config.DefaultEditCommandTemplate {
|
if len(editCmdTemplate) == 0 {
|
||||||
switch editor {
|
switch editor {
|
||||||
case "emacs", "nano", "vi", "vim":
|
case "emacs", "nano", "vi", "vim", "nvim":
|
||||||
editCmdTemplate = "{{editor}} +{{line}} {{filename}}"
|
editCmdTemplate = "{{editor}} +{{line}} -- {{filename}}"
|
||||||
case "subl":
|
case "subl":
|
||||||
editCmdTemplate = "{{editor}} {{filename}}:{{line}}"
|
editCmdTemplate = "{{editor}} -- {{filename}}:{{line}}"
|
||||||
case "code":
|
case "code":
|
||||||
editCmdTemplate = "{{editor}} -r --goto {{filename}}:{{line}}"
|
editCmdTemplate = "{{editor}} -r --goto -- {{filename}}:{{line}}"
|
||||||
|
default:
|
||||||
|
editCmdTemplate = "{{editor}} -- {{filename}}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return utils.ResolvePlaceholderString(editCmdTemplate, templateValues), nil
|
return utils.ResolvePlaceholderString(editCmdTemplate, templateValues), nil
|
||||||
|
@ -47,7 +47,7 @@ func TestEditFileCmdStr(t *testing.T) {
|
|||||||
gitConfigMockResponses: nil,
|
gitConfigMockResponses: nil,
|
||||||
test: func(cmdStr string, err error) {
|
test: func(cmdStr string, err error) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, `nano +1 "test"`, cmdStr)
|
assert.Equal(t, `nano "test"`, cmdStr)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -61,7 +61,7 @@ func TestEditFileCmdStr(t *testing.T) {
|
|||||||
gitConfigMockResponses: map[string]string{"core.editor": "nano"},
|
gitConfigMockResponses: map[string]string{"core.editor": "nano"},
|
||||||
test: func(cmdStr string, err error) {
|
test: func(cmdStr string, err error) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, `nano +1 "test"`, cmdStr)
|
assert.Equal(t, `nano "test"`, cmdStr)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -79,7 +79,7 @@ func TestEditFileCmdStr(t *testing.T) {
|
|||||||
gitConfigMockResponses: nil,
|
gitConfigMockResponses: nil,
|
||||||
test: func(cmdStr string, err error) {
|
test: func(cmdStr string, err error) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, `nano +1 "test"`, cmdStr)
|
assert.Equal(t, `nano "test"`, cmdStr)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -97,7 +97,7 @@ func TestEditFileCmdStr(t *testing.T) {
|
|||||||
gitConfigMockResponses: nil,
|
gitConfigMockResponses: nil,
|
||||||
test: func(cmdStr string, err error) {
|
test: func(cmdStr string, err error) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, `emacs +1 "test"`, cmdStr)
|
assert.Equal(t, `emacs "test"`, cmdStr)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -112,7 +112,7 @@ func TestEditFileCmdStr(t *testing.T) {
|
|||||||
gitConfigMockResponses: nil,
|
gitConfigMockResponses: nil,
|
||||||
test: func(cmdStr string, err error) {
|
test: func(cmdStr string, err error) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, `vi +1 "test"`, cmdStr)
|
assert.Equal(t, `vi "test"`, cmdStr)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -127,7 +127,7 @@ func TestEditFileCmdStr(t *testing.T) {
|
|||||||
gitConfigMockResponses: nil,
|
gitConfigMockResponses: nil,
|
||||||
test: func(cmdStr string, err error) {
|
test: func(cmdStr string, err error) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, `vi +1 "file/with space"`, cmdStr)
|
assert.Equal(t, `vi "file/with space"`, cmdStr)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -144,6 +144,20 @@ func TestEditFileCmdStr(t *testing.T) {
|
|||||||
assert.Equal(t, `vim +1 "open file/at line"`, cmdStr)
|
assert.Equal(t, `vim +1 "open file/at line"`, cmdStr)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
filename: "default edit command template",
|
||||||
|
configEditCommand: "vim",
|
||||||
|
configEditCommandTemplate: "",
|
||||||
|
runner: oscommands.NewFakeRunner(t),
|
||||||
|
getenv: func(env string) string {
|
||||||
|
return ""
|
||||||
|
},
|
||||||
|
gitConfigMockResponses: nil,
|
||||||
|
test: func(cmdStr string, err error) {
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, `vim +1 -- "default edit command template"`, cmdStr)
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
|
@ -3,14 +3,12 @@
|
|||||||
|
|
||||||
package config
|
package config
|
||||||
|
|
||||||
const DefaultEditCommandTemplate = `{{editor}} {{filename}}`
|
|
||||||
|
|
||||||
// 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: ``,
|
EditCommand: ``,
|
||||||
EditCommandTemplate: DefaultEditCommandTemplate,
|
EditCommandTemplate: "",
|
||||||
OpenCommand: "open {{filename}}",
|
OpenCommand: "open -- {{filename}}",
|
||||||
OpenLinkCommand: "open {{link}}",
|
OpenLinkCommand: "open {{link}}",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
const DefaultEditCommandTemplate = `{{editor}} {{filename}}`
|
|
||||||
|
|
||||||
// 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: ``,
|
EditCommand: ``,
|
||||||
EditCommandTemplate: DefaultEditCommandTemplate,
|
EditCommandTemplate: "",
|
||||||
OpenCommand: `xdg-open {{filename}} >/dev/null`,
|
OpenCommand: `xdg-open {{filename}} >/dev/null`,
|
||||||
OpenLinkCommand: `xdg-open {{link}} >/dev/null`,
|
OpenLinkCommand: `xdg-open {{link}} >/dev/null`,
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
const DefaultEditCommandTemplate = `{{editor}} {{filename}}`
|
|
||||||
|
|
||||||
// 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: ``,
|
EditCommand: ``,
|
||||||
EditCommandTemplate: DefaultEditCommandTemplate,
|
EditCommandTemplate: "",
|
||||||
OpenCommand: `start "" {{filename}}`,
|
OpenCommand: `start "" {{filename}}`,
|
||||||
OpenLinkCommand: `start "" {{link}}`,
|
OpenLinkCommand: `start "" {{link}}`,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user