use std::env;
use std::process;
pub fn get_session_id() -> String {
let shell_pid = env::var("PPID").unwrap_or_else(|_| "unknown".to_string());
let _term_id = env::var("WINDOWID")
.or_else(|_| env::var("TERM_SESSION_ID"))
.or_else(|_| env::var("TMUX_PANE"))
.unwrap_or_else(|_| "default".to_string());
let tty_info = if let Ok(output) = process::Command::new("tty").output() {
let tty = String::from_utf8_lossy(&output.stdout).trim().to_string();
if !tty.is_empty() && tty != "not a tty" {
tty.replace("/dev/", "").replace("/", "_")
} else {
env::var("BASH_SUBSHELL")
.or_else(|_| env::var("SHLVL"))
.unwrap_or_else(|_| "fallback".to_string())
}
} else {
"no_tty".to_string()
};
format!("session_{}_{}", shell_pid, tty_info)
.chars()
.filter(|c| c.is_alphanumeric() || *c == '_')
.collect()
}