From 4f66093335e5a0d370cf43b3fc637c0795376334 Mon Sep 17 00:00:00 2001 From: Ryooooooga Date: Tue, 3 Aug 2021 21:38:03 +0900 Subject: [PATCH 1/6] introduce edit command template to open a specifig line of a file --- docs/Config.md | 5 +++-- pkg/commands/files.go | 14 ++++++++++--- pkg/commands/files_test.go | 30 ++++++++++++++++++++++++++- pkg/config/config_default_platform.go | 3 ++- pkg/config/config_linux.go | 3 ++- pkg/config/config_windows.go | 3 ++- pkg/config/user_config.go | 5 ++++- pkg/gui/files_panel.go | 8 +++++-- pkg/gui/keybindings.go | 2 +- pkg/gui/line_by_line_panel.go | 11 ++++++++++ 10 files changed, 71 insertions(+), 13 deletions(-) diff --git a/docs/Config.md b/docs/Config.md index c2565ae93..355e23d02 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -64,7 +64,8 @@ git: disableForcePushing: false parseEmoji: false os: - editCommand: '' # see 'Configuring File Editing' section + editor: '' # see 'Configuring File Editing' section + editCommand: '{{editor}} {{filename}}' openCommand: '' refresher: refreshInterval: 10 # file/submodule refresh interval in seconds @@ -230,7 +231,7 @@ Lazygit will edit a file with the first set editor in the following: ```yaml os: - editCommand: 'vim' # as an example + editor: 'vim' # as an example ``` 2. \$(git config core.editor) diff --git a/pkg/commands/files.go b/pkg/commands/files.go index f4588aac5..1d4ad5fe6 100644 --- a/pkg/commands/files.go +++ b/pkg/commands/files.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "path/filepath" + "strconv" "time" "github.com/go-errors/errors" @@ -321,8 +322,8 @@ func (c *GitCommand) ResetAndClean() error { return c.RemoveUntrackedFiles() } -func (c *GitCommand) EditFileCmdStr(filename string) (string, error) { - editor := c.Config.GetUserConfig().OS.EditCommand +func (c *GitCommand) EditFileCmdStr(filename string, lineNumber int) (string, error) { + editor := c.Config.GetUserConfig().OS.Editor if editor == "" { editor = c.GetConfigValue("core.editor") @@ -346,5 +347,12 @@ func (c *GitCommand) EditFileCmdStr(filename string) (string, error) { return "", errors.New("No editor defined in config file, $GIT_EDITOR, $VISUAL, $EDITOR, or git config") } - return fmt.Sprintf("%s %s", editor, c.OSCommand.Quote(filename)), nil + templateValues := map[string]string{ + "editor": editor, + "filename": c.OSCommand.Quote(filename), + "line": strconv.Itoa(lineNumber), + } + + editTemplate := c.Config.GetUserConfig().OS.EditCommand + return utils.ResolvePlaceholderString(editTemplate, templateValues), nil } diff --git a/pkg/commands/files_test.go b/pkg/commands/files_test.go index fd4b9f69f..46ccda947 100644 --- a/pkg/commands/files_test.go +++ b/pkg/commands/files_test.go @@ -742,6 +742,7 @@ func TestGitCommandRemoveUntrackedFiles(t *testing.T) { func TestEditFileCmdStr(t *testing.T) { type scenario struct { filename string + configEditor string configEditCommand string command func(string, ...string) *exec.Cmd getenv func(string) string @@ -753,6 +754,7 @@ func TestEditFileCmdStr(t *testing.T) { { "test", "", + "{{editor}} {{filename}}", func(name string, arg ...string) *exec.Cmd { return secureexec.Command("exit", "1") }, @@ -769,6 +771,7 @@ func TestEditFileCmdStr(t *testing.T) { { "test", "nano", + "{{editor}} {{filename}}", func(name string, args ...string) *exec.Cmd { assert.Equal(t, "which", name) return secureexec.Command("echo") @@ -787,6 +790,7 @@ func TestEditFileCmdStr(t *testing.T) { { "test", "", + "{{editor}} {{filename}}", func(name string, arg ...string) *exec.Cmd { assert.Equal(t, "which", name) return secureexec.Command("exit", "1") @@ -805,6 +809,7 @@ func TestEditFileCmdStr(t *testing.T) { { "test", "", + "{{editor}} {{filename}}", func(name string, arg ...string) *exec.Cmd { assert.Equal(t, "which", name) return secureexec.Command("exit", "1") @@ -826,6 +831,7 @@ func TestEditFileCmdStr(t *testing.T) { { "test", "", + "{{editor}} {{filename}}", func(name string, arg ...string) *exec.Cmd { assert.Equal(t, "which", name) return secureexec.Command("exit", "1") @@ -848,6 +854,7 @@ func TestEditFileCmdStr(t *testing.T) { { "test", "", + "{{editor}} {{filename}}", func(name string, arg ...string) *exec.Cmd { assert.Equal(t, "which", name) return secureexec.Command("echo") @@ -866,6 +873,7 @@ func TestEditFileCmdStr(t *testing.T) { { "file/with space", "", + "{{editor}} {{filename}}", func(name string, args ...string) *exec.Cmd { assert.Equal(t, "which", name) return secureexec.Command("echo") @@ -881,14 +889,34 @@ func TestEditFileCmdStr(t *testing.T) { assert.Equal(t, "vi \"file/with space\"", cmdStr) }, }, + { + "open file/at line", + "vim", + "{{editor}} +{{line}} {{filename}}", + 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, "vim +1 \"open file/at line\"", cmdStr) + }, + }, } for _, s := range scenarios { gitCmd := NewDummyGitCommand() + gitCmd.Config.GetUserConfig().OS.Editor = s.configEditor gitCmd.Config.GetUserConfig().OS.EditCommand = s.configEditCommand gitCmd.OSCommand.Command = s.command gitCmd.OSCommand.Getenv = s.getenv gitCmd.getGitConfigValue = s.getGitConfigValue - s.test(gitCmd.EditFileCmdStr(s.filename)) + s.test(gitCmd.EditFileCmdStr(s.filename, 1)) } } diff --git a/pkg/config/config_default_platform.go b/pkg/config/config_default_platform.go index fabdf8a88..cb6e338df 100644 --- a/pkg/config/config_default_platform.go +++ b/pkg/config/config_default_platform.go @@ -5,7 +5,8 @@ package config // GetPlatformDefaultConfig gets the defaults for the platform func GetPlatformDefaultConfig() OSConfig { return OSConfig{ - EditCommand: ``, + Editor: ``, + EditCommand: `{{editor}} {{filename}}`, OpenCommand: "open {{filename}}", OpenLinkCommand: "open {{link}}", } diff --git a/pkg/config/config_linux.go b/pkg/config/config_linux.go index 8399e0e47..1eed335f0 100644 --- a/pkg/config/config_linux.go +++ b/pkg/config/config_linux.go @@ -3,7 +3,8 @@ package config // GetPlatformDefaultConfig gets the defaults for the platform func GetPlatformDefaultConfig() OSConfig { return OSConfig{ - EditCommand: ``, + Editor: ``, + EditCommand: `{{editor}} {{filename}}`, OpenCommand: `sh -c "xdg-open {{filename}} >/dev/null"`, OpenLinkCommand: `sh -c "xdg-open {{link}} >/dev/null"`, } diff --git a/pkg/config/config_windows.go b/pkg/config/config_windows.go index f6780eb6b..1bc919848 100644 --- a/pkg/config/config_windows.go +++ b/pkg/config/config_windows.go @@ -3,7 +3,8 @@ package config // GetPlatformDefaultConfig gets the defaults for the platform func GetPlatformDefaultConfig() OSConfig { return OSConfig{ - EditCommand: ``, + Editor: ``, + EditCommand: `{{editor}} {{filename}}`, OpenCommand: `cmd /c "start "" {{filename}}"`, OpenLinkCommand: `cmd /c "start "" {{link}}"`, } diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index 38259f6f2..ea079948e 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -252,7 +252,10 @@ type KeybindingSubmodulesConfig struct { // OSConfig contains config on the level of the os type OSConfig struct { - // EditCommand is the command for editing a file + // Editor is the command for editing a file + Editor string `yaml:"editor,omitempty"` + + // EditCommand is the command template for editing a file EditCommand string `yaml:"editCommand,omitempty"` // OpenCommand is the command for opening a file diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 48c0621cb..f652c3f05 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -474,13 +474,17 @@ func (gui *Gui) handleCommitEditorPress() error { } func (gui *Gui) editFile(filename string) error { - cmdStr, err := gui.GitCommand.EditFileCmdStr(filename) + return gui.editFileAtLine(filename, 1) +} + +func (gui *Gui) editFileAtLine(filename string, lineNumber int) error { + cmdStr, err := gui.GitCommand.EditFileCmdStr(filename, lineNumber) if err != nil { return gui.surfaceError(err) } return gui.runSubprocessWithSuspenseAndRefresh( - gui.OSCommand.WithSpan(gui.Tr.Spans.EditFile).PrepareShellSubProcess(cmdStr), + gui.OSCommand.WithSpan(gui.Tr.Spans.EditFile).ShellCommandFromString(cmdStr), ) } diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index f9537e755..4b20bab95 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -1301,7 +1301,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { ViewName: "main", Contexts: []string{string(MAIN_STAGING_CONTEXT_KEY)}, Key: gui.getKey(config.Universal.Edit), - Handler: gui.handleFileEdit, + Handler: gui.handleLineByLineEdit, Description: gui.Tr.LcEditFile, }, { diff --git a/pkg/gui/line_by_line_panel.go b/pkg/gui/line_by_line_panel.go index d7a5380b2..7171864f4 100644 --- a/pkg/gui/line_by_line_panel.go +++ b/pkg/gui/line_by_line_panel.go @@ -272,3 +272,14 @@ func (gui *Gui) withLBLActiveCheck(f func(*LblPanelState) error) error { return f(state) } + +func (gui *Gui) handleLineByLineEdit() error { + file := gui.getSelectedFile() + if file == nil { + return nil + } + + lineNumber := gui.State.Panels.LineByLine.CurrentLineNumber() + + return gui.editFileAtLine(file.Name, lineNumber) +} From 67cc65930ae62346fcc522f56da59fba5eef1dbe Mon Sep 17 00:00:00 2001 From: Ryooooooga Date: Tue, 3 Aug 2021 22:00:28 +0900 Subject: [PATCH 2/6] fix out of range error --- pkg/commands/patch/patch_modifier.go | 11 ++++++++--- pkg/commands/patch/patch_modifier_test.go | 2 +- pkg/gui/lbl/state.go | 2 +- pkg/gui/line_by_line_panel.go | 11 +++++++++-- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/pkg/commands/patch/patch_modifier.go b/pkg/commands/patch/patch_modifier.go index c2bbc60f6..e5c6d061f 100644 --- a/pkg/commands/patch/patch_modifier.go +++ b/pkg/commands/patch/patch_modifier.go @@ -137,12 +137,17 @@ func ModifiedPatchForLines(log *logrus.Entry, filename string, diffText string, } // I want to know, given a hunk, what line a given index is on -func (hunk *PatchHunk) LineNumberOfLine(idx int) int { - lines := hunk.bodyLines[0 : idx-hunk.FirstLineIdx-1] +func (hunk *PatchHunk) LineNumberOfLine(idx int) (int, error) { + n := idx - hunk.FirstLineIdx - 1 + if n < 0 || len(hunk.bodyLines) <= n { + return -1, fmt.Errorf("line index out of range") + } + + lines := hunk.bodyLines[0:n] offset := nLinesWithPrefix(lines, []string{"+", " "}) - return hunk.newStart + offset + return hunk.newStart + offset, nil } func nLinesWithPrefix(lines []string, chars []string) int { diff --git a/pkg/commands/patch/patch_modifier_test.go b/pkg/commands/patch/patch_modifier_test.go index 8b866019b..1f1eeb114 100644 --- a/pkg/commands/patch/patch_modifier_test.go +++ b/pkg/commands/patch/patch_modifier_test.go @@ -539,7 +539,7 @@ func TestLineNumberOfLine(t *testing.T) { for _, s := range scenarios { t.Run(s.testName, func(t *testing.T) { - result := s.hunk.LineNumberOfLine(s.idx) + result, _ := s.hunk.LineNumberOfLine(s.idx) if !assert.Equal(t, s.expected, result) { fmt.Println(result) } diff --git a/pkg/gui/lbl/state.go b/pkg/gui/lbl/state.go index 8ae828923..6adb03a54 100644 --- a/pkg/gui/lbl/state.go +++ b/pkg/gui/lbl/state.go @@ -167,7 +167,7 @@ func (s *State) SelectedRange() (int, int) { } } -func (s *State) CurrentLineNumber() int { +func (s *State) CurrentLineNumber() (int, error) { return s.CurrentHunk().LineNumberOfLine(s.selectedLineIdx) } diff --git a/pkg/gui/line_by_line_panel.go b/pkg/gui/line_by_line_panel.go index 7171864f4..6f93c36b9 100644 --- a/pkg/gui/line_by_line_panel.go +++ b/pkg/gui/line_by_line_panel.go @@ -208,7 +208,11 @@ func (gui *Gui) handleOpenFileAtLine() error { } // need to look at current index, then work out what my hunk's header information is, and see how far my line is away from the hunk header - lineNumber := state.CurrentLineNumber() + lineNumber, err := state.CurrentLineNumber() + if err != nil { + lineNumber = 1 + } + filenameWithLineNum := fmt.Sprintf("%s:%d", filename, lineNumber) if err := gui.OSCommand.OpenFile(filenameWithLineNum); err != nil { return err @@ -279,7 +283,10 @@ func (gui *Gui) handleLineByLineEdit() error { return nil } - lineNumber := gui.State.Panels.LineByLine.CurrentLineNumber() + lineNumber, err := gui.State.Panels.LineByLine.CurrentLineNumber() + if err != nil { + lineNumber = 1 + } return gui.editFileAtLine(file.Name, lineNumber) } From ac609bd37c0b879ce08f0fcff7b1c7ef09d37333 Mon Sep 17 00:00:00 2001 From: Ryooooooga Date: Wed, 4 Aug 2021 18:43:34 +0900 Subject: [PATCH 3/6] fix backward compatibility --- docs/Config.md | 6 +++--- pkg/commands/files.go | 6 +++--- pkg/commands/files_test.go | 16 ++++++++-------- pkg/commands/patch/patch_modifier.go | 10 ++++++---- pkg/commands/patch/patch_modifier_test.go | 2 +- pkg/config/config_default_platform.go | 8 ++++---- pkg/config/config_linux.go | 8 ++++---- pkg/config/config_windows.go | 8 ++++---- pkg/config/user_config.go | 8 ++++---- pkg/gui/lbl/state.go | 2 +- pkg/gui/line_by_line_panel.go | 12 ++---------- 11 files changed, 40 insertions(+), 46 deletions(-) diff --git a/docs/Config.md b/docs/Config.md index 355e23d02..aa68cbb64 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -64,8 +64,8 @@ git: disableForcePushing: false parseEmoji: false os: - editor: '' # see 'Configuring File Editing' section - editCommand: '{{editor}} {{filename}}' + editCommand: '' # see 'Configuring File Editing' section + editCommandTemplate: '{{editor}} {{filename}}' openCommand: '' refresher: refreshInterval: 10 # file/submodule refresh interval in seconds @@ -231,7 +231,7 @@ Lazygit will edit a file with the first set editor in the following: ```yaml os: - editor: 'vim' # as an example + editCommand: 'vim' # as an example ``` 2. \$(git config core.editor) diff --git a/pkg/commands/files.go b/pkg/commands/files.go index 1d4ad5fe6..fed1e795c 100644 --- a/pkg/commands/files.go +++ b/pkg/commands/files.go @@ -323,7 +323,7 @@ func (c *GitCommand) ResetAndClean() error { } func (c *GitCommand) EditFileCmdStr(filename string, lineNumber int) (string, error) { - editor := c.Config.GetUserConfig().OS.Editor + editor := c.Config.GetUserConfig().OS.EditCommand if editor == "" { editor = c.GetConfigValue("core.editor") @@ -353,6 +353,6 @@ func (c *GitCommand) EditFileCmdStr(filename string, lineNumber int) (string, er "line": strconv.Itoa(lineNumber), } - editTemplate := c.Config.GetUserConfig().OS.EditCommand - return utils.ResolvePlaceholderString(editTemplate, templateValues), nil + editCmdTemplate := c.Config.GetUserConfig().OS.EditCommandTemplate + return utils.ResolvePlaceholderString(editCmdTemplate, templateValues), nil } diff --git a/pkg/commands/files_test.go b/pkg/commands/files_test.go index 46ccda947..f12067e55 100644 --- a/pkg/commands/files_test.go +++ b/pkg/commands/files_test.go @@ -741,13 +741,13 @@ func TestGitCommandRemoveUntrackedFiles(t *testing.T) { // TestEditFileCmdStr is a function. func TestEditFileCmdStr(t *testing.T) { type scenario struct { - filename string - configEditor string - configEditCommand string - command func(string, ...string) *exec.Cmd - getenv func(string) string - getGitConfigValue func(string) (string, error) - test func(string, error) + filename string + configEditCommand string + configEditCommandTemplate string + command func(string, ...string) *exec.Cmd + getenv func(string) string + getGitConfigValue func(string) (string, error) + test func(string, error) } scenarios := []scenario{ @@ -912,8 +912,8 @@ func TestEditFileCmdStr(t *testing.T) { for _, s := range scenarios { gitCmd := NewDummyGitCommand() - gitCmd.Config.GetUserConfig().OS.Editor = s.configEditor gitCmd.Config.GetUserConfig().OS.EditCommand = s.configEditCommand + gitCmd.Config.GetUserConfig().OS.EditCommandTemplate = s.configEditCommandTemplate gitCmd.OSCommand.Command = s.command gitCmd.OSCommand.Getenv = s.getenv gitCmd.getGitConfigValue = s.getGitConfigValue diff --git a/pkg/commands/patch/patch_modifier.go b/pkg/commands/patch/patch_modifier.go index e5c6d061f..3ab13931b 100644 --- a/pkg/commands/patch/patch_modifier.go +++ b/pkg/commands/patch/patch_modifier.go @@ -137,17 +137,19 @@ func ModifiedPatchForLines(log *logrus.Entry, filename string, diffText string, } // I want to know, given a hunk, what line a given index is on -func (hunk *PatchHunk) LineNumberOfLine(idx int) (int, error) { +func (hunk *PatchHunk) LineNumberOfLine(idx int) int { n := idx - hunk.FirstLineIdx - 1 - if n < 0 || len(hunk.bodyLines) <= n { - return -1, fmt.Errorf("line index out of range") + if n < 0 { + n = 0 + } else if n >= len(hunk.bodyLines) { + n = len(hunk.bodyLines) - 1 } lines := hunk.bodyLines[0:n] offset := nLinesWithPrefix(lines, []string{"+", " "}) - return hunk.newStart + offset, nil + return hunk.newStart + offset } func nLinesWithPrefix(lines []string, chars []string) int { diff --git a/pkg/commands/patch/patch_modifier_test.go b/pkg/commands/patch/patch_modifier_test.go index 1f1eeb114..8b866019b 100644 --- a/pkg/commands/patch/patch_modifier_test.go +++ b/pkg/commands/patch/patch_modifier_test.go @@ -539,7 +539,7 @@ func TestLineNumberOfLine(t *testing.T) { for _, s := range scenarios { t.Run(s.testName, func(t *testing.T) { - result, _ := s.hunk.LineNumberOfLine(s.idx) + result := s.hunk.LineNumberOfLine(s.idx) if !assert.Equal(t, s.expected, result) { fmt.Println(result) } diff --git a/pkg/config/config_default_platform.go b/pkg/config/config_default_platform.go index cb6e338df..0f56297d3 100644 --- a/pkg/config/config_default_platform.go +++ b/pkg/config/config_default_platform.go @@ -5,9 +5,9 @@ package config // GetPlatformDefaultConfig gets the defaults for the platform func GetPlatformDefaultConfig() OSConfig { return OSConfig{ - Editor: ``, - EditCommand: `{{editor}} {{filename}}`, - OpenCommand: "open {{filename}}", - OpenLinkCommand: "open {{link}}", + EditCommand: ``, + EditCommandTemplate: `{{editor}} {{filename}}`, + OpenCommand: "open {{filename}}", + OpenLinkCommand: "open {{link}}", } } diff --git a/pkg/config/config_linux.go b/pkg/config/config_linux.go index 1eed335f0..fe75b7322 100644 --- a/pkg/config/config_linux.go +++ b/pkg/config/config_linux.go @@ -3,9 +3,9 @@ package config // GetPlatformDefaultConfig gets the defaults for the platform func GetPlatformDefaultConfig() OSConfig { return OSConfig{ - Editor: ``, - EditCommand: `{{editor}} {{filename}}`, - OpenCommand: `sh -c "xdg-open {{filename}} >/dev/null"`, - OpenLinkCommand: `sh -c "xdg-open {{link}} >/dev/null"`, + EditCommand: ``, + EditCommandTemplate: `{{editor}} {{filename}}`, + OpenCommand: `sh -c "xdg-open {{filename}} >/dev/null"`, + OpenLinkCommand: `sh -c "xdg-open {{link}} >/dev/null"`, } } diff --git a/pkg/config/config_windows.go b/pkg/config/config_windows.go index 1bc919848..71124808b 100644 --- a/pkg/config/config_windows.go +++ b/pkg/config/config_windows.go @@ -3,9 +3,9 @@ package config // GetPlatformDefaultConfig gets the defaults for the platform func GetPlatformDefaultConfig() OSConfig { return OSConfig{ - Editor: ``, - EditCommand: `{{editor}} {{filename}}`, - OpenCommand: `cmd /c "start "" {{filename}}"`, - OpenLinkCommand: `cmd /c "start "" {{link}}"`, + EditCommand: ``, + EditCommandTemplate: `{{editor}} {{filename}}`, + OpenCommand: `cmd /c "start "" {{filename}}"`, + OpenLinkCommand: `cmd /c "start "" {{link}}"`, } } diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index ea079948e..e7f952890 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -252,12 +252,12 @@ type KeybindingSubmodulesConfig struct { // OSConfig contains config on the level of the os type OSConfig struct { - // Editor is the command for editing a file - Editor string `yaml:"editor,omitempty"` - - // EditCommand is the command template for editing a file + // EditCommand is the command for editing a file EditCommand string `yaml:"editCommand,omitempty"` + // EditCommandTemplate is the command template for editing a file + EditCommandTemplate string `yaml:"editCommandTemplate,omitempty"` + // OpenCommand is the command for opening a file OpenCommand string `yaml:"openCommand,omitempty"` diff --git a/pkg/gui/lbl/state.go b/pkg/gui/lbl/state.go index 6adb03a54..8ae828923 100644 --- a/pkg/gui/lbl/state.go +++ b/pkg/gui/lbl/state.go @@ -167,7 +167,7 @@ func (s *State) SelectedRange() (int, int) { } } -func (s *State) CurrentLineNumber() (int, error) { +func (s *State) CurrentLineNumber() int { return s.CurrentHunk().LineNumberOfLine(s.selectedLineIdx) } diff --git a/pkg/gui/line_by_line_panel.go b/pkg/gui/line_by_line_panel.go index 6f93c36b9..8121b6ed3 100644 --- a/pkg/gui/line_by_line_panel.go +++ b/pkg/gui/line_by_line_panel.go @@ -208,11 +208,7 @@ func (gui *Gui) handleOpenFileAtLine() error { } // need to look at current index, then work out what my hunk's header information is, and see how far my line is away from the hunk header - lineNumber, err := state.CurrentLineNumber() - if err != nil { - lineNumber = 1 - } - + lineNumber := state.CurrentLineNumber() filenameWithLineNum := fmt.Sprintf("%s:%d", filename, lineNumber) if err := gui.OSCommand.OpenFile(filenameWithLineNum); err != nil { return err @@ -283,10 +279,6 @@ func (gui *Gui) handleLineByLineEdit() error { return nil } - lineNumber, err := gui.State.Panels.LineByLine.CurrentLineNumber() - if err != nil { - lineNumber = 1 - } - + lineNumber := gui.State.Panels.LineByLine.CurrentLineNumber() return gui.editFileAtLine(file.Name, lineNumber) } From 5ea3dc757926baf7e3cb059ffc53f7a257962331 Mon Sep 17 00:00:00 2001 From: Ryooooooga Date: Fri, 20 Aug 2021 22:39:08 +0900 Subject: [PATCH 4/6] add documentation of editCommandTemplate --- docs/Config.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/Config.md b/docs/Config.md index aa68cbb64..c1d3042df 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -242,6 +242,24 @@ os: Lazygit will log an error if none of these options are set. +You can give the number of lines you are currently pointing to in the line-by-line panel. + +```yaml +os: + editCommand: 'vim' + editCommandTemplate: '{{editor}} +{{line}} {{filename}}' +``` + +or + +```yaml +os: + editCommand: 'code' + editCommandTemplate: '{{editor}} --goto {{filename}}:{{line}}' +``` + +`{{editor}}` in `editCommandTemplate` is replaced with `editCommand`. + ### Recommended Config Values for users of VSCode From 821a59f21da3a15e61c327f1a30363b51fb198c2 Mon Sep 17 00:00:00 2001 From: Ryooooooga Date: Sat, 21 Aug 2021 01:01:34 +0900 Subject: [PATCH 5/6] apply suggestion for the document of editCommandTemplate --- docs/Config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Config.md b/docs/Config.md index c1d3042df..acd44cab0 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -242,7 +242,7 @@ os: Lazygit will log an error if none of these options are set. -You can give the number of lines you are currently pointing to in the line-by-line panel. +You can specify a line number you are currently at when in the line-by-line mode. ```yaml os: From 44140adb921d7891778deb7f1aa2f813622302f4 Mon Sep 17 00:00:00 2001 From: Ryoga Date: Mon, 23 Aug 2021 08:33:05 +0900 Subject: [PATCH 6/6] Update docs/Config.md Co-authored-by: Jesse Duffield --- docs/Config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Config.md b/docs/Config.md index acd44cab0..724f35334 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -258,7 +258,7 @@ os: editCommandTemplate: '{{editor}} --goto {{filename}}:{{line}}' ``` -`{{editor}}` in `editCommandTemplate` is replaced with `editCommand`. +`{{editor}}` in `editCommandTemplate` is replaced with the value of `editCommand`. ### Recommended Config Values