From 2893e37d557990fe20335017b3c934f70e33a401 Mon Sep 17 00:00:00 2001 From: yangjie11 Date: Mon, 12 Jun 2023 17:32:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D.env=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=E7=9A=84=E6=8F=90=E7=A4=BA=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=9C=A8powershell=E4=B8=8A=E4=BD=BF?= =?UTF-8?q?=E7=94=A8env=E7=9A=84=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 43 +++++++++++++++++++++++++++++++++++++++++++ touch_env.ps1 | 8 ++++++++ 2 files changed, 51 insertions(+) diff --git a/README.md b/README.md index a432df6b..0faac654 100644 --- a/README.md +++ b/README.md @@ -29,3 +29,46 @@ or PLAN B: open `~/.bashrc` file, and attach the command `source ~/.env/env.sh` ### Use Env Please see: https://github.com/RT-Thread/rt-thread/blob/master/documentation/env/env.md#bsp-configuration-menuconfig + +## Usage under Windows + +Tested on the following version of PowerShell: + +- PSVersion 5.1.22621.963 +- PSVersion 5.1.19041.2673 + +### Install Env + +您需要以管理员身份运行 PowerShell 来设置执行。(You need to run PowerShell as an administrator to set up execution.) + +在 PowerShell 中执行(Execute the command in PowerShell): + +```powershell +wget https://raw.githubusercontent.com/RT-Thread/env/master/install_windows.ps1 -O install_windows.ps1 +set-executionpolicy remotesigned +.\install_windows.ps1 +``` + +对于中国大陆用户,请使用以下命令: + +```powershell +wget https://gitee.com/RT-Thread-Mirror/env/raw/master/install_windows.ps1 -O install_windows.ps1 +set-executionpolicy remotesigned +.\install_windows.ps1 --gitee +``` + +注意:将其设置为 remotesigned 后,您可以作为普通用户运行 PowerShell。( After setting it to remotesigned, you can run PowerShell as a normal user.) + +### Prepare Env + +方案 A:每次重启 PowerShell 时,都需要输入命令 `~/.env/env.ps1`,以激活环境变量。(PLAN A: Each time you restart PowerShell, you need to enter the command `~/.env/env.ps1` to activate the environment variable.) + +方案 B:打开 `C:\Users\user\Documents\WindowsPowerShell `,新建文件 Microsoft.PowerShell_profile.ps1,然后写入 `~/.env/env.ps1` 内容即可,它将在你重启 PowerShell 时自动执行,无需再执行方案 A 中的命令。(or PLAN B: Open `C:\Users\user\Documents\WindowsPowerShell` and create a new file `Microsoft.PowerShell_profile.ps1`. Then write `~/.env/env.ps1` to the file. It will be executed automatically when you restart PowerShell, without having to execute the command in scenario A.) + +如果还需要使 scons 命令有效以及能使用 QEMU,则需要再添加工具链路径和 QEMU 路径。(If you also need the scons command to work and to use QEMU, you need to add the following two commands to add your toolchain path and the QEMU path.) + +``` +~/.env/env.ps1 +$env:RTT_EXEC_PATH="your toolchain path" +$env:path="your QEMU path;$env:path" +``` diff --git a/touch_env.ps1 b/touch_env.ps1 index e7de3175..9ef8afbc 100644 --- a/touch_env.ps1 +++ b/touch_env.ps1 @@ -12,6 +12,14 @@ if ($args[0] -eq "--gitee") { } $env_dir = "$HOME\.env" + +if (Test-Path -Path $env_dir) { + $option = Read-Host ".env directory already exists. Would you like to remove and recreate .env directory? (Y/N) " option +} if (( $option -eq 'Y' ) -or ($option -eq 'y')) { + Get-ChildItem $env_dir -Recurse | Remove-Item -Force -Recurse + rm -r $env_dir +} + if (!(Test-Path -Path $env_dir)) { echo "creating .env folder!" $package_url=$DEFAULT_RTT_PACKAGE_URL