mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2025-12-12 14:30:10 +01:00
fix: pwsh version <7 and removed cnf
This commit is contained in:
parent
c20a46666c
commit
cfe8a1e1ba
2 changed files with 32 additions and 25 deletions
|
|
@ -61,12 +61,12 @@ Please follow the instruction for your shell:
|
|||
|
||||
> Append the following output to your profile:
|
||||
> ```pwsh
|
||||
> pay-respects pwsh --alias [<alias>] [--nocnf]
|
||||
> pay-respects pwsh --alias [<alias>]
|
||||
> ```
|
||||
|
||||
> Or directly pipe the output to your profile:
|
||||
> ```pwsh
|
||||
> pay-respects pwsh --alias [<alias>] [--nocnf] >> $PROFILE
|
||||
> pay-respects pwsh --alias [<alias>] >> $PROFILE
|
||||
> ```
|
||||
|
||||
</details>
|
||||
|
|
|
|||
|
|
@ -538,11 +538,16 @@ def --env {} [] {{
|
|||
# fetch command and error from session history only when not in cnf mode
|
||||
if ($env:_PR_MODE -ne 'cnf') {{
|
||||
$env:_PR_LAST_COMMAND = ({});
|
||||
if ($PSVersionTable.PSVersion.Major -ge 7) {{
|
||||
$err = Get-Error;
|
||||
if ($env:_PR_LAST_COMMAND -eq $err.InvocationInfo.Line) {{
|
||||
$env:_PR_ERROR_MSG = $err.Exception.Message
|
||||
}}
|
||||
}}
|
||||
if ($env:_PR_LAST_COMMAND -eq $err.InvocationInfo.Line) {{
|
||||
$env:_PR_ERROR_MSG = $err.Exception.Message
|
||||
}}
|
||||
}}
|
||||
$env:_PR_SHELL = '{}';
|
||||
&'{}';
|
||||
}}
|
||||
|
|
@ -638,28 +643,30 @@ end
|
|||
);
|
||||
}
|
||||
"pwsh" => {
|
||||
initialize = format!(
|
||||
r#"{}
|
||||
$ExecutionContext.InvokeCommand.CommandNotFoundAction =
|
||||
{{
|
||||
param(
|
||||
[string]
|
||||
$commandName,
|
||||
[System.Management.Automation.CommandLookupEventArgs]
|
||||
$eventArgs
|
||||
)
|
||||
# powershell does not support run command with specific environment variables
|
||||
# but you must set global variables. so we are memorizing the current mode and the alias function will reset it later.
|
||||
$env:_PR_PWSH_ORIGIN_MODE=$env:_PR_MODE;
|
||||
$env:_PR_MODE='cnf';
|
||||
# powershell may search command with prefix 'get-' or '.\' first when this hook is hit, strip them
|
||||
$env:_PR_LAST_COMMAND=$commandName -replace '^get-|\.\\','';
|
||||
$eventArgs.Command = (Get-Command {});
|
||||
$eventArgs.StopSearch = $True;
|
||||
}}
|
||||
"#,
|
||||
initialize, alias
|
||||
)
|
||||
// usage with pwsh is limited as we cannot get arguments
|
||||
// furthermore there is recursion
|
||||
// initialize = format!(
|
||||
// r#"{}
|
||||
// $ExecutionContext.InvokeCommand.CommandNotFoundAction =
|
||||
// {{
|
||||
// param(
|
||||
// [string]
|
||||
// $commandName,
|
||||
// [System.Management.Automation.CommandLookupEventArgs]
|
||||
// $eventArgs
|
||||
// )
|
||||
// # powershell does not support run command with specific environment variables
|
||||
// # but you must set global variables. so we are memorizing the current mode and the alias function will reset it later.
|
||||
// $env:_PR_PWSH_ORIGIN_MODE=$env:_PR_MODE;
|
||||
// $env:_PR_MODE='cnf';
|
||||
// # powershell may search command with prefix 'get-' or '.\' first when this hook is hit, strip them
|
||||
// $env:_PR_LAST_COMMAND=$commandName -replace '^get-|\.\\','';
|
||||
// $eventArgs.Command = (Get-Command {});
|
||||
// $eventArgs.StopSearch = $True;
|
||||
// }}
|
||||
// "#,
|
||||
// initialize, alias
|
||||
// )
|
||||
}
|
||||
_ => {
|
||||
println!("Unsupported shell: {}", shell);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue