mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-04 23:37:41 +02:00
allow for changing the current directory on exit
For this to work you'll need to put this in your ~/.zshrc (or equivalent rc file): lg() { export LAZYGIT_NEW_DIR_FILE=/Users/jesseduffieldduffield/Library/Application\ Support/jesseduffield/lazygit/.lastd lazygit "$@" if [ -f $LAZYGIT_NEW_DIR_FILE ]; then cd "$(cat $LAZYGIT_NEW_DIR_FILE)" rm -f $LAZYGIT_NEW_DIR_FILE > /dev/null fi }
This commit is contained in:
parent
29ee239987
commit
cbc82cd3c1
@ -160,6 +160,7 @@ type guiState struct {
|
|||||||
Context string // important not to set this value directly but to use gui.changeContext("new context")
|
Context string // important not to set this value directly but to use gui.changeContext("new context")
|
||||||
CherryPickedCommits []*commands.Commit
|
CherryPickedCommits []*commands.Commit
|
||||||
SplitMainPanel bool
|
SplitMainPanel bool
|
||||||
|
RetainOriginalDir bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// for now the split view will always be on
|
// for now the split view will always be on
|
||||||
@ -779,6 +780,12 @@ func (gui *Gui) RunWithSubprocesses() error {
|
|||||||
for {
|
for {
|
||||||
if err := gui.Run(); err != nil {
|
if err := gui.Run(); err != nil {
|
||||||
if err == gocui.ErrQuit {
|
if err == gocui.ErrQuit {
|
||||||
|
if !gui.State.RetainOriginalDir {
|
||||||
|
if err := gui.recordCurrentDirectory(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
break
|
break
|
||||||
} else if err == gui.Errors.ErrSwitchRepo {
|
} else if err == gui.Errors.ErrSwitchRepo {
|
||||||
continue
|
continue
|
||||||
@ -818,18 +825,6 @@ func (gui *Gui) runCommand() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) quit(g *gocui.Gui, v *gocui.View) error {
|
|
||||||
if gui.State.Updating {
|
|
||||||
return gui.createUpdateQuitConfirmation(g, v)
|
|
||||||
}
|
|
||||||
if gui.Config.GetUserConfig().GetBool("confirmOnQuit") {
|
|
||||||
return gui.createConfirmationPanel(g, v, true, "", gui.Tr.SLocalize("ConfirmQuit"), func(g *gocui.Gui, v *gocui.View) error {
|
|
||||||
return gocui.ErrQuit
|
|
||||||
}, nil)
|
|
||||||
}
|
|
||||||
return gocui.ErrQuit
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) handleDonate(g *gocui.Gui, v *gocui.View) error {
|
func (gui *Gui) handleDonate(g *gocui.Gui, v *gocui.View) error {
|
||||||
if !gui.g.Mouse {
|
if !gui.g.Mouse {
|
||||||
return nil
|
return nil
|
||||||
|
@ -72,17 +72,22 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
ViewName: "",
|
ViewName: "",
|
||||||
Key: 'q',
|
Key: 'q',
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.quit,
|
Handler: gui.handleQuit,
|
||||||
|
}, {
|
||||||
|
ViewName: "",
|
||||||
|
Key: 'Q',
|
||||||
|
Modifier: gocui.ModNone,
|
||||||
|
Handler: gui.handleQuitWithoutChangingDirectory,
|
||||||
}, {
|
}, {
|
||||||
ViewName: "",
|
ViewName: "",
|
||||||
Key: gocui.KeyCtrlC,
|
Key: gocui.KeyCtrlC,
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.quit,
|
Handler: gui.handleQuit,
|
||||||
}, {
|
}, {
|
||||||
ViewName: "",
|
ViewName: "",
|
||||||
Key: gocui.KeyEsc,
|
Key: gocui.KeyEsc,
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.quit,
|
Handler: gui.handleQuit,
|
||||||
}, {
|
}, {
|
||||||
ViewName: "",
|
ViewName: "",
|
||||||
Key: gocui.KeyPgup,
|
Key: gocui.KeyPgup,
|
||||||
|
48
pkg/gui/quitting.go
Normal file
48
pkg/gui/quitting.go
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
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) quit(v *gocui.View) error {
|
||||||
|
if gui.State.Updating {
|
||||||
|
return gui.createUpdateQuitConfirmation(gui.g, v)
|
||||||
|
}
|
||||||
|
if gui.Config.GetUserConfig().GetBool("confirmOnQuit") {
|
||||||
|
return gui.createConfirmationPanel(gui.g, v, true, "", gui.Tr.SLocalize("ConfirmQuit"), func(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
return gocui.ErrQuit
|
||||||
|
}, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
return gocui.ErrQuit
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user