@@ -36,13 +36,18 @@ func init() {
36
36
}
37
37
38
38
func defaultFormat () string {
39
+ var shell = os .Getenv ("SHELL" )
40
+
39
41
switch runtime .GOOS {
40
42
case "windows" :
41
43
if os .Getenv ("SHELL" ) == "" {
42
44
return "powershell"
43
45
}
44
46
fallthrough
45
47
default :
48
+ if strings .HasSuffix (shell , "fish" ) {
49
+ return "fish"
50
+ }
46
51
return "bash"
47
52
}
48
53
}
@@ -94,6 +99,8 @@ func main() {
94
99
printPowerShellCredentials (role , creds )
95
100
case "bash" :
96
101
printCredentials (role , creds )
102
+ case "fish" :
103
+ printFishCredentials (role , creds )
97
104
default :
98
105
flag .Usage ()
99
106
os .Exit (1 )
@@ -132,6 +139,18 @@ func printCredentials(role string, creds *credentials.Value) {
132
139
fmt .Printf ("# eval $(%s)\n " , strings .Join (os .Args , " " ))
133
140
}
134
141
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
+
135
154
// printPowerShellCredentials prints the credentials in a way that can easily be sourced
136
155
// with Windows powershell using Invoke-Expression.
137
156
func printPowerShellCredentials (role string , creds * credentials.Value ) {
0 commit comments