// SPDX-FileCopyrightText: Copyright The Lima Authors1// SPDX-License-Identifier: Apache-2.023// From https://raw.githubusercontent.com/norouter/norouter/v0.6.5/cmd/norouter/editorcmd/editorcmd.go4/*5Copyright (C) NoRouter authors.67Licensed under the Apache License, Version 2.0 (the "License");8you may not use this file except in compliance with the License.9You may obtain a copy of the License at1011http://www.apache.org/licenses/LICENSE-2.01213Unless required by applicable law or agreed to in writing, software14distributed under the License is distributed on an "AS IS" BASIS,15WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.16See the License for the specific language governing permissions and17limitations under the License.18*/1920package editorcmd2122import (23"os"24"os/exec"25)2627// Detect detects a text editor command.28// Returns an empty string when no editor is found.29func Detect() string {30candidates := []string{31os.Getenv("VISUAL"),32os.Getenv("EDITOR"),33"editor",34"vim",35"vi",36"emacs",37}38for _, f := range candidates {39if f == "" {40continue41}42x, err := exec.LookPath(f)43if err == nil {44return x45}46}47return ""48}495051