github.com/andrewhsu/cli/v2@v2.0.1-0.20210910131313-d4b4061f5b89/pkg/findsh/find_windows.go (about)

     1  package findsh
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  
     7  	"github.com/cli/safeexec"
     8  )
     9  
    10  func Find() (string, error) {
    11  	shPath, shErr := safeexec.LookPath("sh")
    12  	if shErr == nil {
    13  		return shPath, nil
    14  	}
    15  
    16  	gitPath, err := safeexec.LookPath("git")
    17  	if err != nil {
    18  		return "", shErr
    19  	}
    20  	gitDir := filepath.Dir(gitPath)
    21  
    22  	// regular Git for Windows install
    23  	shPath = filepath.Join(gitDir, "..", "bin", "sh.exe")
    24  	if _, err := os.Stat(shPath); err == nil {
    25  		return filepath.Clean(shPath), nil
    26  	}
    27  
    28  	// git as a scoop shim
    29  	shPath = filepath.Join(gitDir, "..", "apps", "git", "current", "bin", "sh.exe")
    30  	if _, err := os.Stat(shPath); err == nil {
    31  		return filepath.Clean(shPath), nil
    32  	}
    33  
    34  	return "", shErr
    35  }