diff --git a/config/src/config.rs b/config/src/config.rs index be7069d2d..02ed12b33 100644 --- a/config/src/config.rs +++ b/config/src/config.rs @@ -128,6 +128,9 @@ pub struct Config { #[serde(default)] pub exit_behavior: ExitBehavior, + #[serde(default = "default_clean_exits")] + pub clean_exit_codes: Vec, + /// Specifies a map of environment variables that should be set /// when spawning commands in the local domain. /// This is not used when working with remote domains. @@ -1270,6 +1273,10 @@ fn default_prefer_egl() -> bool { !cfg!(windows) } +fn default_clean_exits() -> Vec { + vec![] +} + fn default_inactive_pane_hsb() -> HsbTransform { HsbTransform { brightness: 0.8, diff --git a/docs/changelog.md b/docs/changelog.md index 228a2cf8d..b591ca334 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -20,6 +20,7 @@ As features stabilize some brief notes about them will accumulate here. * Specifying a domain name in a [SpawnCommand](config/lua/SpawnCommand.md) will cause that domain to be attached if it is in the detached state. This is useful when combined with [SwitchToWorkspace](config/lua/keyassignment/SwitchToWorkspace.md). * X11: wezterm now sets `_NET_WM_NAME` in addition to `WM_NAME` for clients that don't know how to fallback * [treat_east_asian_ambiguous_width_as_wide](config/lua/config/treat_east_asian_ambiguous_width_as_wide.md) for control how ambiguous width characters are resolved. [#1888](https://github.com/wez/wezterm/issues/1888) +* [clean_exit_codes](config/lua/config/clean_exit_codes.md) config to fine tune [exit_behavior](config/lua/config/exit_behavior.md) [#1889](https://github.com/wez/wezterm/issues/1889) #### Changed * Debian packages now register wezterm as an alternative for `x-terminal-emulator`. Thanks to [@xpufx](https://github.com/xpufx)! [#1883](https://github.com/wez/wezterm/pull/1883) diff --git a/docs/config/lua/config/clean_exit_codes.md b/docs/config/lua/config/clean_exit_codes.md new file mode 100644 index 000000000..38c58e0ce --- /dev/null +++ b/docs/config/lua/config/clean_exit_codes.md @@ -0,0 +1,21 @@ +## `clean_exit_codes = { 0 }` + +*Since: nightly builds only* + +Defines the set of exit codes that are considered to be a "clean" exit by +[exit_behavior](exit_behavior.md) when the program running in the terminal +completes. + +Acceptable values are an array of integer exit codes that you wish to treat +as successful. + +For example, if you often `CTRL-C` a program and then `CTRL-D`, bash will +typically exit with status `130` to indicate that a program was terminated +with SIGINT, but that bash itself wasn't. In that situation you may wish +to set this config to treat `130` as OK: + +```lua +return { + clean_exit_codes = {130}, +} +``` diff --git a/docs/config/lua/config/exit_behavior.md b/docs/config/lua/config/exit_behavior.md index eb116e905..25a0cefd6 100644 --- a/docs/config/lua/config/exit_behavior.md +++ b/docs/config/lua/config/exit_behavior.md @@ -30,3 +30,5 @@ exit With the default `exit_behavior="CloseOnCleanExit"` setting, that will cause the pane to remain open. +See also: [clean_exit_codes](clean_exit_codes.md) for fine tuning what is +considered to be a clean exit status. diff --git a/mux/src/localpane.rs b/mux/src/localpane.rs index f9afb094d..aaaadf851 100644 --- a/mux/src/localpane.rs +++ b/mux/src/localpane.rs @@ -159,8 +159,16 @@ impl Pane for LocalPane { Err(TryRecvError::Empty) => None, _ => Some(ExitStatus::with_exit_code(1)), }; + if let Some(status) = status { - match (configuration().exit_behavior, status.success(), killed) { + let success = match status.success() { + true => true, + false => configuration() + .clean_exit_codes + .contains(&status.exit_code()), + }; + + match (configuration().exit_behavior, success, killed) { (ExitBehavior::Close, _, _) => *proc = ProcessState::Dead, (ExitBehavior::CloseOnCleanExit, false, false) => { notify = Some(format!( diff --git a/pty/src/lib.rs b/pty/src/lib.rs index b46cfe493..207811a43 100644 --- a/pty/src/lib.rs +++ b/pty/src/lib.rs @@ -181,6 +181,11 @@ impl ExitStatus { Some(_) => false, } } + + /// Returns the exit code that this ExitStatus was constructed with + pub fn exit_code(&self) -> u32 { + self.code + } } impl From for ExitStatus {