Closed alexvy86 closed 1 year ago
What is the output with the following script?
run_hello.ps1
:
Write-Output "Hello from $(Split-Path -Path ([System.Environment]::GetCommandLineArgs()[0]) -Leaf)"
powershell
indeed:
PS C:\Users\alejandrovi\.local\share\chezmoi> cat .\windows\.chezmoiscripts\run_hello.ps1
Write-Output "Hello from $(Split-Path -Path ([System.Environment]::GetCommandLineArgs()[0]) -Leaf)"
PS C:\Users\alejandrovi\.local\share\chezmoi> chezmoi apply
Hello from powershell
I skimmed this repo to see where the issue might be but didn't find anything obvious. Disclaimer: I'm not familiar enough with Go to be able to easily trace calls just by browsing the repo in Github :).
For completeness, my pwsh
and powershell
versions:
PS C:\Users\alejandrovi\.local\share\chezmoi> $PSVersionTable
Name Value
---- -----
PSVersion 7.3.0
PSEdition Core
GitCommitId 7.3.0
OS Microsoft Windows 10.0.22621
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
PS C:\Users\alejandrovi\.local\share\chezmoi> powershell
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows
PS C:\Users\alejandrovi\.local\share\chezmoi> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.22621.608
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.22621.608
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
The default .ps1
interpreter is set to powershell
, so I don't think the config setting is applying properly.
I don't use YAML for my config, so I'm just guessing here, but you might need to separate the keys/properties. Something like
interpreters:
ps1:
command: pwsh.exe
args: -NoLogo
Thanks @bradenhilton ! That was indeed the problem. I remember having several issues when I first tried to set up this section of the config file and thought I had left it working correctly, but evidently not. I'll make a PR to make the docs around this more explicit for the YAML case.
Describe the bug
It seems that
powershell
is being used to run one of myps1
scripts even though I changed the interpreter forps1
files topwsh
. I think this is actuallypowershell
being called from withinpwsh
because the error my script is reporting is this one (Get-FileHash : The term 'Get-FileHash' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
), and this comment from that linked issue shows that it occurs when callingpowershell
from apwsh
instance.To reproduce
Haven't had a chance to try to reproduce it in other machines, but the output included below should show why I think this is what's happening. I can reproduce it every time on my machine though, so can help to troubleshoot.
Expected behavior
powershell
is never called anywehre, if my interpreter forps1
files is set topwsh
.Output of command with the
--verbose
flagMy config file uses
pwsh.exe
as interpreter forps1
files:During
chezmoi apply --debug
, I seepowershell
as the first entry inargs
right after the (failed) execution of my script:Output of
chezmoi doctor
Additional context
Running the script myself in
pwsh
succeeds.