remux/src/util.rs

30 lines
670 B
Rust
Raw Normal View History

use std::{
env::var,
process::exit
};
2023-04-06 13:34:32 -04:00
use tmux_interface::{
Session, Sessions,
variables::session::session::SESSION_ALL
};
/// return a Vec of all sessions or None
2023-04-06 13:34:32 -04:00
pub fn get_sessions() -> Option<Vec<Session>> {
let i_sessions = Sessions::get(SESSION_ALL);
if i_sessions.is_err() { return None; }
let sessions = i_sessions.ok();
if sessions.is_none() { return None; }
Some(sessions.unwrap().0)
}
/// show the tmux nest text if env var is not unset
pub fn prevent_nest() {
let tmux = var("TMUX").ok();
if tmux.is_some() && tmux.unwrap() != "" {
2024-02-04 16:07:24 -05:00
println!("Sessions should be nested with care; unset TMUX or use the '-n' flag to allow.");
exit(1);
}
}