Skip to content

Commit

Permalink
Add git difftool support (keybinding <c-t>)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeevro committed Aug 1, 2022
1 parent 69f4292 commit 4686571
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/keybindings/Keybindings_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>ctrl+s</kbd>: view filter-by-path options
<kbd>W</kbd>: open diff menu
<kbd>ctrl+e</kbd>: open diff menu
<kbd>ctrl+t</kbd>: Launch git difftool
<kbd>@</kbd>: open command log menu
<kbd>}</kbd>: Increase the size of the context shown around changes in the diff view
<kbd>{</kbd>: Decrease the size of the context shown around changes in the diff view
Expand Down
1 change: 1 addition & 0 deletions docs/keybindings/Keybindings_nl.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>ctrl+s</kbd>: bekijk scoping opties
<kbd>W</kbd>: open diff menu
<kbd>ctrl+e</kbd>: open diff menu
<kbd>ctrl+t</kbd>: Launch git difftool
<kbd>@</kbd>: open command log menu
<kbd>}</kbd>: Increase the size of the context shown around changes in the diff view
<kbd>{</kbd>: Decrease the size of the context shown around changes in the diff view
Expand Down
1 change: 1 addition & 0 deletions docs/keybindings/Keybindings_pl.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>ctrl+s</kbd>: view filter-by-path options
<kbd>W</kbd>: open diff menu
<kbd>ctrl+e</kbd>: open diff menu
<kbd>ctrl+t</kbd>: Launch git difftool
<kbd>@</kbd>: open command log menu
<kbd>}</kbd>: Increase the size of the context shown around changes in the diff view
<kbd>{</kbd>: Decrease the size of the context shown around changes in the diff view
Expand Down
1 change: 1 addition & 0 deletions docs/keybindings/Keybindings_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>ctrl+s</kbd>: 查看按路径过滤选项
<kbd>W</kbd>: 打开 diff 菜单
<kbd>ctrl+e</kbd>: 打开 diff 菜单
<kbd>ctrl+t</kbd>: Launch git difftool
<kbd>@</kbd>: 打开命令日志菜单
<kbd>}</kbd>: 扩大差异视图中显示的上下文范围
<kbd>{</kbd>: 缩小差异视图中显示的上下文范围
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ type KeybindingUniversalConfig struct {
FilteringMenu string `yaml:"filteringMenu"`
DiffingMenu string `yaml:"diffingMenu"`
DiffingMenuAlt string `yaml:"diffingMenu-alt"`
DiffTool string `yaml:"difftool"`
CopyToClipboard string `yaml:"copyToClipboard"`
OpenRecentRepos string `yaml:"openRecentRepos"`
SubmitEditorText string `yaml:"submitEditorText"`
Expand Down Expand Up @@ -473,6 +474,7 @@ func GetDefaultConfig() *UserConfig {
FilteringMenu: "<c-s>",
DiffingMenu: "W",
DiffingMenuAlt: "<c-e>",
DiffTool: "<c-t>",
CopyToClipboard: "<c-o>",
SubmitEditorText: "<enter>",
AppendNewline: "<a-enter>",
Expand Down
33 changes: 33 additions & 0 deletions pkg/gui/diffing.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"strings"

"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/modes/diffing"
"github.com/jesseduffield/lazygit/pkg/gui/types"
Expand Down Expand Up @@ -159,3 +160,35 @@ func (gui *Gui) handleCreateDiffingMenuPanel() error {

return gui.c.Menu(types.CreateMenuOptions{Title: gui.c.Tr.DiffingMenuTitle, Items: menuItems})
}

func (gui *Gui) handleLaunchDiffTool() error {
gui.c.LogAction("Launch DiffTool")

cmdStr := "git difftool --submodule "

file := gui.currentlySelectedFilename()
if file == "" || oscommands.FileType(file) == "directory" {
cmdStr += "-d "
} else {
cmdStr += "-y "
}

if gui.State.Modes.Diffing.Active() {
cmdStr += gui.diffStr()
} else {
diffTerm := gui.currentDiffTerminal()
if diffTerm != "" {
cmdStr += fmt.Sprintf(" %s^ %s", diffTerm, diffTerm)
}
}

if file != "" {
cmdStr += " -- " + file
}

gui.c.LogCommand(cmdStr, true)

osCmd := gui.os.Cmd.New(cmdStr)

return osCmd.GetCmd().Start()
}
6 changes: 6 additions & 0 deletions pkg/gui/keybindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,12 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi
Description: self.c.Tr.LcOpenDiffingMenu,
OpensMenu: true,
},
{
ViewName: "",
Key: opts.GetKey(opts.Config.Universal.DiffTool),
Handler: self.handleLaunchDiffTool,
Description: self.c.Tr.LcLaunchDiffTool,
},
{
ViewName: "",
Key: opts.GetKey(opts.Config.Universal.ExtrasMenu),
Expand Down
2 changes: 2 additions & 0 deletions pkg/i18n/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ type TranslationSet struct {
DiffingMenuTitle string
LcSwapDiff string
LcOpenDiffingMenu string
LcLaunchDiffTool string
LcOpenExtrasMenu string
LcShowingGitDiff string
LcCommitDiff string
Expand Down Expand Up @@ -1027,6 +1028,7 @@ func EnglishTranslationSet() TranslationSet {
DiffingMenuTitle: "Diffing",
LcSwapDiff: "reverse diff direction",
LcOpenDiffingMenu: "open diff menu",
LcLaunchDiffTool: "Launch git difftool",
// the actual view is the extras view which I intend to give more tabs in future but for now we'll only mention the command log part
LcOpenExtrasMenu: "open command log menu",
LcShowingGitDiff: "showing output for:",
Expand Down

0 comments on commit 4686571

Please sign in to comment.