agent_servers: Honor terminal settings provided shell when fetching shell env (#40243)

Lukas Wirth created

Release Notes:

- N/A *or* Added/Fixed/Improved ...

Change summary

crates/agent_servers/src/acp.rs | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)

Detailed changes

crates/agent_servers/src/acp.rs 🔗

@@ -9,6 +9,7 @@ use futures::io::BufReader;
 use project::Project;
 use project::agent_server_store::AgentServerCommand;
 use serde::Deserialize;
+use settings::{Settings as _, SettingsLocation};
 use task::Shell;
 use util::{ResultExt as _, get_default_system_shell_preferring_bash};
 
@@ -22,7 +23,7 @@ use gpui::{App, AppContext as _, AsyncApp, Entity, SharedString, Task, WeakEntit
 
 use acp_thread::{AcpThread, AuthRequired, LoadError, TerminalProviderEvent};
 use terminal::TerminalBuilder;
-use terminal::terminal_settings::{AlternateScroll, CursorShape};
+use terminal::terminal_settings::{AlternateScroll, CursorShape, TerminalSettings};
 
 #[derive(Debug, Error)]
 #[error("Unsupported version")]
@@ -818,13 +819,25 @@ impl acp::Client for ClientDelegate {
         let mut env = if let Some(dir) = &args.cwd {
             project
                 .update(&mut self.cx.clone(), |project, cx| {
-                    project.directory_environment(&task::Shell::System, dir.clone().into(), cx)
+                    let worktree = project.find_worktree(dir.as_path(), cx);
+                    let shell = TerminalSettings::get(
+                        worktree.as_ref().map(|(worktree, path)| SettingsLocation {
+                            worktree_id: worktree.read(cx).id(),
+                            path: &path,
+                        }),
+                        cx,
+                    )
+                    .shell
+                    .clone();
+                    project.directory_environment(&shell, dir.clone().into(), cx)
                 })?
                 .await
                 .unwrap_or_default()
         } else {
             Default::default()
         };
+        // Disables paging for `git` and hopefully other commands
+        env.insert("PAGER".into(), "".into());
         for var in args.env {
             env.insert(var.name, var.value);
         }