@@ -27,18 +27,18 @@ const (
27
27
ShellPowershell string = "powershell"
28
28
)
29
29
30
- func ShellByName (shell , programName string ) Shell {
30
+ func ShellByName (shell , programName string ) ( Shell , error ) {
31
31
switch shell {
32
32
case ShellBash :
33
- return Bash (runtime .GOOS , programName )
33
+ return Bash (runtime .GOOS , programName ), nil
34
34
case ShellFish :
35
- return Fish (runtime .GOOS , programName )
35
+ return Fish (runtime .GOOS , programName ), nil
36
36
case ShellZsh :
37
- return Zsh (runtime .GOOS , programName )
37
+ return Zsh (runtime .GOOS , programName ), nil
38
38
case ShellPowershell :
39
- return Powershell (runtime .GOOS , programName )
39
+ return Powershell (runtime .GOOS , programName ), nil
40
40
default :
41
- return nil
41
+ return nil , fmt . Errorf ( "unsupported shell %q" , shell )
42
42
}
43
43
}
44
44
@@ -49,7 +49,7 @@ func ShellOptions(choice *string) *serpent.Enum {
49
49
func DetectUserShell (programName string ) (Shell , error ) {
50
50
// Attempt to get the SHELL environment variable first
51
51
if shell := os .Getenv ("SHELL" ); shell != "" {
52
- return ShellByName (filepath .Base (shell ), "" ), nil
52
+ return ShellByName (filepath .Base (shell ), "" )
53
53
}
54
54
55
55
// Fallback: Look up the current user and parse /etc/passwd
@@ -69,7 +69,7 @@ func DetectUserShell(programName string) (Shell, error) {
69
69
if strings .HasPrefix (line , currentUser .Username + ":" ) {
70
70
parts := strings .Split (line , ":" )
71
71
if len (parts ) > 6 {
72
- return ShellByName (filepath .Base (parts [6 ]), programName ), nil // The shell is typically the 7th field
72
+ return ShellByName (filepath .Base (parts [6 ]), programName ) // The shell is typically the 7th field
73
73
}
74
74
}
75
75
}
0 commit comments