Skip to content

Commit

Permalink
fixes remind101#26: added fish support (remind101#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
rburgst authored and ejholmes committed Nov 27, 2017
1 parent 3dd666a commit 4851064
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,18 @@ func init() {
}

func defaultFormat() string {
var shell = os.Getenv("SHELL")

switch runtime.GOOS {
case "windows":
if os.Getenv("SHELL") == "" {
return "powershell"
}
fallthrough
default:
if strings.HasSuffix(shell, "fish") {
return "fish"
}
return "bash"
}
}
Expand Down Expand Up @@ -94,6 +99,8 @@ func main() {
printPowerShellCredentials(role, creds)
case "bash":
printCredentials(role, creds)
case "fish":
printFishCredentials(role, creds)
default:
flag.Usage()
os.Exit(1)
Expand Down Expand Up @@ -132,6 +139,18 @@ func printCredentials(role string, creds *credentials.Value) {
fmt.Printf("# eval $(%s)\n", strings.Join(os.Args, " "))
}

// printFishCredentials prints the credentials in a way that can easily be sourced
// with fish.
func printFishCredentials(role string, creds *credentials.Value) {
fmt.Printf("set -gx AWS_ACCESS_KEY_ID \"%s\";\n", creds.AccessKeyID)
fmt.Printf("set -gx AWS_SECRET_ACCESS_KEY \"%s\";\n", creds.SecretAccessKey)
fmt.Printf("set -gx AWS_SESSION_TOKEN \"%s\";\n", creds.SessionToken)
fmt.Printf("set -gx AWS_SECURITY_TOKEN \"%s\";\n", creds.SessionToken)
fmt.Printf("set -gx ASSUMED_ROLE \"%s\";\n", role)
fmt.Printf("# Run this to configure your shell:\n")
fmt.Printf("# eval (%s)\n", strings.Join(os.Args, " "))
}

// printPowerShellCredentials prints the credentials in a way that can easily be sourced
// with Windows powershell using Invoke-Expression.
func printPowerShellCredentials(role string, creds *credentials.Value) {
Expand Down

0 comments on commit 4851064

Please sign in to comment.