是否有适用于Mac的类似于posh-git的工具?

29

我刚刚发现了安装了posh-git模块的PowerShell,并且深深地喜欢上了它。我真的很希望在我的Mac上有类似的东西。是否存在这样的替代品?


1
PowerShell 可能自从这个问题被提出以来就已经适用于 Mac 了,所以现在的方法是按照说明安装 PowerShell,然后通过 PowerShellGet 安装 posh-git。https://github.com/dahlbyk/posh-git - Andrew Spencer
2个回答

43

有很多方法可以获得类似于 posh-git 的功能。

例如,安装 bash-completion 可以让你使用 <tab> 来自动完成 Git 命令。

一旦安装了 bash-completion,你可以将以下内容添加到你的 .bash_profile 中:

PS1='\u@\h \W$(__git_ps1 " (%s)")\$ '

这将在你的提示符中包含当前分支名称:

user@computer-name current-folder (branch-name)$

你也可以将以下代码(在这里找到)添加到你的.bash_profile中(在PS1之前):

export GIT_PS1_SHOWDIRTYSTATE=true
export GIT_PS1_SHOWUNTRACKEDFILES=true

这将在分支名称后添加标志以显示存储库的当前状态:

user@computer-name current-folder (branch-name *)$ #Repo has modified files
user@computer-name current-folder (branch-name +)$ #Repo has staged files
user@computer-name current-folder (branch-name %)$ #Repo has untracked files

你也可以通过以下命令启用Git着色:

git config --global color.ui auto


这太棒了,正是我所寻找的。 - Michael Brown
已安装Homebrew和bash-completion,但提供的PS1行生成“-sh: __git_ps1: command not found”错误。 - Jorge Orpinel Pérez
@JorgeOrpinel 你是否在你的.bash_profile中加载了bash完成脚本?确保按照安装bash-completionbrew给出的说明进行操作。你可以使用brew info bash-completion再次获取说明。 - redhotvengeance
这个命令行添加了类似于posh-git的详细信息,但没有应用任何颜色。 - Swazimodo
1
如果你遇到了 -sh: __git_ps1: command not found 错误,你需要下载 git-prompt.sh 脚本。请阅读脚本中的说明。另外一个帮助我设置这个的替代来源可以在这里找到。 - fortune
显示剩余4条评论

21

2
只需在我的机器上设置您的端口。太棒了,谢谢@lyze! - ThinkBonobo
我感觉自己又可以呼吸了...谢谢你! - DMac the Destroyer
太棒了!我在我的 Mac 上一直很想要这样的东西。 - Johnny Oshika
这在Windows的WSL中也能很好地运行。 - Johnny Oshika
同样适用于树莓派,非常惊人! - Johnny Oshika

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接