fix: 不使用环境变量获取shell

This commit is contained in:
Akizon77
2025-05-25 13:58:23 +08:00
parent 4cd8626d35
commit 26b54ac85d

View File

@@ -13,10 +13,8 @@ import (
) )
func newTerminalImpl() (*terminalImpl, error) { func newTerminalImpl() (*terminalImpl, error) {
// 优先获取用户默认 shell shell := ""
shell := os.Getenv("SHELL") // 从 /etc/passwd 获取
if shell == "" {
// 如果 SHELL 环境变量为空,尝试从 /etc/passwd 获取
user, err := os.UserHomeDir() // 当前用户 user, err := os.UserHomeDir() // 当前用户
if err == nil { if err == nil {
passwd, err := os.ReadFile("/etc/passwd") passwd, err := os.ReadFile("/etc/passwd")
@@ -32,7 +30,6 @@ func newTerminalImpl() (*terminalImpl, error) {
} }
} }
} }
}
// 验证 shell 是否可用 // 验证 shell 是否可用
if shell != "" { if shell != "" {