lazygit icon indicating copy to clipboard operation
lazygit copied to clipboard

Opening files in unstaged pane - filename includes linenumber, which causes opening files to fail

Open StefanMich opened this issue 4 years ago • 4 comments

Describe the bug Configuring a customer "opencommand" works, but when opening the file in the "unstaged changes" pae the filename parameter seem to be of a different format than what is used other places - it is of the form :, instead of just . Using pycharm to open that format fails, because it is interpreting the colon and number as part of the filename.

My config:

os:
  editCommand: 'pycharm' # see 'Configuring File Editing' section
  editCommandTemplate: 'pycharm --line {{line}} {{filename}}'
  openCommand: 'pycharm {{filename}}'

To Reproduce Steps to reproduce the behavior:

  1. Go to a change in the file panel
  2. Press enter, opening the change in the unstaged changes panel
  3. Press O for opening the file
  4. File opens, but it is opening a file that does not exist, because the ":5" part is included

Expected behavior File opens with the usual format, {{filename}} {{line}} being separated

Screenshots Command being executed: image

Desktop (please complete the following information):

  • OS: ubuntu 20.04
  • Lazygit Version 0.32.2

StefanMich avatar Jan 26 '22 08:01 StefanMich

The culprit is pkg/gui/line_by_line_panel.go:220:

		lineNumber := state.CurrentLineNumber()
		filenameWithLineNum := fmt.Sprintf("%s:%d", filename, lineNumber)
		if err := gui.OSCommand.OpenFile(filenameWithLineNum); err != nil {
			return err
		}

Unlike in the handler for editing a file, here we're assuming the required format. We should have an openCommandTemplate thingo just like we do for editCommandTemplate, and use that here. I'll chuck a good first issue label on this. If you want to take a stab at it @StefanMich lemme know!

jesseduffield avatar Jan 27 '22 08:01 jesseduffield

I'll give it a go :) Fixed in #1751

StefanMich avatar Jan 31 '22 21:01 StefanMich

Solved by #1804 and can be closed?

mark2185 avatar Mar 28 '22 10:03 mark2185

Yes 👍

StefanMich avatar Apr 03 '22 18:04 StefanMich