Skip to content

Cannot live edit theme and font settings in the terminal user settings file, from within windows terminal #19110

Open
@ridhwaans

Description

@ridhwaans

Windows Terminal version

1.22.11141.0

Windows build number

26100.4652

Other Software

I am on ubuntu 24.04.2 LTS, on WSL2 6.6.87.2, on win11 x86

Edition	Windows 11 Home
Version	24H2
Installed on	‎11/‎8/‎2024
OS build	26100.4652
Experience	Windows Feature Experience Pack 1000.26100.128.0

i run the code below to change the theme and font settings in the terminal user settings file, from within windows terminal

set -e

# 1/2 

$font = $2

if [ $(uname) = Linux ]; then
  if [ -n "$WSL_DISTRO_NAME" ]; then
    echo "(wsl)"

    WINDOWS_HOME=$(wslpath $(powershell.exe '$env:UserProfile') | sed -e 's/\r//g')
    # echo expands glob
    WINDOWS_TERMINAL_SETTINGS_DIR=$(echo $WINDOWS_HOME/AppData/Local/Packages/Microsoft.WindowsTerminal*/LocalState)

    jq --arg base_name "$font" '.profiles.list |= map(if .source == "Windows.Terminal.Wsl" then .font.face = $font else . end)' \
    "$WINDOWS_TERMINAL_SETTINGS_DIR"/settings.json \
    > temp.json && mv temp.json "$WINDOWS_TERMINAL_SETTINGS_DIR"/settings.json
  fi
fi

# 2/2 

$theme = $3

if [ -n "$WSL_DISTRO_NAME" ]; then
      echo "(wsl)"

      WINDOWS_HOME=$(wslpath $(powershell.exe '$env:UserProfile') | sed -e 's/\r//g')
      WINDOWS_TERMINAL_SETTINGS_DIR=$WINDOWS_HOME/AppData/Local/Packages/Microsoft.WindowsTerminal*/LocalState

      # echo expands glob, but ls -d does not
      SETTINGS_FILE=$(echo $WINDOWS_TERMINAL_SETTINGS_DIR)/settings.json
      echo $SETTINGS_FILE

      echo $ENVIRONMENT_DIR/src/themes/$theme/terminal.json
      jq --slurpfile theme "source_dir/src/themes/$theme/terminal.json" \
      '.schemes = [$theme]' \
      $SETTINGS_FILE \
      > temp.json && mv temp.json $SETTINGS_FILE

in both cases, the code fails to live edit and it pops this error

Image

what happens after i restart windows terminal is that i lose my custom profiles, schemes & starting tab, and it reverts back to the default Windows Terminal settings

Steps to reproduce

  • create a bash file with the code
  • run in a linux tab, within wsl2

Expected Behavior

should be able to update the users settings file in windows terminal

Actual Behavior

doesnt edit the users settings file and windows terminal displays and error

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIt either shouldn't be doing this or needs an investigation.Needs-AttentionThe core contributors need to come back around and look at this ASAP.Needs-TriageIt's a new issue that the core contributor team needs to triage at the next triage meeting

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions