diff options
author | mjarkk <mkopenga@gmail.com> | 2021-07-27 22:03:37 +0200 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-10-16 12:22:34 +1100 |
commit | 913a2fd0656c393e743686cf6fe823a963916463 (patch) | |
tree | 6ee4b1edb5a90a18a21790a5aa0d9e03d2eec5b6 /pkg/gui/status_panel.go | |
parent | db736896bc2f10f45f8dbb0fcaccdda2490f32d5 (diff) |
Allow having multiple config files
Diffstat (limited to 'pkg/gui/status_panel.go')
-rw-r--r-- | pkg/gui/status_panel.go | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/pkg/gui/status_panel.go b/pkg/gui/status_panel.go index a3f8deb10..2800a6bf2 100644 --- a/pkg/gui/status_panel.go +++ b/pkg/gui/status_panel.go @@ -1,6 +1,7 @@ package gui import ( + "errors" "fmt" "strings" @@ -114,13 +115,38 @@ func (gui *Gui) handleStatusSelect() error { }) } +func (gui *Gui) askForConfigFile(action func(file string) error) error { + confFiles := gui.Config.GetUserConfigFiles() + switch len(confFiles) { + case 0: + return errors.New("no config file found") + case 1: + return action(confFiles[0]) + default: + menuItems := make([]*menuItem, len(confFiles)) + for i, file := range confFiles { + i := i + menuItems[i] = &menuItem{ + displayString: file, + onPress: func() error { + return action(confFiles[i]) + }, + } + } + return gui.createMenu("select config file", menuItems, createMenuOptions{}) + } +} + func (gui *Gui) handleOpenConfig() error { - return gui.openFile(gui.Config.GetUserConfigPath()) + return gui.askForConfigFile(func(file string) error { + return gui.openFile(file) + }) } func (gui *Gui) handleEditConfig() error { - filename := gui.Config.GetUserConfigPath() - return gui.editFile(filename) + return gui.askForConfigFile(func(file string) error { + return gui.editFile(file) + }) } func lazygitTitle() string { |