cli/pkg/findsh/find_windows.go
Mislav Marohnić 1ec47d8191 Improvements to gh extensions
- Extensions on Windows now enabled through the `sh.exe` interpreter
- `sh.exe` now found on Windows when git was installed via scoop
- `gh extensions list` command shows origin repo for the extension
- `gh extensions upgrade --all` is required to upgrade all extensions
- Added `gh extensions remove`
- Shell completions now include aliases and extension names
- `gh` help output now lists available extension names
- Extensions are stored to XDG_DATA_HOME
2021-06-21 16:54:08 +02:00

35 lines
696 B
Go

package findsh
import (
"os"
"path/filepath"
"github.com/cli/safeexec"
)
func Find() (string, error) {
shPath, shErr := safeexec.LookPath("sh")
if shErr == nil {
return shPath, nil
}
gitPath, err := safeexec.LookPath("git")
if err != nil {
return "", shErr
}
gitDir := filepath.Dir(gitPath)
// regular Git for Windows install
shPath = filepath.Join(gitDir, "..", "bin", "sh.exe")
if _, err := os.Stat(shPath); err == nil {
return filepath.Clean(shPath), nil
}
// git as a scoop shim
shPath = filepath.Join(gitDir, "..", "apps", "git", "current", "bin", "sh.exe")
if _, err := os.Stat(shPath); err == nil {
return filepath.Clean(shPath), nil
}
return "", shErr
}