From d9b8fe5587f24ac3d89c02b62df18f6f6769080b Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Tue, 3 Nov 2026 20:23:16 +0100 Subject: [PATCH] Print a reminder of an available update when lazygit exits Users who use lazygit for short sessions, and never leave it idle for a minute, don't get to see the update menu until a week after the update came out. Print a short message to the terminal after lazygit exits, the way gh and npm do. The user is back in the shell at that point, where they can run the command that we show. Do this at most once a day, and not on a day when the user responded to the update menu. The message doesn't count as a response to the menu. If other lazygit instances show the menu, it stays open there, and an idle lazygit can still show it later that day. Co-Authored-By: Claude Opus 5.5 --- pkg/config/app_state.go | 2 + pkg/gui/controllers/helpers/update_helper.go | 55 ++++++++++++++++++++ pkg/gui/gui.go | 4 ++ pkg/i18n/english.go | 10 ++++ pkg/updates/updates.go | 20 +++++++ pkg/updates/updates_test.go | 26 +++++++++ 6 files changed, 117 insertions(+) diff --git a/pkg/config/app_state.go b/pkg/config/app_state.go index 77101a0bb..9a0d9c258 100644 --- a/pkg/config/app_state.go +++ b/pkg/config/app_state.go @@ -263,6 +263,8 @@ type UpdatesState struct { RespondedVersion string // The version that the user doesn't want to be reminded of SkippedVersion string + // When lazygit last printed a reminder after exiting + LastExitMessage int64 // The version that an update installed in place of the executable at // InstalledPath. It takes effect when lazygit is restarted. diff --git a/pkg/gui/controllers/helpers/update_helper.go b/pkg/gui/controllers/helpers/update_helper.go index 508253fd2..69e6b41ee 100644 --- a/pkg/gui/controllers/helpers/update_helper.go +++ b/pkg/gui/controllers/helpers/update_helper.go @@ -156,6 +156,61 @@ func (self *UpdateHelper) Note() string { return "" } +// ExitMessage returns a message about an available update that we print after +// lazygit exits, or "" if no reminder is due. This reaches users who never +// leave lazygit idle, and they are in the shell, where they can update right +// away. +func (self *UpdateHelper) ExitMessage() string { + version := self.updater.ClaimExitMessage() + if version == nil { + return "" + } + + lines := []string{utils.ResolvePlaceholderString( + self.c.Tr.NewVersionAvailable, + map[string]string{ + "newVersion": version.String(), + "currentVersion": self.updater.CurrentVersion().String(), + }, + )} + + installation := self.updater.Installation() + installationInstructions := utils.ResolvePlaceholderString( + self.c.Tr.ExitMessageInstallationInstructions, + map[string]string{"url": constants.Links.InstallationInstructions}, + ) + switch { + case installation.Kind == updates.InstallKindRelease: + if err := self.updater.CheckCanInstall(); err != nil { + lines = append(lines, + utils.ResolvePlaceholderString( + self.c.Tr.UpdateFolderNotWritable, + map[string]string{"folder": filepath.Dir(installation.ExecutablePath)}, + ), + installationInstructions, + ) + } else if key := self.c.UserConfig().Keybinding.Status.CheckForUpdate.String(); key != "" { + lines = append(lines, utils.ResolvePlaceholderString( + self.c.Tr.ExitMessageInstallWithKey, map[string]string{"key": key}, + )) + } + case installation.UpdateCommand() != "": + lines = append(lines, utils.ResolvePlaceholderString( + self.c.Tr.ExitMessageUpdateCommand, map[string]string{"command": installation.UpdateCommand()}, + )) + default: + lines = append(lines, self.c.Tr.ExitMessageCheckPackageManager, installationInstructions) + } + + lines = append(lines, + utils.ResolvePlaceholderString( + self.c.Tr.ExitMessageReleaseNotes, map[string]string{"url": constants.Links.Releases}, + ), + self.c.Tr.TurnOffUpdateReminders, + ) + return strings.Join(lines, "\n") +} + // ShowUpdateMenu shows the menu for the update that the note in the // bottom-right corner tells the user about func (self *UpdateHelper) ShowUpdateMenu() error { diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index f51d3a95e..96a91a953 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -1059,6 +1059,10 @@ func (gui *Gui) RunAndHandleError(startArgs appTypes.StartArgs) error { } } + if message := gui.helpers.Update.ExitMessage(); message != "" { + fmt.Println(message) + } + return nil } diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index c0e750df8..50151dba9 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -292,6 +292,11 @@ type TranslationSet struct { RemindMeTomorrow string SkipThisVersion string TurnOffUpdateReminders string + ExitMessageInstallWithKey string + ExitMessageUpdateCommand string + ExitMessageCheckPackageManager string + ExitMessageInstallationInstructions string + ExitMessageReleaseNotes string IntroPopupMessage string NonReloadableConfigWarningTitle string NonReloadableConfigWarning string @@ -1531,6 +1536,11 @@ func EnglishTranslationSet() *TranslationSet { RemindMeTomorrow: "Remind me tomorrow", SkipThisVersion: "Skip this version", TurnOffUpdateReminders: "To turn off these reminders, set update.method to never in your config file.", + ExitMessageInstallWithKey: "To install it, start lazygit and press {{.key}} in the status panel.", + ExitMessageUpdateCommand: "To update, run: {{.command}}", + ExitMessageCheckPackageManager: "Check whether your package manager has it yet, or install lazygit from our releases.", + ExitMessageInstallationInstructions: "Installation instructions: {{.url}}", + ExitMessageReleaseNotes: "Release notes: {{.url}}", IntroPopupMessage: englishIntroPopupMessage, NonReloadableConfigWarningTitle: "Config changed", NonReloadableConfigWarning: englishNonReloadableConfigWarning, diff --git a/pkg/updates/updates.go b/pkg/updates/updates.go index 936e15183..af8eaa456 100644 --- a/pkg/updates/updates.go +++ b/pkg/updates/updates.go @@ -41,6 +41,8 @@ const ( // responded to the menu for a long time, e.g. because they never leave // lazygit idle. ReminderMenuAtStartup + // Print a message to the terminal after lazygit exits + ReminderExitMessage ) // The part of config.AppConfigurer that the updater needs @@ -269,6 +271,20 @@ func (u *Updater) DueReminder(reminder Reminder) *types.VersionNumber { return u.dueReminder(u.readAppState(), reminder) } +// ClaimExitMessage returns the version to remind the user of in a message +// after lazygit exits, or nil if no reminder is due, and records that we print +// the message. We print it at most once a day. +func (u *Updater) ClaimExitMessage() *types.VersionNumber { + var version *types.VersionNumber + u.updateAppState(func(state *config.AppState) { + version = u.dueReminder(state, ReminderExitMessage) + if version != nil { + state.Updates.LastExitMessage = u.now().Unix() + } + }) + return version +} + func (u *Updater) dueReminder(state *config.AppState, reminder Reminder) *types.VersionNumber { if !u.RemindersEnabled() { return nil @@ -290,6 +306,10 @@ func (u *Updater) dueReminder(state *config.AppState, reminder Reminder) *types. return nil } } + if reminder == ReminderExitMessage && + u.now().Sub(time.Unix(state.Updates.LastExitMessage, 0)) < reminderInterval { + return nil + } return status.AvailableVersion } diff --git a/pkg/updates/updates_test.go b/pkg/updates/updates_test.go index 2f52e744a..de7035db8 100644 --- a/pkg/updates/updates_test.go +++ b/pkg/updates/updates_test.go @@ -351,6 +351,32 @@ func TestIsHandledAfter(t *testing.T) { assert.True(t, updater.IsHandledAfter(shownAt)) } +func TestClaimExitMessage(t *testing.T) { + now := time.Date(2026, 11, 3, 12, 0, 0, 0, time.UTC) + v0670 := &types.VersionNumber{Major: 0, Minor: 67, Patch: 0} + + updater := newTestUpdater(t, nil, "0.66.2", Installation{Kind: InstallKindRelease, ExecutablePath: "/bin/lazygit"}) + updater.now = func() time.Time { return now } + state := updater.appState.(*fakeAppStateStore).state + state.Updates = config.UpdatesState{LatestVersion: "v0.67.0", LatestVersionFoundAt: now.Add(-8 * 24 * time.Hour).Unix()} + + assert.Equal(t, v0670, updater.ClaimExitMessage()) + assert.Nil(t, updater.ClaimExitMessage()) + + // The exit message isn't a response to the menu, so the menu still + // appears + assert.Equal(t, v0670, updater.DueReminder(ReminderMenuWhenIdle)) + assert.Equal(t, v0670, updater.DueReminder(ReminderMenuAtStartup)) + + now = now.Add(25 * time.Hour) + assert.Equal(t, v0670, updater.ClaimExitMessage()) + + // After a response to the menu, there's no exit message for a day + now = now.Add(25 * time.Hour) + updater.RecordResponse(v0670) + assert.Nil(t, updater.ClaimExitMessage()) +} + func TestRemindersAreOffWithUpdateMethodNever(t *testing.T) { updater := newTestUpdater(t, nil, "0.66.2", Installation{Kind: InstallKindRelease, ExecutablePath: "/bin/lazygit"}) updater.appState.(*fakeAppStateStore).state.Updates = config.UpdatesState{LatestVersion: "v0.67.0"}