恢复 Windows Github Powershell 快捷方式

恢复 Windows Github Powershell 快捷方式

我安装了适用于 Windows 的 Github(Win7 x64)。它还附带一个方便的快捷方式,允许启动针对 Git 优化的 Powershell 实例(当位于跟踪文件夹中时,它还会在提示中显示 git 文件状态等信息)。

我之前删除了那个快捷方式,现在想恢复它。我找到了它正在执行的脚本(app 文件夹中的 shell.ps1),但尝试运行它时出现了几个相当难看的错误,例如:

Set-Alias : The AllScope option cannot be removed from the alias 'cat'.
At C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1:11 char:10
+ set-alias <<<<  cat        get-content
    + CategoryInfo          : WriteError: (cat:String) [Set-Alias], SessionStateUnauthorizedAccessException
    + FullyQualifiedErrorId : AliasAllScopeOptionCannotBeRemoved,Microsoft.PowerShell.Commands.SetAliasCommand

我可以简单地使用替代方案(例如 msys shell),但我真的很好奇为什么 PowerShell 版本不起作用。

答案1

错误提示您的配置文件与 shell.ps1 发生冲突。此错误可能是因为您cat在配置文件中定义了别名,而它试图覆盖shell.ps1

我会遵循该脚本本身的建议:

Generally you would run this from your Powershell Profile like this:

. (Resolve-Path "$env:LOCALAPPDATA\GitHub\shell.ps1")

无论如何:这个的核心不是这个脚本,而是随附的模块,因此请确保在您的个人资料中添加一行:

Import-Module $env:posh_git

是处理提示和其他元素的部分。

如果您想避免使用配置文件 - 只需使用-noprofileswitch on powershell.exe

答案2

查看答案https://stackoverflow.com/q/17457182/95580;以下命令对我有用:

%LocalAppData%\GitHub\GitHub.appref-ms --reinstall-shortcuts

答案3

好吧,我设法找到了一个解决方案,通过在我的个人资料中手动加载我的 posh-git(该Import-Module $env:posh_git命令不起作用并且抛出了一个关于 $env:posh_git 不是模块的严重错误):

. (Resolve-Path "$env:LOCALAPPDATA\GitHub\shell.ps1")
. (Resolve-Path "$env:LOCALAPPDATA\GitHub\PoshGit_e0fc5e56ff55708a890f408f03656f758fa0ba8a\profile.example.ps1")

...并通过注释掉位于 ( C:\Windows\System32\WindowsPowerShell\v1.0) 中的默认配置文件中的所有默认别名。即使没有这最后的更改,它也正常工作,但 Poweshell 在启动时一直显示大量错误。奇怪的是,诸如cat和之类的别名ls仍然有效。

相关内容