ronantakizawa/codereview-bench huggingface dataset:
Repository: jesseduffield/lazygit
File: pkg/gui/filetree/commit_file_tree_view_model.go (Go)

Code before:
	self.canRebase = canRebase
}

func (self *CommitFileTreeViewModel) GetSelected() *CommitFileNode {
	if self.Len() == 0 {
		return nil
	}

	return self.Get(self.GetSelectedLineIdx())
}

func (self *CommitFileTreeViewModel) GetSelectedItemId() string {
	item := self.GetSelected()
	if item == nil {
		return ""
	}

	return item.ID()
}

func (self *CommitFileTreeViewModel) GetSelectedItems() ([]*CommitFileNode, int, int) {
	startIdx, endIdx := self.GetSelectionRange()

	nodes := []*CommitFileNode{}
	for i := startIdx; i <= endIdx; i++ {
		nodes = append(nodes, self.Get(i))
	}

	return nodes, startIdx, endIdx
}

func (self *CommitFileTreeViewModel) GetSelectedItemIds() ([]string, int, int) {
	selectedItems, startIdx, endIdx := self.GetSelectedItems()

	ids := lo.Map(selectedItems, func(item *CommitFileNode, _ int) string {
		return item.ID()
	})

	return ids, startIdx, endIdx
}

func (self *CommitFileTreeViewModel) GetSelectedFile() *models.CommitFile {
	node := self.GetSelected()
	if node == nil {
		return nil
	}

	return node.File
}

func (self *CommitFileTreeViewModel) GetSelectedPath() string {

Review comment (suggestion):
Can you add a check at the top of this function which returns `nil, 0, 0` if Len() is 0, like I do in this commit: https://github.com/jesseduffield/lazygit/commit/75d471df04d2333a8f809fd241beb2efa2a54138

Code after:
	self.canRebase = canRebase
}

func (self *CommitFileTreeViewModel) GetSelected() *CommitFileNode {
	if self.Len() == 0 {
		return nil
	}

	return self.Get(self.GetSelectedLineIdx())
}

func (self *CommitFileTreeViewModel) GetSelectedItemId() string {
	item := self.GetSelected()
	if item == nil {
		return ""
	}

	return item.ID()
}

func (self *CommitFileTreeViewModel) GetSelectedItems() ([]*CommitFileNode, int, int) {
	if self.Len() == 0 {
		return nil, 0, 0
	}

	startIdx, endIdx := self.GetSelectionRange()

	nodes := []*CommitFileNode{}
	for i := startIdx; i <= endIdx; i++ {
		nodes = append(nodes, self.Get(i))
	}

	return nodes, startIdx, endIdx
}

func (self *CommitFileTreeViewModel) GetSelectedItemIds() ([]string, int, int) {
	selectedItems, startIdx, endIdx := self.GetSelectedItems()

	ids := lo.Map(selectedItems, func(item *CommitFileNode, _ int) string {
		return item.ID()
	})

	return ids, startIdx, endIdx
}

func (self *CommitFileTreeViewModel) GetSelectedFile() *models.CommitFile {
	node := self.GetSelected()
	if node == nil {
		return nil
	}
Repository: jesseduffield/lazygit
File: pkg/gui/controllers/switch_to_diff_files_controller.go (Go)

Code before:
		Context:   self.context,
	})
}

func (self *SwitchToDiffFilesController) viewFiles(opts SwitchToCommitFilesContextOpts) error {
	diffFilesContext := self.diffFilesContext

	diffFilesContext.SetSelection(0)
	diffFilesContext.SetRef(opts.Ref)
	diffFilesContext.SetTitleRef(opts.Ref.Description())
	diffFilesContext.SetCanRebase(opts.CanRebase)
	diffFilesContext.SetParentContext(opts.Context)
	diffFilesContext.SetWindowName(opts.Context.GetWindowName())
	diffFilesContext.ClearSearchString()
	diffFilesContext.GetView().TitlePrefix = opts.Context.GetView().TitlePrefix

	if err := self.c.Refresh(types.RefreshOptions{
		Scope: []types.RefreshableView{types.COMMIT_FILES},
	}); err != nil {
		return err
	}

	return self.c.PushContext(diffFilesContext)
}

func (self *SwitchToDiffFilesController) itemHasFilesToView(ref types.Ref) *types.DisabledReason {
	if ref.RefName() == "" {
		return &types.DisabledReason{Text: self.c.Tr.SelectedItemDoesNotHaveFiles}
	}

	return nil
}


Review comment (suggestion):
I'd add a comment explaining that if we're dealing with an empty commit, this function won't return a disabled reason. It's instead checking whether the selected item could ever have files. Maybe there's a better function name to make that clear and remove the need for a comment but nothing comes to mind

Code after:
		Context:   self.context,
	})
}

func (self *SwitchToDiffFilesController) viewFiles(opts SwitchToCommitFilesContextOpts) error {
	diffFilesContext := self.diffFilesContext

	diffFilesContext.SetSelection(0)
	diffFilesContext.SetRef(opts.Ref)
	diffFilesContext.SetTitleRef(opts.Ref.Description())
	diffFilesContext.SetCanRebase(opts.CanRebase)
	diffFilesContext.SetParentContext(opts.Context)
	diffFilesContext.SetWindowName(opts.Context.GetWindowName())
	diffFilesContext.ClearSearchString()
	diffFilesContext.GetView().TitlePrefix = opts.Context.GetView().TitlePrefix

	if err := self.c.Refresh(types.RefreshOptions{
		Scope: []types.RefreshableView{types.COMMIT_FILES},
	}); err != nil {
		return err
	}

	return self.c.PushContext(diffFilesContext)
}

func (self *SwitchToDiffFilesController) itemRepresentsCommit(ref types.Ref) *types.DisabledReason {
	if ref.RefName() == "" {
		return &types.DisabledReason{Text: self.c.Tr.SelectedItemDoesNotHaveFiles}
	}

	return nil
}
Repository: jesseduffield/lazygit
File: pkg/gui/controllers/helpers/mode_helper.go (Go)

Code before:
	return []ModeStatus{
		{
			IsActive: self.c.Modes().Diffing.Active,
			Description: func() string {
				return self.withResetButton(
					fmt.Sprintf(
						"%s %s",
						self.c.Tr.ShowingGitDiff,
						"git diff "+strings.Join(self.diffHelper.DiffArgs(), " "),
					),
					style.FgMagenta,
				)
			},
			Reset: self.diffHelper.ExitDiffMode,
		},
		{
			IsActive: self.c.Git().Patch.PatchBuilder.Active,
			Description: func() string {
				return self.withResetButton(self.c.Tr.BuildingPatch, style.FgYellow.SetBold())
			},
			Reset: self.patchBuildingHelper.Reset,
		},
		{
			IsActive: self.c.Modes().Filtering.Active,
			Description: func() string {
				filterContent := ""
				if self.c.Modes().Filtering.GetPath() != "" {
					filterContent = self.c.Modes().Filtering.GetPath()
				} else {
					filterContent = self.c.Modes().Filtering.GetAuthor()
				}
				return self.withResetButton(
					fmt.Sprintf(
						"%s '%s'",
						self.c.Tr.FilteringBy,
						filterContent,
					),
					style.FgRed,
				)
			},
			Reset: self.ExitFilterMode,
		},
		{
			IsActive: self.c.Modes().MarkedBaseCommit.Active,
			Description: func() string {
				return self.withResetButton(
					self.c.Tr.MarkedBaseCommitStatus,
					style.FgCyan,
				)
			},
			Reset: self.mergeAndRebaseHelper.ResetMarkedBaseCommit,

Review comment (security):
Another "wastedassign" linter warning here. Again, you could use `lo.Ternary`, or rewrite the code like this:
```
	filterContent := self.c.Modes().Filtering.GetPath()
	if filterContent == "" {
		filterContent = self.c.Modes().Filtering.GetAuthor()
	}
```

Code after:
	return []ModeStatus{
		{
			IsActive: self.c.Modes().Diffing.Active,
			Description: func() string {
				return self.withResetButton(
					fmt.Sprintf(
						"%s %s",
						self.c.Tr.ShowingGitDiff,
						"git diff "+strings.Join(self.diffHelper.DiffArgs(), " "),
					),
					style.FgMagenta,
				)
			},
			Reset: self.diffHelper.ExitDiffMode,
		},
		{
			IsActive: self.c.Git().Patch.PatchBuilder.Active,
			Description: func() string {
				return self.withResetButton(self.c.Tr.BuildingPatch, style.FgYellow.SetBold())
			},
			Reset: self.patchBuildingHelper.Reset,
		},
		{
			IsActive: self.c.Modes().Filtering.Active,
			Description: func() string {
				filterContent := lo.Ternary(self.c.Modes().Filtering.GetPath() != "", self.c.Modes().Filtering.GetPath(), self.c.Modes().Filtering.GetAuthor())
				return self.withResetButton(
					fmt.Sprintf(
						"%s '%s'",
						self.c.Tr.FilteringBy,
						filterContent,
					),
					style.FgRed,
				)
			},
			Reset: self.ExitFilterMode,
		},
		{
			IsActive: self.c.Modes().MarkedBaseCommit.Active,
			Description: func() string {
				return self.withResetButton(
					self.c.Tr.MarkedBaseCommitStatus,
					style.FgCyan,
				)
			},
			Reset: self.mergeAndRebaseHelper.ResetMarkedBaseCommit,
		},
		{
			IsActive: self.c.Modes().CherryPicking.Active,
			Description: func() string {
				copiedCount := len(self.c.Modes().CherryPicking.CherryPickedCommits)
Repository: jesseduffield/lazygit
File: pkg/integration/tests/filter_by_author/select_author.go (Go)

Code before:
				Contains("commit 3"),
				Contains("commit 2"),
				Contains("commit 1"),
				Contains("commit 0"),
			)

		t.Views().Information().Content(Contains("Filtering by 'Paul Oberstein <paul.oberstein@email.com>'"))

		t.Views().Commits().
			Press(keys.Universal.FilteringMenu)

		t.ExpectPopup().Menu().
			Title(Equals("Filtering")).
			Select(Contains("Stop filtering by author")).
			Confirm()

		t.Views().Commits().
			IsFocused().
			SelectNextItem().
			SelectNextItem().
			SelectNextItem().
			SelectNextItem().
			SelectNextItem().
			SelectNextItem().
			SelectNextItem().
			SelectNextItem().
			Press(keys.Universal.FilteringMenu)

		t.ExpectPopup().Menu().
			Title(Equals("Filtering")).
			Select(Contains("Filter by 'Siegfried Kircheis <siegfried.kircheis@email.com>'")).
			Confirm()

		t.Views().Commits().
			IsFocused().
			Lines(
				Contains("commit 0"),
			)

		t.Views().Information().Content(Contains("Filtering by 'Siegfried Kircheis <siegfried.kircheis@email.com>'"))
	},
})


Review comment (suggestion):
I find it hard to understand which commit ends up being selected after this, so I'd suggest to do
```
NavigateToLine(Contains("SK commit 0")).
```
instead.

Code after:
				Contains("commit 4"),
				Contains("commit 3"),
				Contains("commit 2"),
				Contains("commit 1"),
				Contains("commit 0"),
			)

		t.Views().Information().Content(Contains("Filtering by 'Paul Oberstein <paul.oberstein@email.com>'"))

		t.Views().Commits().
			Press(keys.Universal.FilteringMenu)

		t.ExpectPopup().Menu().
			Title(Equals("Filtering")).
			Select(Contains("Stop filtering")).
			Confirm()

		t.Views().Commits().
			IsFocused().
			NavigateToLine(Contains("SK commit 0")).
			Press(keys.Universal.FilteringMenu)

		t.ExpectPopup().Menu().
			Title(Equals("Filtering")).
			Select(Contains("Filter by 'Siegfried Kircheis <siegfried.kircheis@email.com>'")).
			Confirm()

		t.Views().Commits().
			IsFocused().
			Lines(
				Contains("commit 0"),
			)

		t.Views().Information().Content(Contains("Filtering by 'Siegfried Kircheis <siegfried.kircheis@email.com>'"))
	},
})
Repository: jesseduffield/lazygit
File: pkg/config/user_config_validation.go (Go)

Code before:
package config

import (
	"fmt"
	"slices"
	"strings"
)

func (config *UserConfig) Validate() error {
	if err := validateEnum("gui.statusPanelView", config.Gui.StatusPanelView, []string{"dashboard", "allBranchesLog"}); err != nil {
		return err
	}
	return nil
}

func validateEnum(name string, value string, allowedValues []string) error {
	if slices.Contains(allowedValues, value) {
		return nil
	}
	allowedValuesStr := strings.Join(allowedValues, ", ")
	return fmt.Errorf("unexpectd value '%s' for '%s'. Allowed values: %s", value, name, allowedValuesStr)
}


Review comment (suggestion):
```suggestion
	return fmt.Errorf("Unexpected value '%s' for '%s'. Allowed values: %s", value, name, allowedValuesStr)
```

Code after:
package config

import (
	"fmt"
	"slices"
	"strings"
)

func (config *UserConfig) Validate() error {
	if err := validateEnum("gui.statusPanelView", config.Gui.StatusPanelView, []string{"dashboard", "allBranchesLog"}); err != nil {
		return err
	}
	return nil
}

func validateEnum(name string, value string, allowedValues []string) error {
	if slices.Contains(allowedValues, value) {
		return nil
	}
	allowedValuesStr := strings.Join(allowedValues, ", ")
	return fmt.Errorf("Unexpected value '%s' for '%s'. Allowed values: %s", value, name, allowedValuesStr)
}
Repository: jesseduffield/lazygit
File: pkg/config/user_config_validation.go (Go)

Code before:
package config

import (
	"fmt"
	"slices"
	"strings"
)

func (config *UserConfig) Validate() error {
	if err := validateEnum("gui.statusPanelView", config.Gui.StatusPanelView, []string{"dashboard", "allBranchesLog"}); err != nil {
		return err
	}
	return nil
}

func validateEnum(name string, value string, allowedValues []string) error {
	if slices.Contains(allowedValues, value) {
		return nil
	}
	allowedValuesStr := strings.Join(allowedValues, ", ")
	return fmt.Errorf("Unexpectd value '%s' for '%s'. Allowed values: %s", value, name, allowedValuesStr)
}


Review comment (suggestion):
```suggestion
	return fmt.Errorf("Unexpected value '%s' for '%s'. Allowed values: %s", value, name, allowedValuesStr)
```

There's still an e missing.

Code after:
package config

import (
	"fmt"
	"slices"
	"strings"
)

func (config *UserConfig) Validate() error {
	if err := validateEnum("gui.statusPanelView", config.Gui.StatusPanelView, []string{"dashboard", "allBranchesLog"}); err != nil {
		return err
	}
	return nil
}

func validateEnum(name string, value string, allowedValues []string) error {
	if slices.Contains(allowedValues, value) {
		return nil
	}
	allowedValuesStr := strings.Join(allowedValues, ", ")
	return fmt.Errorf("Unexpected value '%s' for '%s'. Allowed values: %s", value, name, allowedValuesStr)
}
Repository: jesseduffield/lazygit
File: pkg/integration/tests/status/log_cmd.go (Go)

Code before:
package status

import (
	"github.com/jesseduffield/lazygit/pkg/config"
	. "github.com/jesseduffield/lazygit/pkg/integration/components"
)

var LogCmd = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Cycle between two different log commands in the Status view",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
		config.UserConfig.Git.AllBranchesLogCmd = `echo "view1"`
		config.UserConfig.Git.AllBranchesLogCmds = []string{`echo "view2"`}
	},
	SetupRepo: func(shell *Shell) {},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {

		t.Views().Status().
			Focus().
			Press(keys.Status.AllBranchesLogGraph)
		t.Views().Main().Content(Contains("view1"))

		t.Views().Status().
			Focus().
			Press(keys.Status.AllBranchesLogGraph)
		t.Views().Main().Content(Contains("view2"))

		t.Views().Status().
			Focus().
			Press(keys.Status.AllBranchesLogGraph)
		t.Views().Main().Content(Contains("view1"))
	},
})


Review comment (suggestion):
I'd maybe also add the check that it _does not contain view2_ at the same time. Just to be extra sure it's not displaying `view1view2` somehow.

Code after:
package status

import (
	"github.com/jesseduffield/lazygit/pkg/config"
	. "github.com/jesseduffield/lazygit/pkg/integration/components"
)

var LogCmd = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Cycle between two different log commands in the Status view",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
		config.UserConfig.Git.AllBranchesLogCmd = `echo "view1"`
		config.UserConfig.Git.AllBranchesLogCmds = []string{`echo "view2"`}
	},
	SetupRepo: func(shell *Shell) {},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Status().
			Focus().
			Press(keys.Status.AllBranchesLogGraph)
		t.Views().Main().Content(Contains("view1"))

		t.Views().Status().
			Focus().
			Press(keys.Status.AllBranchesLogGraph)
		t.Views().Main().Content(Contains("view2").DoesNotContain("view1"))

		t.Views().Status().
			Focus().
			Press(keys.Status.AllBranchesLogGraph)
		t.Views().Main().Content(Contains("view1").DoesNotContain("view2"))
	},
})
Repository: jesseduffield/lazygit
File: pkg/config/config_linux.go (Go)

Code before:
package config

import (
	"os"
	"strings"
)

func isWSL() bool {
	data, err := os.ReadFile("/proc/sys/kernel/osrelease")
	return err == nil && strings.Contains(string(data), "microsoft")
}

func isContainer() bool {
	data, err := os.ReadFile("/proc/1/cgroup")

	if strings.Contains(string(data), "docker") ||
		strings.Contains(string(data), "/lxc/") ||
		os.Getenv("CONTAINER") != "" {
		return err == nil && true
	}

	return err == nil && false
}

// GetPlatformDefaultConfig gets the defaults for the platform
func GetPlatformDefaultConfig() OSConfig {
	if isWSL() && !isContainer() {
		return OSConfig{
			Open:     `powershell.exe start explorer.exe {{filename}} >/dev/null`,
			OpenLink: `powershell.exe start {{link}} >/dev/null`,
		}
	}

	return OSConfig{
		Open:     `xdg-open {{filename}} >/dev/null`,
		OpenLink: `xdg-open {{link}} >/dev/null`,
	}
}


Review comment (suggestion):
Your change is certainly an improvement, but I find this condition still strange for two reasons: it checks the error only after looking for the strings (which is probably fine in practice, as `data` is likely to be empty when there was an error, but it's still weird), and then the funny `&& true` at the end.

I'd clean it up a bit further to something like
```go
	return err == nil && (strings.Contains(string(data), "docker") ||
		strings.Contains(string(data), "/lxc/") ||
		os.Getenv("CONTAINER") != "")
```

Code after:
package config

import (
	"os"
	"strings"
)

func isWSL() bool {
	data, err := os.ReadFile("/proc/sys/kernel/osrelease")
	return err == nil && strings.Contains(string(data), "microsoft")
}

func isContainer() bool {
	data, err := os.ReadFile("/proc/1/cgroup")
	return err == nil && (strings.Contains(string(data), "docker") ||
		strings.Contains(string(data), "/lxc/") ||
		os.Getenv("CONTAINER") != "")
}

// GetPlatformDefaultConfig gets the defaults for the platform
func GetPlatformDefaultConfig() OSConfig {
	if isWSL() && !isContainer() {
		return OSConfig{
			Open:     `powershell.exe start explorer.exe {{filename}} >/dev/null`,
			OpenLink: `powershell.exe start {{link}} >/dev/null`,
		}
	}

	return OSConfig{
		Open:     `xdg-open {{filename}} >/dev/null`,
		OpenLink: `xdg-open {{link}} >/dev/null`,
	}
}
Repository: jesseduffield/lazygit
File: pkg/config/config_linux.go (Go)

Code before:
package config

import (
	"os"
	"strings"
)

func isWSL() bool {
	data, err := os.ReadFile("/proc/sys/kernel/osrelease")
	return err == nil && strings.Contains(string(data), "microsoft")
}

func isContainer() bool {
	data, err := os.ReadFile("/proc/1/cgroup")
	return err == nil && strings.Contains(string(data), "docker") ||
		strings.Contains(string(data), "/lxc/") ||
		os.Getenv("CONTAINER") != ""
}

// GetPlatformDefaultConfig gets the defaults for the platform
func GetPlatformDefaultConfig() OSConfig {
	if isWSL() && !isContainer() {
		return OSConfig{
			Open:     `powershell.exe start explorer.exe {{filename}} >/dev/null`,
			OpenLink: `powershell.exe start {{link}} >/dev/null`,
		}
	}

	return OSConfig{
		Open:     `xdg-open {{filename}} >/dev/null`,
		OpenLink: `xdg-open {{link}} >/dev/null`,
	}
}


Review comment (suggestion):
That's not quite right. `&&` binds stronger than `||`, so you do need the `()` around the `||` parts of the condition. See my example above.

Code after:
package config

import (
	"os"
	"strings"
)

func isWSL() bool {
	data, err := os.ReadFile("/proc/sys/kernel/osrelease")
	return err == nil && strings.Contains(string(data), "microsoft")
}

func isContainer() bool {
	data, err := os.ReadFile("/proc/1/cgroup")
	return err == nil && (strings.Contains(string(data), "docker") ||
		strings.Contains(string(data), "/lxc/") ||
		os.Getenv("CONTAINER") != "")
}

// GetPlatformDefaultConfig gets the defaults for the platform
func GetPlatformDefaultConfig() OSConfig {
	if isWSL() && !isContainer() {
		return OSConfig{
			Open:     `powershell.exe start explorer.exe {{filename}} >/dev/null`,
			OpenLink: `powershell.exe start {{link}} >/dev/null`,
		}
	}

	return OSConfig{
		Open:     `xdg-open {{filename}} >/dev/null`,
		OpenLink: `xdg-open {{link}} >/dev/null`,
	}
}
Repository: jesseduffield/lazygit
File: pkg/gui/pty.go (Go)

Code before:
		gui.Mutexes.PtyMutex.Unlock()

		return cmd, ptmx
	}

	onClose := func() {
		gui.Mutexes.PtyMutex.Lock()
		ptmx.Close()
		delete(gui.viewPtmxMap, view.Name())
		gui.Mutexes.PtyMutex.Unlock()
	}

	linesToRead := gui.linesToReadFromCmdTask(view)
	if err := manager.NewTask(manager.NewCmdTask(start, prefix, linesToRead, onClose), cmdStr); err != nil {
		return err
	}

	return nil
}

func removeExistingTermEnvVars(env []string) (updatedEnv []string) {
	for _, envVar := range env {
		if !isTermEnvVar(envVar) {
			updatedEnv = append(updatedEnv, envVar)
		}
	}

	return
}

// Terminals set a variety of different environment variables
// to identify themselves to processes. This list should catch the most common among them.
func isTermEnvVar(envVar string) bool {
	return strings.HasPrefix(envVar, "TERM=") ||
		strings.HasPrefix(envVar, "TERM_PROGRAM=") ||
		strings.HasPrefix(envVar, "TERM_PROGRAM_VERSION=") ||
		strings.HasPrefix(envVar, "TERMINAL_EMULATOR=") ||
		strings.HasPrefix(envVar, "TERMINAL_NAME=") ||
		strings.HasPrefix(envVar, "TERMINAL_VERSION_")
}


Review comment (bug):
I'm not a fan of named return values (and if I remember right, @jesseduffield isn't either, but I might be wrong about that). It may just be a matter of personal taste, but I'd have written this as follows:
```go
func removeExistingTermEnvVars(env []string) []string {
	return lo.Filter(env, func(envVar string, _ int) bool {
		return !isTermEnvVar(envVar)
	})
}
```

Code after:
		gui.viewPtmxMap[view.Name()] = ptmx
		gui.Mutexes.PtyMutex.Unlock()

		return cmd, ptmx
	}

	onClose := func() {
		gui.Mutexes.PtyMutex.Lock()
		ptmx.Close()
		delete(gui.viewPtmxMap, view.Name())
		gui.Mutexes.PtyMutex.Unlock()
	}

	linesToRead := gui.linesToReadFromCmdTask(view)
	if err := manager.NewTask(manager.NewCmdTask(start, prefix, linesToRead, onClose), cmdStr); err != nil {
		return err
	}

	return nil
}

func removeExistingTermEnvVars(env []string) []string {
	return lo.Filter(env, func(envVar string, _ int) bool {
		return !isTermEnvVar(envVar)
	})
}

// Terminals set a variety of different environment variables
// to identify themselves to processes. This list should catch the most common among them.
func isTermEnvVar(envVar string) bool {
	return strings.HasPrefix(envVar, "TERM=") ||
		strings.HasPrefix(envVar, "TERM_PROGRAM=") ||
		strings.HasPrefix(envVar, "TERM_PROGRAM_VERSION=") ||
		strings.HasPrefix(envVar, "TERMINAL_EMULATOR=") ||
		strings.HasPrefix(envVar, "TERMINAL_NAME=") ||
		strings.HasPrefix(envVar, "TERMINAL_VERSION_")
}