Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop exec on unix in the look subcommand in order to share code with windows #134

Merged
merged 1 commit into from
Apr 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 13 additions & 19 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"path/filepath"
"runtime"
"strings"
"syscall"

"github.com/motemen/ghq/logger"
"github.com/urfave/cli"
Expand Down Expand Up @@ -371,27 +370,22 @@ func doLook(c *cli.Context) error {
case 0:
return fmt.Errorf("No repository found")
case 1:
if runtime.GOOS == "windows" {
cmd := exec.Command(os.Getenv("COMSPEC"))
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Dir = reposFound[0].FullPath
if err := cmd.Start(); err != nil {
return err
}
return cmd.Wait()
}
shell := os.Getenv("SHELL")
if shell == "" {
shell = "/bin/sh"
}
logger.Log("cd", reposFound[0].FullPath)
if err := os.Chdir(reposFound[0].FullPath); err != nil {
return err
if runtime.GOOS == "windows" {
shell = os.Getenv("COMSPEC")
} else {
shell = "/bin/sh"
}
}
env := append(syscall.Environ(), "GHQ_LOOK="+reposFound[0].RelPath)
syscall.Exec(shell, []string{shell}, env)
repo := reposFound[0]
cmd := exec.Command(shell)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Dir = repo.FullPath
cmd.Env = append(os.Environ(), "GHQ_LOOK="+repo.RelPath)
return cmd.Run()
default:
logger.Log("error", "More than one repositories are found; Try more precise name")
for _, repo := range reposFound {
Expand Down