-
Notifications
You must be signed in to change notification settings - Fork 2k
shell selection for env #1033
shell selection for env #1033
Changes from 7 commits
cba15e8
7585680
e13e2b6
33d8058
6b73567
92f6b45
9aa861e
49686b9
6fe4331
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package commands | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
@@ -33,6 +34,10 @@ import ( | |
"github.com/docker/machine/utils" | ||
) | ||
|
||
var ( | ||
ErrUnknownShell = errors.New("unknown shell") | ||
) | ||
|
||
type machineConfig struct { | ||
machineName string | ||
machineDir string | ||
|
@@ -228,6 +233,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", | ||
|
@@ -644,3 +653,19 @@ func getCertPathInfo(c *cli.Context) libmachine.CertPathInfo { | |
ClientKeyPath: clientKeyPath, | ||
} | ||
} | ||
|
||
func detectShell() (string, error) { | ||
// attempt to get the SHELL env var | ||
shell := filepath.Base(os.Getenv("SHELL")) | ||
// none detected; check for windows env | ||
if shell == "." && os.Getenv("windir") != "" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this check should be:
although also don't rely on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||
log.Printf("On Windows, please specify either cmd or powershell with the --shell flag.\n\n") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might be nice to put cmd, powershell strings in single quotes for readability. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point -- thx! |
||
return "", ErrUnknownShell | ||
} | ||
|
||
if shell == "" { | ||
return "", ErrUnknownShell | ||
} | ||
|
||
return shell, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this wrapped in
filepath.Base
so that we get the value we expect in case SHELL contains something like/usr/bin/zsh
? Just making sure I understand correctly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct -- this is the current behavior today.