Skip to content

Commit afefff5

Browse files
authored
EIM-301 create terminal profile (#236)
1 parent 3deac9c commit afefff5

File tree

2 files changed

+457
-1
lines changed

2 files changed

+457
-1
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# ESP-IDF PowerShell Profile Fragment
2+
# Version: {{idf_version}}
3+
# Auto-generated - Installed via ESP-IDF Manager
4+
5+
{{env_var_pairs}}
6+
7+
function Parse-CMakeVersion {
8+
$cmakeFile = "{{idf_path}}\tools\cmake\version.cmake"
9+
10+
if (-not (Test-Path $cmakeFile)) {
11+
Write-Warning "CMake version file not found at: $cmakeFile"
12+
return "{{idf_version}}"
13+
}
14+
15+
$major = $null
16+
$minor = $null
17+
18+
try {
19+
$content = Get-Content $cmakeFile -ErrorAction Stop
20+
21+
foreach ($line in $content) {
22+
$line = $line.Trim()
23+
24+
if ($line -match '^set\(IDF_VERSION_MAJOR') {
25+
if ($line -match '\d+') {
26+
$major = $matches[0]
27+
}
28+
}
29+
elseif ($line -match '^set\(IDF_VERSION_MINOR') {
30+
if ($line -match '\d+') {
31+
$minor = $matches[0]
32+
}
33+
}
34+
}
35+
36+
if ($null -eq $major -or $null -eq $minor) {
37+
Write-Warning "Could not parse version, using: {{idf_version}}"
38+
return "{{idf_version}}"
39+
}
40+
41+
return "$major.$minor"
42+
}
43+
catch {
44+
Write-Warning "Failed to read CMake version file: $($_.Exception.Message)"
45+
return "{{idf_version}}"
46+
}
47+
}
48+
49+
$IdfVersion = Parse-CMakeVersion
50+
51+
# Set environment variables
52+
$env:ESP_IDF_VERSION = "$IdfVersion"
53+
$env_var_pairs.GetEnumerator() | ForEach-Object {
54+
Set-Item -Path "env:$($_.Key)" -Value $_.Value -ErrorAction SilentlyContinue
55+
}
56+
57+
# Prepend ESP-IDF tools to PATH (only if not already present)
58+
$idfToolsPath = "{{add_paths_extras}}"
59+
if ($env:PATH -notlike "*$idfToolsPath*") {
60+
$env:PATH = "$idfToolsPath;$env:PATH"
61+
}
62+
63+
# Define ESP-IDF helper functions
64+
function global:Invoke-idfpy {
65+
& "{{idf_python_env_path}}\Scripts\python.exe" "{{idf_path}}\tools\idf.py" @args
66+
}
67+
68+
function global:esptool.py {
69+
& "{{idf_python_env_path}}\Scripts\python.exe" "{{idf_path}}\components\esptool_py\esptool\esptool.py" @args
70+
}
71+
72+
function global:espefuse.py {
73+
& "{{idf_python_env_path}}\Scripts\python.exe" "{{idf_path}}\components\esptool_py\esptool\espefuse.py" @args
74+
}
75+
76+
function global:espsecure.py {
77+
& "{{idf_python_env_path}}\Scripts\python.exe" "{{idf_path}}\components\esptool_py\esptool\espsecure.py" @args
78+
}
79+
80+
function global:otatool.py {
81+
& "{{idf_python_env_path}}\Scripts\python.exe" "{{idf_path}}\components\app_update\otatool.py" @args
82+
}
83+
84+
function global:parttool.py {
85+
& "{{idf_python_env_path}}\Scripts\python.exe" "{{idf_path}}\components\partition_table\parttool.py" @args
86+
}
87+
88+
# Create alias for idf.py
89+
New-Alias -Name idf.py -Value Invoke-idfpy -Force -Scope Global -ErrorAction SilentlyContinue
90+
91+
# Python venv activation
92+
. "{{idf_python_env_path}}\Scripts\Activate.ps1"
93+
94+
Write-Host "ESP-IDF environment loaded (v$IdfVersion)" -ForegroundColor Green

0 commit comments

Comments
 (0)