fix: pwsh: custom history log

This commit is contained in:
qwjyh 2022-12-05 01:48:04 +09:00
parent 57b4300bd6
commit 907253b097

View file

@ -33,13 +33,17 @@ Set-Alias whereis where.exe
# change window name # change window name
# save my history # save my history
$My_Pwsh_History = "$HOME\my_pwsh_history.txt" $My_Pwsh_History = "$HOME\my_pwsh_history.txt"
# shell starts
Write-Output "$(Get-Date -UFormat '+%Y-%m-%d %H:%M:%S') $env:COMPUTERNAME`:$PID [START]"
| Out-File -FilePath $My_Pwsh_History -Append -Encoding utf8
# save
function Invoke-Starship-PreCommand { function Invoke-Starship-PreCommand {
# window title # window title
$ParentFolder = Split-Path $PWD -Leaf $ParentFolder = Split-Path $PWD -Leaf
$host.ui.Write("`e]0; $ParentFolder `a") $host.ui.Write("`e]0; $ParentFolder `a")
# save log # save log
Write-Output "$(Get-Date -UFormat '+%Y-%m-%d %H:%M:%S') $env:COMPUTERNAME`:$PID [$Global:LASTEXITCODE] $(Get-History -Count 1)" Write-Output "$(Get-Date -UFormat '+%Y-%m-%d %H:%M:%S') $env:COMPUTERNAME`:$PID $PWD [$Global:LASTEXITCODE] $(Get-History -Count 1)"
| Out-File -FilePath $My_Pwsh_History -Append -Encoding utf8 | Out-File -FilePath $My_Pwsh_History -Append -Encoding utf8
} }
Invoke-Expression (&starship init powershell) Invoke-Expression (&starship init powershell)