From d49727ff100d8a518cf5c245eb88d9429729c817 Mon Sep 17 00:00:00 2001 From: Donough Liu Date: Fri, 12 Jul 2024 01:48:46 +0800 Subject: [PATCH] terminal: Set `TERM_PROGRAM` and `TERM_PROGRAM_VERSION` environment variables in integrated terminal (#14213) ![image](https://github.com/zed-industries/zed/assets/31354274/9d1c5410-897b-40a1-8256-2d7e207f69ff) These two environment variables are essential when people need to detect terminal type and do something. Many popular terminals set them. fixes https://github.com/zed-industries/zed/issues/4571 Release Notes: - Set `TERM_PROGRAM` and `TERM_PROGRAM_VERSION` environment variables in the integrated terminal ([#4571](https://github.com/zed-industries/zed/issues/4571)). --- Cargo.lock | 1 + crates/project/src/terminals.rs | 1 + crates/terminal/Cargo.toml | 3 ++- crates/terminal/src/terminal.rs | 6 ++++++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index e99a440e6b28fe1f1fbcffb83991ebd7a56f13a9..2406785e670118b7febe7c151a7e2037420dbee9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10737,6 +10737,7 @@ dependencies = [ "gpui", "libc", "rand 0.8.5", + "release_channel", "schemars", "serde", "serde_derive", diff --git a/crates/project/src/terminals.rs b/crates/project/src/terminals.rs index 91851b80b34bb2783990e21b92671f28a3c31cdb..40423c26f741d75bb40d5076b20d088a9f8b7b2f 100644 --- a/crates/project/src/terminals.rs +++ b/crates/project/src/terminals.rs @@ -180,6 +180,7 @@ impl Project { settings.max_scroll_history_lines, window, completion_tx, + cx, ) .map(|builder| { let terminal_handle = cx.new_model(|cx| builder.subscribe(cx)); diff --git a/crates/terminal/Cargo.toml b/crates/terminal/Cargo.toml index 994702a446b307555607177b2549d7fd808100b4..958207bce93c2ade602f57572995cfca535d0beb 100644 --- a/crates/terminal/Cargo.toml +++ b/crates/terminal/Cargo.toml @@ -21,7 +21,7 @@ dirs.workspace = true futures.workspace = true gpui.workspace = true libc.workspace = true -task.workspace = true +release_channel.workspace = true schemars.workspace = true serde.workspace = true serde_derive.workspace = true @@ -29,6 +29,7 @@ serde_json.workspace = true settings.workspace = true sysinfo.workspace = true smol.workspace = true +task.workspace = true theme.workspace = true thiserror.workspace = true util.workspace = true diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs index d66be6c47413b204e03d97f2a48952cbeaa35d21..3fedfcf4be779f5bde555bae9f13e37c608cef9f 100644 --- a/crates/terminal/src/terminal.rs +++ b/crates/terminal/src/terminal.rs @@ -319,12 +319,18 @@ impl TerminalBuilder { max_scroll_history_lines: Option, window: AnyWindowHandle, completion_tx: Sender<()>, + cx: &mut AppContext, ) -> Result { // TODO: Properly set the current locale, env.entry("LC_ALL".to_string()) .or_insert_with(|| "en_US.UTF-8".to_string()); env.insert("ZED_TERM".to_string(), "true".to_string()); + env.insert("TERM_PROGRAM".to_string(), "zed".to_string()); + env.insert( + "TERM_PROGRAM_VERSION".to_string(), + release_channel::AppVersion::global(cx).to_string(), + ); let pty_options = { let alac_shell = match shell.clone() {