mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-29 23:17:32 +02:00
Record current directory on switch
This commit is contained in:
parent
950bb5090d
commit
b8fc829f86
@ -128,6 +128,11 @@ func NewApp(config config.AppConfigurer, filterPath string) (*App, error) {
|
|||||||
return app, err
|
return app, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dirName, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
return app, err
|
||||||
|
}
|
||||||
|
|
||||||
showRecentRepos, err := app.setupRepo()
|
showRecentRepos, err := app.setupRepo()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return app, err
|
return app, err
|
||||||
@ -135,7 +140,7 @@ func NewApp(config config.AppConfigurer, filterPath string) (*App, error) {
|
|||||||
|
|
||||||
gitConfig := git_config.NewStdCachedGitConfig(app.Log)
|
gitConfig := git_config.NewStdCachedGitConfig(app.Log)
|
||||||
|
|
||||||
app.Gui, err = gui.NewGui(app.Common, config, gitConfig, app.Updater, filterPath, showRecentRepos)
|
app.Gui, err = gui.NewGui(app.Common, config, gitConfig, app.Updater, filterPath, showRecentRepos, dirName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return app, err
|
return app, err
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,6 @@ func NewDummyUpdater() *updates.Updater {
|
|||||||
|
|
||||||
func NewDummyGui() *Gui {
|
func NewDummyGui() *Gui {
|
||||||
newAppConfig := config.NewDummyAppConfig()
|
newAppConfig := config.NewDummyAppConfig()
|
||||||
dummyGui, _ := NewGui(utils.NewDummyCommon(), newAppConfig, git_config.NewFakeGitConfig(nil), NewDummyUpdater(), "", false)
|
dummyGui, _ := NewGui(utils.NewDummyCommon(), newAppConfig, git_config.NewFakeGitConfig(nil), NewDummyUpdater(), "", false, "")
|
||||||
return dummyGui
|
return dummyGui
|
||||||
}
|
}
|
||||||
|
@ -124,6 +124,8 @@ type Gui struct {
|
|||||||
PopupHandler PopupHandler
|
PopupHandler PopupHandler
|
||||||
|
|
||||||
IsNewRepo bool
|
IsNewRepo bool
|
||||||
|
|
||||||
|
InitialRepoDir string
|
||||||
}
|
}
|
||||||
|
|
||||||
type listPanelState struct {
|
type listPanelState struct {
|
||||||
@ -447,6 +449,7 @@ func NewGui(
|
|||||||
updater *updates.Updater,
|
updater *updates.Updater,
|
||||||
filterPath string,
|
filterPath string,
|
||||||
showRecentRepos bool,
|
showRecentRepos bool,
|
||||||
|
initialRepoDir string,
|
||||||
) (*Gui, error) {
|
) (*Gui, error) {
|
||||||
gui := &Gui{
|
gui := &Gui{
|
||||||
Common: cmn,
|
Common: cmn,
|
||||||
@ -464,6 +467,8 @@ func NewGui(
|
|||||||
// but now we do it via state. So we need to still support the config for the
|
// but now we do it via state. So we need to still support the config for the
|
||||||
// sake of backwards compatibility. We're making use of short circuiting here
|
// sake of backwards compatibility. We're making use of short circuiting here
|
||||||
ShowExtrasWindow: cmn.UserConfig.Gui.ShowCommandLog && !config.GetAppState().HideCommandLog,
|
ShowExtrasWindow: cmn.UserConfig.Gui.ShowCommandLog && !config.GetAppState().HideCommandLog,
|
||||||
|
|
||||||
|
InitialRepoDir: initialRepoDir,
|
||||||
}
|
}
|
||||||
|
|
||||||
guiIO := oscommands.NewGuiIO(
|
guiIO := oscommands.NewGuiIO(
|
||||||
@ -590,7 +595,11 @@ func (gui *Gui) RunAndHandleError() error {
|
|||||||
|
|
||||||
switch err {
|
switch err {
|
||||||
case gocui.ErrQuit:
|
case gocui.ErrQuit:
|
||||||
if !gui.State.RetainOriginalDir {
|
if gui.State.RetainOriginalDir {
|
||||||
|
if err := gui.recordDirectory(gui.InitialRepoDir); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if err := gui.recordCurrentDirectory(); err != nil {
|
if err := gui.recordCurrentDirectory(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -11,16 +11,18 @@ import (
|
|||||||
// shell can then change to that directory. That means you don't get kicked
|
// shell can then change to that directory. That means you don't get kicked
|
||||||
// back to the directory that you started with.
|
// back to the directory that you started with.
|
||||||
func (gui *Gui) recordCurrentDirectory() error {
|
func (gui *Gui) recordCurrentDirectory() error {
|
||||||
if os.Getenv("LAZYGIT_NEW_DIR_FILE") == "" {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// determine current directory, set it in LAZYGIT_NEW_DIR_FILE
|
// determine current directory, set it in LAZYGIT_NEW_DIR_FILE
|
||||||
dirName, err := os.Getwd()
|
dirName, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
return gui.recordDirectory(dirName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) recordDirectory(dirName string) error {
|
||||||
|
if os.Getenv("LAZYGIT_NEW_DIR_FILE") == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return gui.OSCommand.CreateFileWithContent(os.Getenv("LAZYGIT_NEW_DIR_FILE"), dirName)
|
return gui.OSCommand.CreateFileWithContent(os.Getenv("LAZYGIT_NEW_DIR_FILE"), dirName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,6 +84,10 @@ func (gui *Gui) dispatchSwitchToRepo(path string, reuse bool) error {
|
|||||||
gui.Mutexes.RefreshingFilesMutex.Lock()
|
gui.Mutexes.RefreshingFilesMutex.Lock()
|
||||||
defer gui.Mutexes.RefreshingFilesMutex.Unlock()
|
defer gui.Mutexes.RefreshingFilesMutex.Unlock()
|
||||||
|
|
||||||
|
if err := gui.recordCurrentDirectory(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
gui.resetState("", reuse)
|
gui.resetState("", reuse)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user