Skip to content

Commit

Permalink
fix: don't attempt to display cmd_duration notification if in TTY (#4535
Browse files Browse the repository at this point in the history
)

Disables the display of notifications from cmd_duration on Linux if
none of DISPLAY, WAYLAND_DISPLAY, or MIR_SOCKET are set.
This prevents starship from attempting to create notifications in tty 
environments, which was previously causing hangs.
  • Loading branch information
gabrielvictorcf committed Nov 28, 2022
1 parent c2c2eec commit 0427863
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/modules/cmd_duration.rs
Expand Up @@ -48,13 +48,14 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
}
});

Some(undistract_me(module, &config, elapsed))
Some(undistract_me(module, &config, context, elapsed))
}

#[cfg(not(feature = "notify"))]
fn undistract_me<'a, 'b>(
module: Module<'a>,
_config: &'b CmdDurationConfig,
_context: &'a Context,
_elapsed: u128,
) -> Module<'a> {
module
Expand All @@ -64,12 +65,24 @@ fn undistract_me<'a, 'b>(
fn undistract_me<'a, 'b>(
module: Module<'a>,
config: &'b CmdDurationConfig,
context: &'a Context,
elapsed: u128,
) -> Module<'a> {
use notify_rust::{Notification, Timeout};
use nu_ansi_term::{unstyle, AnsiStrings};

if config.show_notifications && config.min_time_to_notify as u128 <= elapsed {
if cfg!(target_os = "linux") {
let in_graphical_session = ["DISPLAY", "WAYLAND_DISPLAY", "MIR_SOCKET"]
.iter()
.find_map(|&var| context.get_env(var).filter(|val| !val.is_empty()))
.is_some();

if !in_graphical_session {
return module;
};
}

let body = format!(
"Command execution {}",
unstyle(&AnsiStrings(&module.ansi_strings()))
Expand Down

0 comments on commit 0427863

Please sign in to comment.