1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-12 11:15:00 +02:00
lazygit/pkg/gui/quitting.go

71 lines
1.7 KiB
Go
Raw Normal View History

package gui
import (
"os"
"github.com/jesseduffield/gocui"
)
// when a user runs lazygit with the LAZYGIT_NEW_DIR_FILE env variable defined
// we will write the current directory to that file on exit so that their
// shell can then change to that directory. That means you don't get kicked
// back to the directory that you started with.
func (gui *Gui) recordCurrentDirectory() error {
if os.Getenv("LAZYGIT_NEW_DIR_FILE") == "" {
return nil
}
// determine current directory, set it in LAZYGIT_NEW_DIR_FILE
dirName, err := os.Getwd()
if err != nil {
return err
}
return gui.OSCommand.CreateFileWithContent(os.Getenv("LAZYGIT_NEW_DIR_FILE"), dirName)
}
func (gui *Gui) handleQuitWithoutChangingDirectory(g *gocui.Gui, v *gocui.View) error {
gui.State.RetainOriginalDir = true
return gui.quit(v)
}
func (gui *Gui) handleQuit(g *gocui.Gui, v *gocui.View) error {
gui.State.RetainOriginalDir = false
return gui.quit(v)
}
func (gui *Gui) handleTopLevelReturn(g *gocui.Gui, v *gocui.View) error {
if gui.inDiffMode() {
return gui.exitDiffMode()
}
if gui.inFilterMode() {
return gui.exitFilterMode()
}
if gui.Config.GetUserConfig().GetBool("quitOnTopLevelReturn") {
return gui.handleQuit(g, v)
}
return nil
}
func (gui *Gui) quit(v *gocui.View) error {
if gui.State.Updating {
return gui.createUpdateQuitConfirmation(gui.g, v)
}
if gui.Config.GetUserConfig().GetBool("confirmOnQuit") {
2020-08-15 08:36:39 +02:00
return gui.createConfirmationPanel(createConfirmationPanelOpts{
returnToView: v,
returnFocusOnClose: true,
title: "",
prompt: gui.Tr.SLocalize("ConfirmQuit"),
handleConfirm: func() error {
return gocui.ErrQuit
},
})
}
return gocui.ErrQuit
}