Terminal execution exceptions

更新时间:
复制 MD 格式

Introduction

Dvelopment environment and configuration might influence command execution in the terminal. VS Code and JetBrains IDEs have certain limitations and compatibility issues with terminals on different operating systems. This might cause issues like not being able to invoke terminal commands or get results when you using the Lingma Agent mode.

VS Code

Common troubleshooting methods

The Lingma plugin in VS Code relies on the VS Code Shell integration API to xecute terminal commands and read their outputs. This API is a new feature in VS Code version 1.93 and currently only supports the following types of shells.

Ensure your VS Code version is greater than 1.93 and that your default terminal is one of the following:

  • Linux/macOS: bash, fish, pwsh, zsh

  • Windows: Git Bash, pwsh

If you encounter terminal execution exceptions, try the following methods:

Method 1: Upgrade VS Code

Check your VS Code version and ensure it's 1.93 or above:

  1. Open VS Code.

  2. Press Cmd + Shift + P (Mac) or Ctrl + Shift + P (Windows/Linux).

  3. Type Code: Check for Updates, and then select it.

  4. Restart VS Code after the update is complete.

Method 2: Configure a supported VS Code shell

  1. Open VS Code.

  2. Press Cmd + Shift + P (Mac) or Ctrl + Shift + P (Windows/Linux).

  3. Type Terminal: Select Default Profile, and then select it.

  4. Choose a supported shell:

    • Linux/macOS: bash, fish, pwsh, zsh

    • Windows: Git Bash, pwsh

  5. Exit VS Code, and reopen it.

Method 3: Manually install shell integration

If you still encounter issues with the steps above, manually install shell integration.

For example,

  • zsh:

    1. Add the following line to your ~/.zshrc file:

      [[ "$TERM_PROGRAM" == "vscode" ]] && . "$(code --locate-shell-integration-path zsh)"
    2. Save the file.

    3. Exit VS Code, and reopen it.

  • Bash (~/.bashrc):

[[ "$TERM_PROGRAM" == "vscode" ]] && . "$(code --locate-shell-integration-path bash)"
  • PowerShell ($Profile):

if ($env:TERM_PROGRAM -eq "vscode") { . "$(code --locate-shell-integration-path pwsh)" }
  • Fish (~/.config/fish/config.fish):

string match -q "$TERM_PROGRAM" "vscode"; and . (code --locate-shell-integration-path fish)

Still having issues?

If you still can't get terminal output after trying the methods above, click Stop Terminal to close the terminal window. Then, run the command again. This will reset the terminal connection and should fix the problem.

Windows

Git Bash

Git Bash provides a Unix-like command line experience on Windows. To use Git Bash, you need to:

  1. Download and run the Git for Windows installer from https://git-scm.com/downloads/win.

  2. Exit and reopen VS Code.

  3. Press Ctrl + Shift + P to open the command palette.

  4. Type Terminal: Select Default Profile, then select it.

  5. Choose Git Bash.

PowerShell

Make sure your powershell version is updated to versions later than 7.

  • Check your current PowerShell version by running the command: $PSVersionTable.PSVersion

  • If your version is lower than 7, update PowerShell.

By default, PowerShell restricts script execution for security reasons. To change the setting:

  1. Open PowerShell as an administrator: Press Win + X and select Windows PowerShell (Administrator) or Windows Terminal (Administrator).

  2. Check the current execution policy by running the command:

    Get-ExecutionPolicy
    • If the output is already RemoteSigned, Unrestricted, or Bypass, you might not need to change the execution policy. These policies should allow shell integration to work properly.

    • If the output is Restricted or AllSigned, change the policy to enable shell integration.

  3. Change the execution policy by running the command:

    Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

    This will set the RemoteSigned policy only for the current user, which is safer than a system-wide change.

  4. Confirm the change: Type Y at the prompt and press Enter.

  5. Verify the policy change: Run Get-ExecutionPolicy again to confirm the new setting.

  6. Restart VS Code and try shell integration again.

WSL

If you use WSL, try adding . "$(code --locate-shell-integration-path bash)" to your ~/.bashrc file, then restart and try again.

Other exceptions

Terminal output exceptions

If you see abnormal output with rectangles, lines, escape sequences, or control characters, it might be related to terminal customization tools. Common causes include zsh themes like: Powerlevel10k, Oh My Zsh, fish shell, etc.

How to troubleshoot:

  1. Temporarily disable these tools in your shell configuration file (for example, the ~/.zshrc file for zsh).

  2. If the problem is resolved, gradually re-enable features to identify the conflicting tool.

For example, if you use Powerlevel10k in zsh, disable it by commenting out the relevant lines in your ~/.zshrc file:

# Comment out the source line for Powerlevel10k
# source /path/to/powerlevel10k/powerlevel10k.zsh-theme

If the problem can be fixed by disabling these themes, you might need to find other VS Code shell integration configuration.

JetBrains IDEs

The Lingma plugin does not currently support the new terminal (Beta) available in the new UI starting from the 2024.1 version of the IDEs.

image.png

To disable the new terminal:

  • Method 1: In Settings or Preferences, open Tools - Terminal - Enable New Terminal and uncheck the new terminal option.

  • Method 2: In the Terminal window title, click the image.svg icon and uncheck Enable New Terminal.

Contact us

Contact us if you still can't solve your problem after checking the solutions in this document.