mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 12:25:47 +02:00
Open file on unspecified line
This commit is contained in:
parent
16802a048e
commit
936ae69429
2 changed files with 24 additions and 2 deletions
|
@ -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,
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue