在PowerShell中使用thefuck

使用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)

It doesn’t work on Win10 powershell after put alias in $profile · Issue #536 · nvbn/thefuck (github.com)

Powershell, The term ‘thefuck’ is not recognized as the name of a cmdlet · Issue #809 · nvbn/thefuck (github.com)

知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议
上一篇
下一篇