diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-05-20 00:29:53 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-05-20 00:34:27 +0300 |
| commit | 2b97799b6715fd6c355db9c225029765971915e6 (patch) | |
| tree | cb7c2c7093f439ad3460687b88c3e6cf539b64e8 /src/pane.rs | |
| parent | ff8e5a14abe445a61dc200fd30a70870c75d183c (diff) | |
feat: add configurable default shell
refs #196
Diffstat (limited to 'src/pane.rs')
| -rw-r--r-- | src/pane.rs | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/src/pane.rs b/src/pane.rs index aba31943..10112f0f 100644 --- a/src/pane.rs +++ b/src/pane.rs @@ -250,6 +250,22 @@ fn shutdown_pane_processes(pane_id: PaneId, child_pid: u32) { ); } +fn pane_shell(configured_shell: &str) -> String { + pane_shell_from(configured_shell, std::env::var("SHELL").ok()) +} + +fn pane_shell_from(configured_shell: &str, env_shell: Option<String>) -> String { + let configured_shell = configured_shell.trim(); + if !configured_shell.is_empty() { + return configured_shell.to_string(); + } + + env_shell + .map(|shell| shell.trim().to_string()) + .filter(|shell| !shell.is_empty()) + .unwrap_or_else(|| "/bin/sh".into()) +} + impl PaneRuntime { pub fn shutdown(self) { self.detect_handle.abort(); @@ -267,11 +283,12 @@ impl PaneRuntime { cwd: std::path::PathBuf, scrollback_limit_bytes: usize, host_terminal_theme: crate::terminal_theme::TerminalTheme, + default_shell: &str, events: mpsc::Sender<AppEvent>, render_notify: Arc<Notify>, render_dirty: Arc<AtomicBool>, ) -> std::io::Result<Self> { - let shell = std::env::var("SHELL").unwrap_or_else(|_| "/bin/sh".into()); + let shell = pane_shell(default_shell); let mut cmd = CommandBuilder::new(&shell); cmd.cwd(cwd); cmd.env(crate::HERDR_ENV_VAR, crate::HERDR_ENV_VALUE); @@ -1100,6 +1117,28 @@ mod tests { } #[test] + fn pane_shell_prefers_configured_shell() { + assert_eq!( + pane_shell_from("/usr/bin/nu", Some("/bin/bash".to_string())), + "/usr/bin/nu" + ); + } + + #[test] + fn pane_shell_falls_back_to_shell_env() { + assert_eq!( + pane_shell_from("", Some("/bin/bash".to_string())), + "/bin/bash" + ); + } + + #[test] + fn pane_shell_ignores_empty_values() { + assert_eq!(pane_shell_from(" ", Some(" ".to_string())), "/bin/sh"); + assert_eq!(pane_shell_from("", None), "/bin/sh"); + } + + #[test] fn pane_terminal_identity_overrides_outer_terminal_env() { let output = capture_shell_output("printf '%s\\n%s\\n' \"$TERM\" \"$COLORTERM\"", &[]); assert_eq!(output, "xterm-256color\ntruecolor\n"); |
