mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-03-23 21:51:07 +02:00
small changes
This commit is contained in:
parent
913a2fd065
commit
d02e52989e
@ -265,10 +265,19 @@ os:
|
||||
|
||||
`{{editor}}` in `editCommandTemplate` is replaced with the value of `editCommand`.
|
||||
|
||||
### Change config file used
|
||||
### Overriding default config file location
|
||||
|
||||
- Use `--config-file=~/.base_lg_conf,~/.light_theme_lg_conf` or `$LG_CONFIG_FILE="~/.base_lg_conf,~/.light_theme_lg_conf"`
|
||||
- Change the default config directory `$CONFIG_DIR="~/.config/lazygit"`
|
||||
To override the default config directory, use `$CONFIG_DIR="~/.config/lazygit"`. This directory contains the config file in addition to some other files lazygit uses to keep track of state across sessions.
|
||||
|
||||
To override the individual config file used, use the `--use-config-file` arg or the `LG_CONFIG_FILE` env var.
|
||||
|
||||
If you want to merge a specific config file into a more general config file, perhaps for the sake of setting some theme-specific options, you can supply a list of comma-separated config file paths, like so:
|
||||
|
||||
```sh
|
||||
lazygit --use-config-file=~/.base_lg_conf,~/.light_theme_lg_conf
|
||||
or
|
||||
LG_CONFIG_FILE="~/.base_lg_conf,~/.light_theme_lg_conf" lazygit
|
||||
```
|
||||
|
||||
### Recommended Config Values
|
||||
|
||||
|
2
main.go
2
main.go
@ -62,7 +62,7 @@ func main() {
|
||||
flaggy.String(&gitDir, "g", "git-dir", "equivalent of the --git-dir git argument")
|
||||
|
||||
customConfig := ""
|
||||
flaggy.String(&customConfig, "cf", "config-file", "Comma seperated list to custom config file(s)")
|
||||
flaggy.String(&customConfig, "ucf", "use-config-file", "Comma seperated list to custom config file(s)")
|
||||
|
||||
flaggy.Parse()
|
||||
|
||||
|
@ -57,19 +57,16 @@ func NewAppConfig(name, version, commit, date string, buildSource string, debugg
|
||||
}
|
||||
|
||||
var userConfigFiles []string
|
||||
|
||||
userConfigFilesOverwrite := os.Getenv("LG_CONFIG_FILE")
|
||||
deafultConfFiles := true
|
||||
if userConfigFilesOverwrite != "" {
|
||||
customConfigFiles := os.Getenv("LG_CONFIG_FILE")
|
||||
if customConfigFiles != "" {
|
||||
// Load user defined config files
|
||||
userConfigFiles = strings.Split(userConfigFilesOverwrite, ",")
|
||||
deafultConfFiles = false
|
||||
userConfigFiles = strings.Split(customConfigFiles, ",")
|
||||
} else {
|
||||
// Load default config files
|
||||
userConfigFiles = []string{filepath.Join(configDir, ConfigFilename)}
|
||||
}
|
||||
|
||||
userConfig, err := loadUserConfigWithDefaults(userConfigFiles, deafultConfFiles)
|
||||
userConfig, err := loadUserConfigWithDefaults(userConfigFiles)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -86,25 +83,28 @@ func NewAppConfig(name, version, commit, date string, buildSource string, debugg
|
||||
}
|
||||
|
||||
appConfig := &AppConfig{
|
||||
Name: "lazygit",
|
||||
Version: version,
|
||||
Commit: commit,
|
||||
BuildDate: date,
|
||||
Debug: debuggingFlag,
|
||||
BuildSource: buildSource,
|
||||
UserConfig: userConfig,
|
||||
UserConfigFiles: userConfigFiles,
|
||||
UserConfigDir: configDir,
|
||||
DeafultConfFiles: deafultConfFiles,
|
||||
UserConfigPath: filepath.Join(configDir, "config.yml"),
|
||||
TempDir: tempDir,
|
||||
AppState: appState,
|
||||
IsNewRepo: false,
|
||||
Name: "lazygit",
|
||||
Version: version,
|
||||
Commit: commit,
|
||||
BuildDate: date,
|
||||
Debug: debuggingFlag,
|
||||
BuildSource: buildSource,
|
||||
UserConfig: userConfig,
|
||||
UserConfigFiles: userConfigFiles,
|
||||
UserConfigDir: configDir,
|
||||
UserConfigPath: filepath.Join(configDir, "config.yml"),
|
||||
TempDir: tempDir,
|
||||
AppState: appState,
|
||||
IsNewRepo: false,
|
||||
}
|
||||
|
||||
return appConfig, nil
|
||||
}
|
||||
|
||||
func isCustomConfigFile(path string) bool {
|
||||
return path != filepath.Join(ConfigDir(), ConfigFilename)
|
||||
}
|
||||
|
||||
func ConfigDir() string {
|
||||
legacyConfigDirectory := configDirForVendor("jesseduffield")
|
||||
if _, err := os.Stat(legacyConfigDirectory); !os.IsNotExist(err) {
|
||||
@ -128,37 +128,39 @@ func findOrCreateConfigDir() (string, error) {
|
||||
return folder, os.MkdirAll(folder, 0755)
|
||||
}
|
||||
|
||||
func loadUserConfigWithDefaults(configFiles []string, deafultConfFiles bool) (*UserConfig, error) {
|
||||
return loadUserConfig(configFiles, GetDefaultConfig(), deafultConfFiles)
|
||||
func loadUserConfigWithDefaults(configFiles []string) (*UserConfig, error) {
|
||||
return loadUserConfig(configFiles, GetDefaultConfig())
|
||||
}
|
||||
|
||||
func loadUserConfig(configFiles []string, base *UserConfig, deafultConfFiles bool) (*UserConfig, error) {
|
||||
for _, fileName := range configFiles {
|
||||
content, readConfFileErr := ioutil.ReadFile(fileName)
|
||||
if readConfFileErr != nil {
|
||||
if !deafultConfFiles {
|
||||
return nil, readConfFileErr
|
||||
}
|
||||
|
||||
_, err := os.Stat(fileName)
|
||||
if err == nil {
|
||||
return nil, readConfFileErr
|
||||
}
|
||||
func loadUserConfig(configFiles []string, base *UserConfig) (*UserConfig, error) {
|
||||
for _, path := range configFiles {
|
||||
if _, err := os.Stat(path); err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
return nil, readConfFileErr
|
||||
return nil, err
|
||||
}
|
||||
|
||||
file, err := os.Create(fileName)
|
||||
// if use has supplied their own custom config file path(s), we assume
|
||||
// the files have already been created, so we won't go and create them here.
|
||||
if isCustomConfigFile(path) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
file, err := os.Create(path)
|
||||
if err != nil {
|
||||
if os.IsPermission(err) {
|
||||
// apparently when people have read-only permissions they prefer us to fail silently
|
||||
continue
|
||||
} else {
|
||||
return nil, readConfFileErr
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
file.Close()
|
||||
}
|
||||
|
||||
content, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := yaml.Unmarshal(content, base); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -231,7 +233,7 @@ func (c *AppConfig) GetTempDir() string {
|
||||
}
|
||||
|
||||
func (c *AppConfig) ReloadUserConfig() error {
|
||||
userConfig, err := loadUserConfigWithDefaults(c.UserConfigFiles, c.DeafultConfFiles)
|
||||
userConfig, err := loadUserConfigWithDefaults(c.UserConfigFiles)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -268,7 +270,13 @@ func (c *AppConfig) SaveAppState() error {
|
||||
return err
|
||||
}
|
||||
|
||||
return ioutil.WriteFile(filepath, marshalledAppState, 0644)
|
||||
err = ioutil.WriteFile(filepath, marshalledAppState, 0644)
|
||||
if err != nil && os.IsPermission(err) {
|
||||
// apparently when people have read-only permissions they prefer us to fail silently
|
||||
return nil
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// loadAppState loads recorded AppState from file
|
||||
|
@ -656,11 +656,7 @@ func (gui *Gui) showIntroPopupMessage(done chan struct{}) error {
|
||||
onConfirm := func() error {
|
||||
done <- struct{}{}
|
||||
gui.Config.GetAppState().StartupPopupVersion = StartupPopupVersion
|
||||
err := gui.Config.SaveAppState()
|
||||
if err != nil && os.IsPermission(err) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
return gui.Config.SaveAppState()
|
||||
}
|
||||
|
||||
return gui.ask(askOpts{
|
||||
|
@ -114,11 +114,7 @@ func (gui *Gui) updateRecentRepoList() error {
|
||||
known, recentRepos := newRecentReposList(recentRepos, currentRepo)
|
||||
gui.Config.SetIsNewRepo(known)
|
||||
gui.Config.GetAppState().RecentRepos = recentRepos
|
||||
err = gui.Config.SaveAppState()
|
||||
if err != nil && os.IsPermission(err) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
return gui.Config.SaveAppState()
|
||||
}
|
||||
|
||||
// newRecentReposList returns a new repo list with a new entry but only when it doesn't exist yet
|
||||
|
@ -119,7 +119,7 @@ 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")
|
||||
return errors.New(gui.Tr.NoConfigFileFoundErr)
|
||||
case 1:
|
||||
return action(confFiles[0])
|
||||
default:
|
||||
@ -133,20 +133,16 @@ func (gui *Gui) askForConfigFile(action func(file string) error) error {
|
||||
},
|
||||
}
|
||||
}
|
||||
return gui.createMenu("select config file", menuItems, createMenuOptions{})
|
||||
return gui.createMenu(gui.Tr.SelectConfigFile, menuItems, createMenuOptions{})
|
||||
}
|
||||
}
|
||||
|
||||
func (gui *Gui) handleOpenConfig() error {
|
||||
return gui.askForConfigFile(func(file string) error {
|
||||
return gui.openFile(file)
|
||||
})
|
||||
return gui.askForConfigFile(gui.openFile)
|
||||
}
|
||||
|
||||
func (gui *Gui) handleEditConfig() error {
|
||||
return gui.askForConfigFile(func(file string) error {
|
||||
return gui.editFile(file)
|
||||
})
|
||||
return gui.askForConfigFile(gui.editFile)
|
||||
}
|
||||
|
||||
func lazygitTitle() string {
|
||||
|
@ -427,6 +427,8 @@ type TranslationSet struct {
|
||||
LcSelectBranch string
|
||||
CreatePullRequest string
|
||||
CreatingPullRequestAtUrl string
|
||||
SelectConfigFile string
|
||||
NoConfigFileFoundErr string
|
||||
Spans Spans
|
||||
}
|
||||
|
||||
@ -947,6 +949,8 @@ func englishTranslationSet() TranslationSet {
|
||||
LcDefaultBranch: "default branch",
|
||||
LcSelectBranch: "select branch",
|
||||
CreatingPullRequestAtUrl: "Creating pull request at URL: %s",
|
||||
SelectConfigFile: "Select config file",
|
||||
NoConfigFileFoundErr: "No config file found",
|
||||
Spans: Spans{
|
||||
// TODO: combine this with the original keybinding descriptions (those are all in lowercase atm)
|
||||
CheckoutCommit: "Checkout commit",
|
||||
|
@ -76,11 +76,7 @@ func (u *Updater) getLatestVersionNumber() (string, error) {
|
||||
// RecordLastUpdateCheck records last time an update check was performed
|
||||
func (u *Updater) RecordLastUpdateCheck() error {
|
||||
u.Config.GetAppState().LastUpdateCheck = time.Now().Unix()
|
||||
err := u.Config.SaveAppState()
|
||||
if err != nil && os.IsPermission(err) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
return u.Config.SaveAppState()
|
||||
}
|
||||
|
||||
// expecting version to be of the form `v12.34.56`
|
||||
|
Loading…
x
Reference in New Issue
Block a user