diff --git a/cmd/gh/main.go b/cmd/gh/main.go index 2e9614a79..05c2f27bc 100644 --- a/cmd/gh/main.go +++ b/cmd/gh/main.go @@ -6,6 +6,7 @@ import ( "io" "net" "os" + "os/exec" "path" "strings" @@ -49,7 +50,11 @@ func main() { if isShell { err = command.ExecuteShellAlias(expandedArgs) if err != nil { - fmt.Fprintf(stderr, "failed to run alias %q: %s\n", expandedArgs, err) + if ee, ok := err.(*exec.ExitError); ok { + os.Exit(ee.ExitCode()) + } + + fmt.Fprintf(stderr, "failed to run external command: %s", err) os.Exit(3) } diff --git a/command/root.go b/command/root.go index 2b3aa6a4d..ddd4d9834 100644 --- a/command/root.go +++ b/command/root.go @@ -374,12 +374,7 @@ func ExecuteShellAlias(args []string) error { externalCmd.Stdin = os.Stdin preparedCmd := run.PrepareCmd(externalCmd) - err := preparedCmd.Run() - if err != nil { - return fmt.Errorf("failed to run external command: %w", err) - } - - return nil + return preparedCmd.Run() } func findSh() (string, error) {