Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] shims file ps1 sometimes $PSScriptRoot is empty string #5834

Open
uuRRx0 opened this issue Mar 20, 2024 · 0 comments
Open

[Bug] shims file ps1 sometimes $PSScriptRoot is empty string #5834

uuRRx0 opened this issue Mar 20, 2024 · 0 comments
Labels

Comments

@uuRRx0
Copy link

uuRRx0 commented Mar 20, 2024

Bug Report

Current Behavior

When adding a tool like scoop-setup.ps1, after running the command scoop setup arg1, the value of $PSScriptRoot in the command_path method is a empty string.

Expected Behavior

Ability to correctly call the scoop setup arg1 method

Additional context/output

Possible Solution

When $PSSScriptRoot is a null character, you can add a fallback hard-coded path parameter, such as the post_install hook in the configuration below.

System details

Windows version: 11

OS architecture: 64bit

PowerShell version: 5.1.22621.2506

Additional software: [(optional) e.g. ConEmu, Git]

Scoop Configuration

//# Your configuration here
{
   "version": "0.2024.03.18",
   "description": "Command for scoop local installation.",
   "homepage": "https://github.com/uuRRx0/scoop-utils",
   "license": "MIT",
   "url": "https://mirror.ghproxy.com/https://raw.githubusercontent.com/uuRRx0/scoop-utils/3a34d468ba6074bb2f418a8d8325b17e38942a05/scoop-setup.ps1",
   "hash": "33a5be93bda8826b3e16b6fec13682e00c39f2fc0c7609ab59fd828c9e0ad1ae",
   "checkver": {
     "url": "https://github.com/uuRRx0/scoop-utils/commits/main/scoop-setup.ps1.atom",
     "regex": "(?s)>(\\d+)-(\\d+)-(\\d+)T.*?/(?<sha>[0-9a-f]{40})",
     "replace": "0.${1}.${2}.${3}"
   },
   "bin": "scoop-setup.ps1",
   "post_install": [
     "# fix shims file $PSScriptRoot is empty string",
     "$filePath = \"$scoopdir/shims/scoop-setup.ps1\"",
     "$content = (Get-Content -Path $filePath) -join \"`r`n\"",
     "$newContent = $content -replace \"(?sm)((#\\s)(.+)\\r\\n)(\\`$path = )(.+?).$\", \"`$1`$4 if (`$PSScriptRoot -eq `\"`\" -or `$PSScriptRoot -eq `$null) { `\"`$3`\" } else { (`$5) }\"" ,
     "$newContent | Out-UTF8File $filePath"
   ],
   "autoupdate": {
     "url": "https://mirror.ghproxy.com/https://raw.githubusercontent.com/uuRRx0/scoop-utils/$matchSha/scoop-setup.ps1"
   }
}
@uuRRx0 uuRRx0 added the bug label Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant