zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
50.95k stars 3.16k forks source link

TERM env is copied instead of being set to zed #17991

Open susanthenerd opened 2 months ago

susanthenerd commented 2 months ago

Check for existing issues

Describe the bug / provide steps to reproduce it

When launching a terminal from an existing terminal emulator, the TERM environment variable is inherited. For example:

However, when starting the terminal from a graphical launcher (such as fuzzel), the TERM environment variable is set to TERM=dumb, which causes the terminal to become unusable due to lack of proper capabilities.

To fix this, the TERM environment variable should be set to a more appropriate value, depending on the context. Ideally:

This adjustment will prevent issues with improperly configured terminal environments when launched from non-terminal programs.

Environment

Zed: v0.152.3 (Zed) OS: Linux Wayland nixos 24.11 Memory: 62.5 GiB Architecture: x86_64 GPU: Intel(R) Graphics (ADL GT2) || Intel open-source Mesa driver || Mesa 24.2.2

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your Zed.log file to this issue.

No response

SomeoneToIgnore commented 2 months ago

The issue description says nothing about Zed, so interested to see what's expected from it.

So far, we do some fallbacks when using ssh mode: https://github.com/zed-industries/zed/blob/9fd550cf112dc331956fb83482688f9b43618f85/crates/project/src/terminals.rs#L150-L151

we can do similar things in TerminalKind::Shell(_) nearby.

susanthenerd commented 2 months ago

I've realize I wrote a very bad bug report. The problem is that a lot of programs check for the TERM variable to be set and if it isn't properly set they don't work in the terminal.

In my situation nothing works because fish won't load things if the TERM env variable is dumb which is set by default by zed right now when launched from outside a terminal

2zqa commented 2 months ago

Can reproduce. An alternative title could be "TERM environment variable should be set to xterm-256color to enable color printing in terminal". See video demonstration. @susanthenerd, I assume this is what you were trying to convey?

https://github.com/user-attachments/assets/eb78a2ac-7b92-4395-b027-4419a08a6af9

In the meantime, a workaround is to set the TERM variable explicitly to xterm256-color in your .config/settings.json:

{
  // other settings here...
  "terminal": {
    "env": {
      "TERM": "xterm-256color"
    }
  }
}

Environment:

Zed: v0.153.6 (Zed) OS: Linux Wayland fedora 40 Memory: 31 GiB Architecture: x86_64 GPU: Intel(R) Graphics (RPL-U) || Intel open-source Mesa driver || Mesa 24.1.7

notpeter commented 2 months ago

I can reproduce on MacOS too. When launched via Finder/Spotlight (or relaunched via zed: reload workspace) TERM is alacritty but when launched via the zed CLI from an external terminal it matches the TERM of the launching terminal (xterm-256color for Terminal.app or Warp).

bhb603 commented 2 weeks ago

X-posting here because I think this is the root cause of the other issue: https://github.com/zed-industries/zed/issues/20603#issuecomment-2479603938

tl;dr, when I launch zed . from a tmux session, the zed terminal inherits TERM=tmux-256color, which causes weird behavior, i.e. the command is prepended to the output.