diff options
author | Luka Markušić <luka.markusic@microblink.com> | 2023-02-03 11:07:42 +0100 |
---|---|---|
committer | Luka Markušić <luka.markusic@microblink.com> | 2023-02-03 11:07:42 +0100 |
commit | 936ae69429aa48b61cc9da878544c014c8288bf1 (patch) | |
tree | 7bdc42226bcedb1eb9d52d5724c700886d7979c3 | |
parent | 16802a048e0425182f08cf0e9a2bc31480e9a55d (diff) |
Open file on unspecified linefeature/open-file-without-specified-line
-rw-r--r-- | pkg/commands/git_commands/file.go | 10 | ||||
-rw-r--r-- | pkg/gui/controllers/helpers/files_helper.go | 16 |
2 files changed, 24 insertions, 2 deletions
diff --git a/pkg/commands/git_commands/file.go b/pkg/commands/git_commands/file.go index 111733bb7..630c10374 100644 --- a/pkg/commands/git_commands/file.go +++ b/pkg/commands/git_commands/file.go @@ -27,7 +27,7 @@ func (self *FileCommands) Cat(fileName string) (string, error) { return string(buf), nil } -func (self *FileCommands) GetEditCmdStr(filename string, lineNumber int) (string, error) { +func (self *FileCommands) GetEditor() (string, error) { editor := self.UserConfig.OS.EditCommand if editor == "" { @@ -50,6 +50,14 @@ func (self *FileCommands) GetEditCmdStr(filename string, lineNumber int) (string if editor == "" { return "", errors.New("No editor defined in config file, $GIT_EDITOR, $VISUAL, $EDITOR, or git config") } + return editor, nil +} + +func (self *FileCommands) GetEditCmdStr(filename string, lineNumber int) (string, error) { + editor, err := self.GetEditor() + if err != nil { + return "", err + } templateValues := map[string]string{ "editor": editor, diff --git a/pkg/gui/controllers/helpers/files_helper.go b/pkg/gui/controllers/helpers/files_helper.go index 72be6e4e5..c3c1737e5 100644 --- a/pkg/gui/controllers/helpers/files_helper.go +++ b/pkg/gui/controllers/helpers/files_helper.go @@ -34,7 +34,21 @@ func NewFilesHelper( var _ IFilesHelper = &FilesHelper{} func (self *FilesHelper) EditFile(filename string) error { - return self.EditFileAtLine(filename, 1) + editor, err := self.git.File.GetEditor() + if err != nil { + return self.c.Error(err) + } + editCmd := "" + switch editor { + case "code": + editCmd = editor + " -r --goto -- " + filename + default: + editCmd = editor + " -- " + filename + } + self.c.LogAction(self.c.Tr.Actions.EditFile) + return self.c.RunSubprocessAndRefresh( + self.os.Cmd.NewShell(editCmd), + ) } func (self *FilesHelper) EditFileAtLine(filename string, lineNumber int) error { |