Skip to content

Commit 4851064

Browse files
rburgstejholmes
authored andcommitted
fixes #26: added fish support (#27)
1 parent 3dd666a commit 4851064

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

main.go

+19
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,18 @@ func init() {
3636
}
3737

3838
func defaultFormat() string {
39+
var shell = os.Getenv("SHELL")
40+
3941
switch runtime.GOOS {
4042
case "windows":
4143
if os.Getenv("SHELL") == "" {
4244
return "powershell"
4345
}
4446
fallthrough
4547
default:
48+
if strings.HasSuffix(shell, "fish") {
49+
return "fish"
50+
}
4651
return "bash"
4752
}
4853
}
@@ -94,6 +99,8 @@ func main() {
9499
printPowerShellCredentials(role, creds)
95100
case "bash":
96101
printCredentials(role, creds)
102+
case "fish":
103+
printFishCredentials(role, creds)
97104
default:
98105
flag.Usage()
99106
os.Exit(1)
@@ -132,6 +139,18 @@ func printCredentials(role string, creds *credentials.Value) {
132139
fmt.Printf("# eval $(%s)\n", strings.Join(os.Args, " "))
133140
}
134141

142+
// printFishCredentials prints the credentials in a way that can easily be sourced
143+
// with fish.
144+
func printFishCredentials(role string, creds *credentials.Value) {
145+
fmt.Printf("set -gx AWS_ACCESS_KEY_ID \"%s\";\n", creds.AccessKeyID)
146+
fmt.Printf("set -gx AWS_SECRET_ACCESS_KEY \"%s\";\n", creds.SecretAccessKey)
147+
fmt.Printf("set -gx AWS_SESSION_TOKEN \"%s\";\n", creds.SessionToken)
148+
fmt.Printf("set -gx AWS_SECURITY_TOKEN \"%s\";\n", creds.SessionToken)
149+
fmt.Printf("set -gx ASSUMED_ROLE \"%s\";\n", role)
150+
fmt.Printf("# Run this to configure your shell:\n")
151+
fmt.Printf("# eval (%s)\n", strings.Join(os.Args, " "))
152+
}
153+
135154
// printPowerShellCredentials prints the credentials in a way that can easily be sourced
136155
// with Windows powershell using Invoke-Expression.
137156
func printPowerShellCredentials(role string, creds *credentials.Value) {

0 commit comments

Comments
 (0)