diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2019-10-07 12:34:12 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2019-11-11 21:45:31 +1100 |
commit | cbc82cd3c1e8668d37aad049401222a382613f98 (patch) | |
tree | 1925bc51831d4f8c7505947e1cef70e7f88d2e68 /pkg/gui/quitting.go | |
parent | 29ee2399876bccbc4fe388252545df2763b11029 (diff) |
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
}
Diffstat (limited to 'pkg/gui/quitting.go')
-rw-r--r-- | pkg/gui/quitting.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/pkg/gui/quitting.go b/pkg/gui/quitting.go new file mode 100644 index 000000000..fca71d221 --- /dev/null +++ b/pkg/gui/quitting.go @@ -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 +} |