Skip to content

Commit 8163a2c

Browse files
committed
2 parents 61c53d4 + 1a35485 commit 8163a2c

3 files changed

Lines changed: 18 additions & 8 deletions

File tree

linux/01installHomeBrew.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
2-
brew install powershell
2+
# 判断pwsh是否安装
3+
if ! command -v pwsh &> /dev/null
4+
then
5+
echo "pwsh not found, install it"
6+
brew install powershell
7+
else
8+
echo "pwsh found, skip install"
9+
fi

profile/profile_unix.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ function Initialize-Environment {
6969
if (Test-Path -Path "/home/linuxbrew/.linuxbrew/bin"){
7070
$env:PATH += ":/home/linuxbrew/.linuxbrew/bin/"
7171
}
72+
if($IsLinux){
73+
Sync-PathFromBash
74+
}
7275
# 初始化开发工具
7376
Write-Verbose "初始化开发工具"
7477
$tools = @{

psutils/modules/env.psm1

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ function Sync-PathFromBash {
448448
param()
449449

450450
try {
451-
Write-Verbose "正在从 Bash 登录 Shell 中获取 PATH..."
451+
Write-Information "正在从 Bash 登录 Shell 中获取 PATH..."
452452
# 使用 'bash -l' 确保加载了 ~/.profile 或 ~/.bash_profile
453453
# '-c' 表示执行后面的命令
454454
$bashPathOutput = bash -l -c 'echo $PATH'
@@ -464,29 +464,29 @@ function Sync-PathFromBash {
464464
$bashPaths = $bashPathOutput.Split($separator, [System.StringSplitOptions]::RemoveEmptyEntries)
465465
$psPaths = $env:PATH.Split($separator, [System.StringSplitOptions]::RemoveEmptyEntries)
466466

467-
Write-Verbose "从 Bash 中找到的路径: $($bashPaths.Count)"
468-
Write-Verbose "当前 PowerShell 中的路径: $($psPaths.Count)"
467+
Write-Information "从 Bash 中找到的路径: $($bashPaths.Count)"
468+
Write-Information "当前 PowerShell 中的路径: $($psPaths.Count)"
469469

470470
# 使用 Compare-Object 找出只存在于 Bash PATH 中的路径
471471
# ReferenceObject 是基准,DifferenceObject 是要比较的对象
472472
$missingPaths = Compare-Object -ReferenceObject $psPaths -DifferenceObject $bashPaths -PassThru | Where-Object { $_ -ne $null }
473473

474474
if ($missingPaths.Count -gt 0) {
475-
Write-Host "发现 $($missingPaths.Count) 个需要从 Bash 同步的路径。" -ForegroundColor Yellow
475+
Write-Information "发现 $($missingPaths.Count) 个需要从 Bash 同步的路径。"
476476

477477
# 将找到的缺失路径连接成一个字符串
478478
$pathsToAdd = $missingPaths -join $separator
479479

480480
# 遍历并显示将要添加的每一个路径
481481
foreach ($path in $missingPaths) {
482-
Write-Host " -> 正在添加: $path" -ForegroundColor Green
482+
Write-Information " -> 正在添加: $path"
483483
}
484484

485485
# 将新路径追加到现有的 PowerShell PATH 后面
486486
$env:PATH = "$($env:PATH)$separator$pathsToAdd"
487-
Write-Host "PowerShell PATH 已成功更新!" -ForegroundColor Green
487+
Write-Information "PowerShell PATH 已成功更新!"
488488
} else {
489-
Write-Verbose "Power-Shell 的 PATH 与 Bash 完全同步,无需操作。"
489+
Write-Information "Power-Shell 的 PATH 与 Bash 完全同步,无需操作。"
490490
}
491491
}
492492
catch {

0 commit comments

Comments
 (0)