Fix init error in PowerShell strict mode (#233)

This commit is contained in:
Ajeet D'Souza 2021-07-17 17:57:04 +05:30 committed by GitHub
parent b9b0abe471
commit 20d9f3d18c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 3 deletions

View File

@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Nushell: errors on 0.33.0.
- PowerShell: errors when initializing in `StrictMode`.
## [0.7.2] - 2021-06-10

View File

@ -280,7 +280,8 @@ mod tests {
#[values(false, true)] resolve_symlinks: bool,
) {
let opts = Opts { cmd, hook, echo, resolve_symlinks };
let source = Powershell(&opts).render().unwrap();
let mut source = "Set-StrictMode -Version latest\n".to_string();
Powershell(&opts).render_into(&mut source).unwrap();
Command::new("pwsh")
.args(&["-NoLogo", "-NonInteractive", "-NoProfile", "-Command", &source])

View File

@ -34,8 +34,11 @@ function __zoxide_hook {
}
# Initialize hook.
if ($__zoxide_hooked -ne '1') {
$__zoxide_hooked = '1'
{# Initialize $__zoxide_hooked if it does not exist. Removing this will cause
# an unset variable error in StrictMode. #}
$__zoxide_hooked = (Get-Variable __zoxide_hooked -ValueOnly -ErrorAction silentlycontinue)
if ($__zoxide_hooked -ne 1) {
$__zoxide_hooked = 1
{%- match hook %}
{%- when InitHook::None %}
{{ not_configured }}