mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-09-16 09:16:26 +02:00
Open file on unspecified line
This commit is contained in:
@@ -27,7 +27,7 @@ func (self *FileCommands) Cat(fileName string) (string, error) {
|
|||||||
return string(buf), nil
|
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
|
editor := self.UserConfig.OS.EditCommand
|
||||||
|
|
||||||
if editor == "" {
|
if editor == "" {
|
||||||
@@ -50,6 +50,14 @@ func (self *FileCommands) GetEditCmdStr(filename string, lineNumber int) (string
|
|||||||
if editor == "" {
|
if editor == "" {
|
||||||
return "", errors.New("No editor defined in config file, $GIT_EDITOR, $VISUAL, $EDITOR, or git config")
|
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{
|
templateValues := map[string]string{
|
||||||
"editor": editor,
|
"editor": editor,
|
||||||
|
@@ -34,7 +34,21 @@ func NewFilesHelper(
|
|||||||
var _ IFilesHelper = &FilesHelper{}
|
var _ IFilesHelper = &FilesHelper{}
|
||||||
|
|
||||||
func (self *FilesHelper) EditFile(filename string) error {
|
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 {
|
func (self *FilesHelper) EditFileAtLine(filename string, lineNumber int) error {
|
||||||
|
Reference in New Issue
Block a user