File tree Expand file tree Collapse file tree 2 files changed +8
-4
lines changed
Expand file tree Collapse file tree 2 files changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -171,7 +171,8 @@ add_path() {
171171 path_to_add=$1
172172 [[ " :$PATH :" == * " :$path_to_add :" * ]] && return
173173 if [[ -n " $GITHUB_PATH " ]]; then
174- echo " $path_to_add " | tee -a " $GITHUB_PATH " > /dev/null 2>&1
174+ existing=$( cat " $GITHUB_PATH " 2> /dev/null)
175+ printf ' %s\n%s' " $path_to_add " " $existing " > " $GITHUB_PATH "
175176 else
176177 profile=$( get_shell_profile)
177178 ([ -e " $profile " ] && grep -q " :$path_to_add \" " " $profile " 2> /dev/null) || echo " export PATH=\"\$ {PATH:+\$ {PATH}:}\" $path_to_add " | sudo tee -a " $profile " > /dev/null 2>&1
Original file line number Diff line number Diff line change @@ -81,13 +81,15 @@ Function Get-PathFromRegistry {
8181# Function to add a location to PATH.
8282Function Add-Path {
8383 param (
84- [string ]$PathItem
84+ [string ]$PathItem ,
85+ [switch ]$Force
8586 )
86- if (" $env: PATH ;" .contains(" $PathItem ;" )) {
87+ if (-not $Force -and " $env: PATH ;" .contains(" $PathItem ;" )) {
8788 return
8889 }
8990 if ($env: GITHUB_PATH ) {
90- Add-Content $PathItem - Path $env: GITHUB_PATH - Encoding utf8
91+ $existingContent = Get-Content $env: GITHUB_PATH - Raw - ErrorAction SilentlyContinue
92+ Set-Content - Path $env: GITHUB_PATH - Value " $PathItem `n $existingContent " - NoNewline - Encoding utf8
9193 $env: PATH += " $PathItem ;"
9294 } else {
9395 $newPath = (Get-ItemProperty - Path ' hkcu:\Environment' - Name PATH).Path.replace(" $PathItem ;" , ' ' )
@@ -375,6 +377,7 @@ if(-not($env:ImageOS) -and -not($env:ImageVersion)) {
375377 if (-not (Test-Path - LiteralPath $current_profile )) {
376378 New-Item - Path $current_profile - ItemType " file" - Force > $null 2>&1
377379 }
380+ Add-Path - PathItem $bin_dir - Force
378381}
379382
380383$src = Join-Path - Path $PSScriptRoot - ChildPath \..
You can’t perform that action at this time.
0 commit comments