// Package ps provides shell determination by process name
package psimport ()// 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())switchstrings.SplitN(strings.TrimSuffix(, ".exe"), "-", 2)[0] {case"bash":ifisBLE() {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:ifstrings.Contains(, "xonsh-wrapped") { // nix packaged versionreturn"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]; != "" {returnfilepath.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(); {returntrue } }returnfalse}
The pages are generated with Goldsv0.8.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.