1package cmdutil
2
3import (
4	"fmt"
5	"os"
6
7	"github.com/cli/cli/v2/internal/config"
8)
9
10// TODO: consider passing via Factory
11// TODO: support per-hostname settings
12func DetermineEditor(cf func() (config.Config, error)) (string, error) {
13	editorCommand := os.Getenv("GH_EDITOR")
14	if editorCommand == "" {
15		cfg, err := cf()
16		if err != nil {
17			return "", fmt.Errorf("could not read config: %w", err)
18		}
19		editorCommand, _ = cfg.Get("", "editor")
20	}
21
22	return editorCommand, nil
23}
24