summaryrefslogtreecommitdiffstats
path: root/pkg/commands
diff options
context:
space:
mode:
authorLuka Markušić <luka.markusic@microblink.com>2022-02-15 19:34:36 +0100
committerJesse Duffield <jessedduffield@gmail.com>2022-03-16 19:55:58 +1100
commit866f4b9f0efa13dfb4b3ab995ab5595a3ed29e2f (patch)
tree0252401594cafbb091ac544d12c4fbf31d3639b4 /pkg/commands
parentf56988039af1ffd44d9ce82ee7e885d012974e46 (diff)
Support line offset for most common editors by default
Diffstat (limited to 'pkg/commands')
-rw-r--r--pkg/commands/git_commands/file.go10
-rw-r--r--pkg/commands/git_commands/file_test.go11
2 files changed, 16 insertions, 5 deletions
diff --git a/pkg/commands/git_commands/file.go b/pkg/commands/git_commands/file.go
index 026d79cb0..353a8dcdc 100644
--- a/pkg/commands/git_commands/file.go
+++ b/pkg/commands/git_commands/file.go
@@ -58,5 +58,15 @@ func (self *FileCommands) GetEditCmdStr(filename string, lineNumber int) (string
}
editCmdTemplate := self.UserConfig.OS.EditCommandTemplate
+ if editCmdTemplate == "{{editor}} {{filename}}" {
+ switch editor {
+ case "emacs", "nano", "vi", "vim":
+ editCmdTemplate = "{{editor}} +{{line}} {{filename}}"
+ case "subl":
+ editCmdTemplate = "{{editor}} {{filename}}:{{line}}"
+ case "code":
+ editCmdTemplate = "{{editor}} --goto {{filename}}:{{line}}"
+ }
+ }
return utils.ResolvePlaceholderString(editCmdTemplate, templateValues), nil
}
diff --git a/pkg/commands/git_commands/file_test.go b/pkg/commands/git_commands/file_test.go
index a26699b3e..61482054b 100644
--- a/pkg/commands/git_commands/file_test.go
+++ b/pkg/commands/git_commands/file_test.go
@@ -47,7 +47,7 @@ func TestEditFileCmdStr(t *testing.T) {
gitConfigMockResponses: nil,
test: func(cmdStr string, err error) {
assert.NoError(t, err)
- assert.Equal(t, `nano "test"`, cmdStr)
+ assert.Equal(t, `nano +1 "test"`, cmdStr)
},
},
{
@@ -61,7 +61,7 @@ func TestEditFileCmdStr(t *testing.T) {
gitConfigMockResponses: map[string]string{"core.editor": "nano"},
test: func(cmdStr string, err error) {
assert.NoError(t, err)
- assert.Equal(t, `nano "test"`, cmdStr)
+ assert.Equal(t, `nano +1 "test"`, cmdStr)
},
},
{
@@ -79,6 +79,7 @@ func TestEditFileCmdStr(t *testing.T) {
gitConfigMockResponses: nil,
test: func(cmdStr string, err error) {
assert.NoError(t, err)
+ assert.Equal(t, `nano +1 "test"`, cmdStr)
},
},
{
@@ -96,7 +97,7 @@ func TestEditFileCmdStr(t *testing.T) {
gitConfigMockResponses: nil,
test: func(cmdStr string, err error) {
assert.NoError(t, err)
- assert.Equal(t, `emacs "test"`, cmdStr)
+ assert.Equal(t, `emacs +1 "test"`, cmdStr)
},
},
{
@@ -111,7 +112,7 @@ func TestEditFileCmdStr(t *testing.T) {
gitConfigMockResponses: nil,
test: func(cmdStr string, err error) {
assert.NoError(t, err)
- assert.Equal(t, `vi "test"`, cmdStr)
+ assert.Equal(t, `vi +1 "test"`, cmdStr)
},
},
{
@@ -126,7 +127,7 @@ func TestEditFileCmdStr(t *testing.T) {
gitConfigMockResponses: nil,
test: func(cmdStr string, err error) {
assert.NoError(t, err)
- assert.Equal(t, `vi "file/with space"`, cmdStr)
+ assert.Equal(t, `vi +1 "file/with space"`, cmdStr)
},
},
{