Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanndickson committed Aug 12, 2024
1 parent f9ba2e9 commit 30daf72
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions completion/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ const (
ShellPowershell string = "powershell"
)

func ShellByName(shell, programName string) Shell {
func ShellByName(shell, programName string) (Shell, error) {
switch shell {
case ShellBash:
return Bash(runtime.GOOS, programName)
return Bash(runtime.GOOS, programName), nil
case ShellFish:
return Fish(runtime.GOOS, programName)
return Fish(runtime.GOOS, programName), nil
case ShellZsh:
return Zsh(runtime.GOOS, programName)
return Zsh(runtime.GOOS, programName), nil
case ShellPowershell:
return Powershell(runtime.GOOS, programName)
return Powershell(runtime.GOOS, programName), nil
default:
return nil
return nil, fmt.Errorf("unsupported shell %q", shell)
}
}

Expand All @@ -49,7 +49,7 @@ func ShellOptions(choice *string) *serpent.Enum {
func DetectUserShell(programName string) (Shell, error) {
// Attempt to get the SHELL environment variable first
if shell := os.Getenv("SHELL"); shell != "" {
return ShellByName(filepath.Base(shell), ""), nil
return ShellByName(filepath.Base(shell), "")
}

// Fallback: Look up the current user and parse /etc/passwd
Expand All @@ -69,7 +69,7 @@ func DetectUserShell(programName string) (Shell, error) {
if strings.HasPrefix(line, currentUser.Username+":") {
parts := strings.Split(line, ":")
if len(parts) > 6 {
return ShellByName(filepath.Base(parts[6]), programName), nil // The shell is typically the 7th field
return ShellByName(filepath.Base(parts[6]), programName) // The shell is typically the 7th field
}
}
}
Expand Down

0 comments on commit 30daf72

Please # to comment.