// Package ps provides shell determination by process name
package ps import ( ) // DetermineShell determines shell by parent process name. func () string { , := ps.FindProcess(os.Getpid()) if != nil { return "" } for { if , = ps.FindProcess(.PPid()); != nil || == nil { return "" } := resolveExecutable(.Pid(), .Executable()) switch strings.SplitN(strings.TrimSuffix(, ".exe"), "-", 2)[0] { case "bash": if isBLE() { return "bash-ble" } return "bash" case "cmd": return "cmd-clink" case "elvish": return "elvish" case "fish": return "fish" case "nu": return "nushell" case "oil": return "oil" case "osh": return "oil" case "powershell": return "powershell" case "pwsh": return "powershell" case "tcsh": return "tcsh" case "xonsh": return "xonsh" case "zsh": return "zsh" default: if strings.Contains(, "xonsh-wrapped") { // nix packaged version return "xonsh" } } } } // resolveExecutable returns the binary name for a process. On Termux (Android 10+), // execve is rewritten by termux-exec to run binaries through the system linker // (/system/bin/linker64) to bypass app data exec restrictions, so the kernel comm // shows "linker"/"linker64" instead of the binary name. The real binary path is // recoverable as the first entry of /proc/<pid>/cmdline. func resolveExecutable( int, string) string { switch { case "linker", "linker64": , := os.ReadFile(fmt.Sprintf("/proc/%d/cmdline", )) if != nil { return } if := strings.SplitN(string(), "\x00", 2)[0]; != "" { return filepath.Base() } } return } func isBLE() bool { := []string{ "_bleopt_connect_tty", "_ble_util_fdlist_cloexec", "_ble_util_fd_null", "_ble_util_fd_stderr", "_ble_util_fd_stdin", "_ble_util_fd_stdout", "_ble_util_fdvars_export", "_ble_util_fd_zero", } for , := range { if , := os.LookupEnv(); { return true } } return false }