Zed Windows Build and Update Script #16811
Replies: 14 comments 5 replies
-
WSL SSH Setup Guide for Zed Remote DevelopmentI was experimenting this weekend to get Zed remote development working on WSL2. Prerequisites
GistHere is the gist: https://gist.github.com/da-moon/51f23971feb005d5389642e56ce33bff Script Features
Zed Environment Variable SupportA key feature of this script is its support for the How to Use the Script
Updating Zed ConfigurationTo ensure Zed sets the correct environment variables when using the integrated terminal on Windows, you can update the Zed configuration file. Note that this configuration is separate from the SSH configuration and only affects Zed's behavior on the Windows side. Run the following PowerShell snippet to update the Zed configuration file: $jsonPath = "$env:APPDATA\Zed\settings.json"
$cleanedContent = (Get-Content -Path $jsonPath) | ForEach-Object {
$_ -replace '//.*', ''
} | Out-String
$jsonContent = $cleanedContent | ConvertFrom-Json
if (-not $jsonContent.terminal) {
$jsonContent | Add-Member -MemberType NoteProperty -Name "terminal" -Value @{ "env" = @{} }
} elseif (-not $jsonContent.terminal.env) {
$jsonContent.terminal | Add-Member -MemberType NoteProperty -Name "env" -Value @{}
}
if (-not $jsonContent.terminal.env.PSObject.Properties["TERM_PROGRAM"]) {
$jsonContent.terminal.env.TERM_PROGRAM = "zed"
}
$jsonContent | ConvertTo-Json -Depth 10 | Set-Content -Path $jsonPath -Force Note: This snippet will remove any comments from your Zed configuration file. If you have important comments in your configuration, make sure to back up the file before running the snippet. This snippet updates the Zed configuration to set the Customizing Your WSL Environment for ZedAfter running the setup script, you'll need to update your SSH configuration on Windows to take advantage of the Zed-specific features:
With the SSH configuration set up, you can customize your WSL environment based on whether you're connecting from Zed. For example, to prevent Zellij from automatically starting a session when using Zed's terminal, add this to your if [ -x "$(command -v zellij)" ]; then
terminal="$(ps -o comm= -p $(ps -o ppid= -p $$))"
case "${terminal}" in
"warp" | "tilda" | "poetry" | "node" | "zed-editor")
# No action needed, terminal matches one of the conditions
;;
*)
if [ "${TERM_PROGRAM}" != "vscode" ] && [ "${TERM_PROGRAM}" != "zed" ]; then
eval "$(zellij setup --generate-auto-start bash)"
fi
;;
esac
fi Troubleshooting
ConclusionThis script aims to simplify the process of setting up SSH access to WSL2, with specific enhancements for Zed users. It provides a foundation for seamless remote development experiences. Feel free to customize the script further to suit your specific needs. I welcome any feedback or suggestions for improvements. Happy coding with Zed and WSL! |
Beta Was this translation helpful? Give feedback.
-
You can use the following snippet in your Import-Module Microsoft.PowerShell.SecretStore
# NOTE: use a safer password than `00000000` if needed !
Unlock-SecretStore -Password (ConvertTo-SecureString "00000000" -AsPlainText -Force)
# NOTE: initialize the `SecretStore` secret store
# Register-SecretVault -Name 'SecretStore' -ModuleName 'Microsoft.PowerShell.SecretStore'
# Set-SecretStorePassword -NewPassword (ConvertTo-SecureString "00000000" -AsPlainText -Force)
if (Get-Command Get-Secret -ErrorAction SilentlyContinue) {
# NOTE: setting API key in the secret store
# Set-Secret -Vault 'SecretStore' -Name 'OPENAI_API_KEY' -Secret "<YOUR-OPENAPI-TOKEN>"
# NOTE: remove an element from the secret store
# Remove-Secret -Vault 'SecretStore' -Name "OPENAI_API_KEY"
if (Get-Secret -AsPlainText -Name 'OPENAI_API_KEY' -Vault 'SecretStore' -ErrorAction SilentlyContinue) {
`$env:OPENAI_API_KEY = "$(Get-Secret -AsPlainText -Name 'OPENAI_API_KEY' -Vault 'SecretStore')"
}
if (Get-Secret -AsPlainText -Name 'ANTHROPIC_API_KEY' -Vault 'SecretStore' -ErrorAction SilentlyContinue) {
`$env:ANTHROPIC_API_KEY = "$(Get-Secret -AsPlainText -Name 'ANTHROPIC_API_KEY' -Vault 'SecretStore')"
}
if (Get-Secret -AsPlainText -Name 'GOOGLE_AI_API_KEY' -Vault 'SecretStore' -ErrorAction SilentlyContinue) {
`$env:GOOGLE_AI_API_KEY = "$(Get-Secret -AsPlainText -Name 'GOOGLE_AI_API_KEY' -Vault 'SecretStore')"
}
} Keep in mind that this approach won't pass in environment variables to Zed when it is launched through the start menu. To pass API keys to Zed , launched from start menu / shortcut, you have to persist it on User environment variables if (Get-Command Get-Secret -ErrorAction SilentlyContinue) {
@('OPENAI_API_KEY', 'ANTHROPIC_API_KEY', 'GOOGLE_AI_API_KEY') | ForEach-Object {
if (Get-Secret -AsPlainText -Name $_ -Vault 'SecretStore' -ErrorAction SilentlyContinue) {
$secretValue = Get-Secret -AsPlainText -Name $_ -Vault 'SecretStore'
[Environment]::SetEnvironmentVariable($_, $secretValue, 'User')
Write-Host "$_ has been set from SecretStore and persisted at the user level."
} else {
Write-Host "$_ not found in SecretStore."
}
}
} else {
Write-Host "SecretStore module not found or Get-Secret command not available."
}
Write-Host "Environment variables have been updated. You may need to restart your applications or log out and back in for the changes to take effect."
|
Beta Was this translation helpful? Give feedback.
-
@da-moon Nice effort, much appreciated! I suggest you to add a "clean" or "uninstall" flag to enable a complete removal of Zed and, optionally, all or some of its dependencies (e.g., "-u All", "-u VSBuildTools", "-u WinSDK", "-u Rust") from the system. |
Beta Was this translation helpful? Give feedback.
-
Hey @da-moon , the above script does not works for me |
Beta Was this translation helpful? Give feedback.
-
Script works for me, thank @da-moon, maybe you could prepare PR into |
Beta Was this translation helpful? Give feedback.
-
I have an error when I'm trying to build:
|
Beta Was this translation helpful? Give feedback.
-
@vxxvvxxv |
Beta Was this translation helpful? Give feedback.
-
Doesn't work with latest versions of Powershell Core for me due to depreciated Get-WMIObject. Running it the old Windows Powershell seems to work and is an easy way around this though - in case anyone else has this issue. |
Beta Was this translation helpful? Give feedback.
-
First off, thank you for the time and effort you have put into writing this script🙏 I went through the whole download process and through your's and others' comments managed to complete the download, but now, neither the desktop shortcut nor the zed.exe file manage to open the program. I went through all the troubleshooting steps and the only error message I got was when I run
I tried my best to see if I could find a solution through the comments here, searching the internet, and copilot/chatgpt, but after a few hours, it is not looking any better. If you have any advice as to what I can do to fix the issue and open the program, I would be very appreciative. Thanks! |
Beta Was this translation helpful? Give feedback.
-
Good job! |
Beta Was this translation helpful? Give feedback.
-
For anyone else who gets the dreaded "path too long" error despite having long paths enabled:
This can be resolved by setting long paths in git, ie. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the script, by the way. One thing that has changed since you wrote this is that CMake is also a dependency now, but the build script still works fine. |
Beta Was this translation helpful? Give feedback.
-
Invoke-RestMethod : {"message":"API rate limit exceeded for 178.157.58.21. (But here's the good news: Authenticated req
uests get a higher rate limit. Check out the documentation for more details.)","documentation_url":"https://docs.github
.com/rest/overview/resources-in-the-rest-api#rate-limiting"}
所在位置 D:\build-zed.ps1:19 字符: 17
+ $releases = Invoke-RestMethod -Uri $releasesUrl -Method Get
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod],WebExce
ption
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand |
Beta Was this translation helpful? Give feedback.
-
In case it's helpful for anyone else:
|
Beta Was this translation helpful? Give feedback.
-
Zed Windows Build and Update Script
Hey everyone!
I love this editor and want to give back to the community.
I wrote a PowerShell script that automates the building, installing, and updating Zed on Windows.
With this script, you won't have to launch
zed
in WSL which has it's own issues (e.g #14126)Here are its key features:
Automatic Update Checking
Flexible Installation
Build Process
Environment Setup
Command-line Integration
zed --help
) from any terminalUser Convenience
Channel Support
ZED_CHANNEL
environment variable to determine which channel to useVersion Management
Error Handling and Diagnostics
Customization
This script provides a comprehensive solution for Windows users to easily install, update, and manage Zed, offering similar convenience to package managers on other platforms.
Usage Guide
To use this script, follow these steps:
Download the script from the following gist:
https://gist.github.com/da-moon/bd9dd0f9f5164f06108727fa35bfe644
Save the script as
build-zed.ps1
on your local machine.Open PowerShell as an administrator.
Navigate to the directory containing the script:
(Optional) If you want to use the preview channel, set the environment variable:
Run the script:
.\build-zed.ps1
Follow any on-screen prompts for installing dependencies if needed.
Once the script completes, you can run Zed using the
zed
command from any PowerShell or Command Prompt window.Using the Zed Command
After installation, you can use the
zed
command in the following ways:zed
: Opens Zed in the current directoryzed .
: Opens Zed in the current directory (explicitly)zed path/to/file
: Opens the specified file in Zedzed --help
: Displays help informationTroubleshooting
If you encounter any issues while using the
zed
command, try the following:$env:LOCALAPPDATA\Programs\Zed\zed.exe
).PATH
; if it did not work, try closing and opening a new Powershell terminal.--help
). Read these carefully, as they may provide clues about what's going wrong.$env:LOCALAPPDATA\Programs\Zed\zed.exe
directly to see if there are any visible error messages.If problems persist, please report the issue on the gist page, including any error messages and the steps to reproduce the problem.
For any issues or contributions, please visit the gist page and leave a comment or create a fork with your improvements.
Beta Was this translation helpful? Give feedback.
All reactions