package termenv

import (
	
	
	
	

	
	
	
)

var (
	cmdList  = []string{"cmd", "cmd.exe"}
	pwshList = []string{"powershell", "powershell.exe", "pwsh", "pwsh.exe"}
)

// IsTerminal 检查是否为终端设备中
func () bool {
	 := int(os.Stdout.Fd())
	return term.IsTerminal()
}

// CurrentShell get current used shell env file.
//
// eg "/bin/zsh" "/bin/bash".
// if onlyName=true, will return "zsh", "bash"
func ( bool,  ...string) string {
	return comfunc.CurrentShell(, ...)
}

// HasShellEnv has shell env check.
//
// Usage:
//
//	HasShellEnv("sh")
//	HasShellEnv("bash")
func ( string) bool {
	// can also use: "echo $0"
	,  := shellExec("echo OK", )
	if  != nil {
		return false
	}
	return strings.TrimSpace() == "OK"
}

// IsShellSpecialVar reports whether the character identifies a special
// shell variable such as $*.
func ( uint8) bool {
	switch  {
	case '*', '#', '$', '@', '!', '?', '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
		return true
	}
	return false
}

func shellExec(,  string) (string, error) {
	// "-c" for bash,sh,zsh shell
	 := "-c"
	if  == "" {
		 = CurrentShell(true, "sh")
	}

	// special for Windows shell
	if runtime.GOOS == "windows" {
		// use cmd.exe, mark is "/c"
		if checkfn.StringsContains(cmdList, ) {
			 = "/c"
		} else if checkfn.StringsContains(pwshList, ) {
			// "-Command" for powershell
			 = "-Command"
		}
	}

	 := exec.Command(, , )
	,  := .CombinedOutput()
	return string(), 
}