diff --git a/commands/commands.go b/commands/commands.go index 1efb9daac1..568afcc546 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -228,6 +228,10 @@ var Commands = []cli.Command{ Name: "swarm", Usage: "Display the Swarm config instead of the Docker daemon", }, + cli.StringFlag{ + Name: "shell", + Usage: "Force environment to be configured for specified shell", + }, cli.BoolFlag{ Name: "unset, u", Usage: "Unset variables instead of setting them", diff --git a/commands/env.go b/commands/env.go index 2e688be2db..e751a13a50 100644 --- a/commands/env.go +++ b/commands/env.go @@ -14,7 +14,10 @@ import ( ) func cmdEnv(c *cli.Context) { - userShell := filepath.Base(os.Getenv("SHELL")) + userShell := c.String("shell") + if userShell == "" { + userShell = filepath.Base(os.Getenv("SHELL")) + } if c.Bool("unset") { switch userShell { case "fish": @@ -89,6 +92,9 @@ func cmdEnv(c *cli.Context) { case "fish": fmt.Printf("set -x DOCKER_TLS_VERIFY 1;\nset -x DOCKER_CERT_PATH %q;\nset -x DOCKER_HOST %s;\n\n%s\n", cfg.machineDir, dockerHost, usageHint) + case "powershell": + fmt.Printf("$env:DOCKER_TLS_VERIFY=1\n$env:DOCKER_CERT_PATH=\"%s\"\n$env:DOCKER_HOST=\"%s\"\n\n%s\n", + cfg.machineDir, dockerHost, usageHint) default: fmt.Printf("export DOCKER_TLS_VERIFY=1\nexport DOCKER_CERT_PATH=%q\nexport DOCKER_HOST=%s\n\n%s\n", cfg.machineDir, dockerHost, usageHint) @@ -98,6 +104,12 @@ func cmdEnv(c *cli.Context) { func generateUsageHint(machineName string, userShell string) string { cmd := "" switch userShell { + case "powershell": + if machineName != "" { + cmd = fmt.Sprintf("Param(docker-machine env %s)", machineName) + } else { + cmd = "Param(docker-machine env)" + } case "fish": if machineName != "" { cmd = fmt.Sprintf("eval (docker-machine env %s)", machineName) diff --git a/ssh/keys.go b/ssh/keys.go index 636a684b4b..ce815fcbce 100644 --- a/ssh/keys.go +++ b/ssh/keys.go @@ -12,6 +12,7 @@ import ( "io" "os" "runtime" + "syscall" gossh "golang.org/x/crypto/ssh" ) @@ -82,7 +83,9 @@ func (kp *KeyPair) WriteToFile(privateKeyPath string, publicKeyPath string) erro // windows does not support chmod switch runtime.GOOS { - case "darwin", "linux": + case "windows": + syscall.Chmod(f.Name(), 0600) + default: if err := f.Chmod(0600); err != nil { return err }