From fc7a3b0824bf007345fd6fa04fe0f957d07ba898 Mon Sep 17 00:00:00 2001 From: Dongdong Zhou Date: Mon, 21 Mar 2022 20:51:49 +0000 Subject: [PATCH] Add support to set terminal shell --- Cargo.lock | 9 +++++---- defaults/settings.toml | 1 + lapce-data/src/config.rs | 2 ++ lapce-data/src/proxy.rs | 2 ++ lapce-data/src/terminal.rs | 4 +++- lapce-proxy/Cargo.toml | 1 + lapce-proxy/src/dispatch.rs | 9 +++++++-- lapce-proxy/src/terminal.rs | 17 ++++++++++++----- lapce-ui/src/settings.rs | 5 +---- lapce-ui/src/split.rs | 2 ++ 10 files changed, 36 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 797a424a..ac92e6f8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2103,6 +2103,7 @@ dependencies = [ "toml", "wasmer", "wasmer-wasi", + "which", "xi-rope", ] @@ -2212,9 +2213,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.101" +version = "0.2.121" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cb00336871be5ed2c8ed44b60ae9959dc5b9f08539422ed43f09e34ecaeba21" +checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f" [[package]] name = "libgit2-sys" @@ -5384,9 +5385,9 @@ dependencies = [ [[package]] name = "which" -version = "4.2.2" +version = "4.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea187a8ef279bc014ec368c27a920da2024d2a711109bfbe3440585d5cf27ad9" +checksum = "5c4fb54e6113b6a8772ee41c3404fb0301ac79604489467e0a9ce1f3e97c24ae" dependencies = [ "either", "lazy_static", diff --git a/defaults/settings.toml b/defaults/settings.toml index 64f46b07..b92209b0 100644 --- a/defaults/settings.toml +++ b/defaults/settings.toml @@ -2,6 +2,7 @@ modal = false color-theme = "Lapce Dark" icon-theme = "" +terminal-shell = "" [editor] font-family = "Cascadia Code" diff --git a/lapce-data/src/config.rs b/lapce-data/src/config.rs index 50368408..e3bc33f2 100644 --- a/lapce-data/src/config.rs +++ b/lapce-data/src/config.rs @@ -102,6 +102,8 @@ pub struct LapceConfig { pub modal: bool, #[field_names(desc = "Set the color theme of Lapce")] pub color_theme: String, + #[field_names(desc = "Set the terminal Shell")] + pub terminal_shell: String, } #[derive(FieldNames, Debug, Clone, Deserialize, Serialize, Default)] diff --git a/lapce-data/src/proxy.rs b/lapce-data/src/proxy.rs index 68eaba3a..60009a0e 100644 --- a/lapce-data/src/proxy.rs +++ b/lapce-data/src/proxy.rs @@ -370,6 +370,7 @@ pub fn new_terminal( &self, term_id: TermId, cwd: Option, + shell: String, raw: Arc>, ) { let _ = self.term_tx.send((term_id, TermEvent::NewTerminal(raw))); @@ -378,6 +379,7 @@ pub fn new_terminal( &json!({ "term_id": term_id, "cwd": cwd, + "shell": shell, }), ) } diff --git a/lapce-data/src/terminal.rs b/lapce-data/src/terminal.rs index c5d32cfd..f60648a4 100644 --- a/lapce-data/src/terminal.rs +++ b/lapce-data/src/terminal.rs @@ -491,6 +491,7 @@ pub fn new( split_id: WidgetId, event_sink: ExtEventSink, proxy: Arc, + config: &Config, ) -> Self { let cwd = workspace.path.as_ref().cloned(); let widget_id = WidgetId::next(); @@ -504,8 +505,9 @@ pub fn new( let local_proxy = proxy.clone(); let local_raw = raw.clone(); + let shell = config.lapce.terminal_shell.clone(); std::thread::spawn(move || { - local_proxy.new_terminal(term_id, cwd, local_raw); + local_proxy.new_terminal(term_id, cwd, shell, local_raw); }); Self { diff --git a/lapce-proxy/Cargo.toml b/lapce-proxy/Cargo.toml index ccfaa584..c42317d9 100644 --- a/lapce-proxy/Cargo.toml +++ b/lapce-proxy/Cargo.toml @@ -5,6 +5,7 @@ authors = ["Dongdong Zhou "] edition = "2021" [dependencies] +which = "4.2.5" regex = "1.5.4" grep-searcher = "0.1.8" grep-matcher = "0.1.5" diff --git a/lapce-proxy/src/dispatch.rs b/lapce-proxy/src/dispatch.rs index 6e4a9fce..779dcd4d 100644 --- a/lapce-proxy/src/dispatch.rs +++ b/lapce-proxy/src/dispatch.rs @@ -128,6 +128,7 @@ pub enum Notification { NewTerminal { term_id: TermId, cwd: Option, + shell: String, }, InstallPlugin { plugin: PluginDescription, @@ -532,8 +533,12 @@ fn handle_notification(&self, rpc: Notification) { ); }); } - Notification::NewTerminal { term_id, cwd } => { - let mut terminal = Terminal::new(term_id, cwd, 50, 10); + Notification::NewTerminal { + term_id, + cwd, + shell, + } => { + let mut terminal = Terminal::new(term_id, cwd, shell, 50, 10); let tx = terminal.tx.clone(); self.terminals.lock().insert(term_id, tx); let dispatcher = self.clone(); diff --git a/lapce-proxy/src/terminal.rs b/lapce-proxy/src/terminal.rs index 2f066f58..615424ad 100644 --- a/lapce-proxy/src/terminal.rs +++ b/lapce-proxy/src/terminal.rs @@ -69,6 +69,7 @@ impl Terminal { pub fn new( term_id: TermId, cwd: Option, + shell: String, width: usize, height: usize, ) -> Terminal { @@ -76,11 +77,17 @@ pub fn new( let mut config = TermConfig::default(); config.pty_config.working_directory = cwd.or_else(|| BaseDirs::new().map(|d| PathBuf::from(d.home_dir()))); - config.pty_config.shell = - std::env::var("SHELL").ok().map(|shell| Program::WithArgs { - program: shell, - args: vec!["-l".to_string()], - }); + let shell = shell.trim(); + if !shell.is_empty() { + let mut parts = shell.split(' '); + let program = parts.next().unwrap(); + if let Ok(p) = which::which(program) { + config.pty_config.shell = Some(Program::WithArgs { + program: p.to_str().unwrap().to_string(), + args: parts.map(|p| p.to_string()).collect::>(), + }) + } + } setup_env(&config); #[cfg(target_os = "macos")] diff --git a/lapce-ui/src/settings.rs b/lapce-ui/src/settings.rs index b35147be..a3a43073 100644 --- a/lapce-ui/src/settings.rs +++ b/lapce-ui/src/settings.rs @@ -199,9 +199,7 @@ fn update( env: &Env, ) { if data.settings.shown { - for child in self.children.iter_mut() { - child.update(ctx, data, env); - } + self.children[self.active].update(ctx, data, env); } } @@ -431,7 +429,6 @@ pub fn new( } fn update_children(&mut self, ctx: &mut EventCtx, data: &mut LapceTabData) { - println!("update settings children"); self.children.clear(); let (kind, fileds, descs, settings) = match self.kind { diff --git a/lapce-ui/src/split.rs b/lapce-ui/src/split.rs index 51c98432..8f42904e 100644 --- a/lapce-ui/src/split.rs +++ b/lapce-ui/src/split.rs @@ -493,6 +493,7 @@ pub fn split_terminal( self.split_id, ctx.get_external_handle(), data.proxy.clone(), + &data.config, )); let terminal = LapceTerminalView::new(&terminal_data); Arc::make_mut(&mut data.terminal) @@ -896,6 +897,7 @@ fn event( data.terminal.split_id, ctx.get_external_handle(), data.proxy.clone(), + &data.config, )); let terminal = LapceTerminalView::new(&terminal_data); self.insert_flex_child(