使用pip install thefuck -i https://pypi.tuna.tsinghua.edu.cn/simple
安装这个thefuck工具,选择清华镜像源
然后在PowerShell的$ProFile文件中添加环境变量,并定义一个函数。
# fuck
$env:PYTHONIOENCODING='utf-8'
function Invoke-TheFuck {
$history = (Get-History -Count 1).CommandLine;
if (-not [string]::IsNullOrWhiteSpace($history)) {
$fuck = $(thefuck $args $history);
if (-not [string]::IsNullOrWhiteSpace($fuck)) {
if ($fuck.StartsWith("echo")) { $fuck = $fuck.Substring(5); }
else { Invoke-Expression "$fuck"; }
}
}
}
Set-Alias -name "fuck" -value "Invoke-TheFuck"
# 来自:https://github.com/nvbn/thefuck/issues/536#issuecomment-350558359
大功告成
powershell encoding warning on every ‘fuck’ execution · Issue #514 · nvbn/thefuck (github.com)