mirror of
https://github.com/ahmetb/kubectx.git
synced 2025-06-10 16:07:31 +00:00
31 lines
598 B
Go
31 lines
598 B
Go
package cmdutil
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
|
|
"github.com/mattn/go-isatty"
|
|
|
|
"github.com/ahmetb/kubectx/internal/env"
|
|
)
|
|
|
|
// isTerminal determines if given fd is a TTY.
|
|
func isTerminal(fd *os.File) bool {
|
|
return isatty.IsTerminal(fd.Fd())
|
|
}
|
|
|
|
// fzfInstalled determines if fzf(1) is in PATH.
|
|
func fzfInstalled() bool {
|
|
v, _ := exec.LookPath("fzf")
|
|
if v != "" {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
// IsInteractiveMode determines if we can do choosing with fzf.
|
|
func IsInteractiveMode(stdout *os.File) bool {
|
|
v := os.Getenv(env.EnvFZFIgnore)
|
|
return v == "" && isTerminal(stdout) && fzfInstalled()
|
|
}
|