3

我已经安装了 powerline 并且默认配置显示了我当前的 git 分支。我还想显示该分支的状态(暂存/未暂存文件的数量等......)我发现powerline-gitstatus似乎可以完成这项工作,但我不知道如何配置它..

我已按照此处提供的说明将显示在https://github.com/jaspernbrouwer/powerline-gitstatus#configuration的配置条目复制到~/.config/powerline/themes/shell/default.json其中。

下一节说明

然后,您可以通过将 Gitstatus 段添加到您的段配置来激活它,例如在 .config/powerline/themes/shell/default.json 中:

{  
   "function": "powerline_gitstatus.gitstatus",  
   "priority": 40  
}

该文件 ( .config/powerline/themes/shell/default.json) 不存在,因此我创建了它,添加了该条目,然后重新启动了我的 shell。虽然它没有达到预期的效果。我想也许我应该添加相同的条目,.config/powerline/config.json但我不知道该放在哪里。

如果有人可以指导我完成此操作,我将不胜感激。

4

2 回答 2

9

对我来说,default主题根本没有显示任何 VCS 信息,所以我切换到default_leftonly. 使用该主题,以下内容对我有用:

确保您已安装 git_status python 模块:

python3 -m pip install powerline_gitstatus

创建一个~/.config/powerline/colorschemes/default.json包含

{
  "groups": {
    "gitstatus":                 { "fg": "gray8",           "bg": "gray2", "attrs": [] },
    "gitstatus_branch":          { "fg": "gray8",           "bg": "gray2", "attrs": [] },
    "gitstatus_branch_clean":    { "fg": "green",           "bg": "gray2", "attrs": [] },
    "gitstatus_branch_dirty":    { "fg": "gray8",           "bg": "gray2", "attrs": [] },
    "gitstatus_branch_detached": { "fg": "mediumpurple",    "bg": "gray2", "attrs": [] },
    "gitstatus_tag":             { "fg": "darkcyan",        "bg": "gray2", "attrs": [] },
    "gitstatus_behind":          { "fg": "gray10",          "bg": "gray2", "attrs": [] },
    "gitstatus_ahead":           { "fg": "gray10",          "bg": "gray2", "attrs": [] },
    "gitstatus_staged":          { "fg": "green",           "bg": "gray2", "attrs": [] },
    "gitstatus_unmerged":        { "fg": "brightred",       "bg": "gray2", "attrs": [] },
    "gitstatus_changed":         { "fg": "mediumorange",    "bg": "gray2", "attrs": [] },
    "gitstatus_untracked":       { "fg": "brightestorange", "bg": "gray2", "attrs": [] },
    "gitstatus_stashed":         { "fg": "darkblue",        "bg": "gray2", "attrs": [] },
    "gitstatus:divider":         { "fg": "gray8",           "bg": "gray2", "attrs": [] }
  }
}

创建一个~/.config/powerline/themes/shell/default_leftonly.json包含

{
  "segments": {
    "left": [
      {
        "function": "powerline.segments.common.net.hostname",
        "priority": 10
      },
      {
        "function": "powerline.segments.common.env.user",
        "priority": 30
      },
      {
        "function": "powerline.segments.common.env.virtualenv",
        "priority": 50
      },
      {
        "function": "powerline_gitstatus.gitstatus",
        "priority": 40
      },
      {
        "function": "powerline.segments.shell.cwd",
        "priority": 10
      },
      {
        "function": "powerline.segments.shell.jobnum",
        "priority": 20
      },
      {
        "function": "powerline.segments.shell.last_pipe_status",
        "priority": 10
      }
    ]
  }
}

并创建一个~/.config/powerline/config.json包含

{
  "ext": {
    "shell": {
      "theme": "default_leftonly"
    }
  }
}

于 2019-11-17T11:47:13.240 回答
3

我也很努力地找出正确的配置。一旦做对了,我写了这篇文章来指导一个人完成电力线的设置。包括安装正确的字体和配置 Visual Studio Code。我希望它有所帮助。

总结如下:

创建目录:

mkdir ~/.config/powerline
mkdir ~/.config/powerline/colorschemes   
mkdir ~/.config/powerline/themes
mkdir ~/.config/powerline/themes/shell

复制默认配置文件(可能路径有另一个 python 版本):

cp ~/.local/lib/python3.7/site-packages/powerline/config_files/colorschemes/default.json ~/.config/powerline/colorschemes/
cp ~/.local/lib/python3.7/site-packages/powerline/config_files/colorschemes/solarized.json ~/.config/powerline/colorschemes/
cp ~/.local/lib/python3.7/site-packages/powerline/config_files/themes/shell/default.json ~/.config/powerline/themes/shell/

将以下行添加到 ~/.config/powerline/colorschemes 中的两个文件中

这些行需要添加到“组”部分,并且在添加行之前不要忘记最后一行中的逗号。

"gitstatus":                 { "fg": "gray8",           "bg": "gray2", "attrs": [] },
"gitstatus_branch":          { "fg": "gray8",           "bg": "gray2", "attrs": [] },
"gitstatus_branch_clean":    { "fg": "green",           "bg": "gray2", "attrs": [] },
"gitstatus_branch_dirty":    { "fg": "gray8",           "bg": "gray2", "attrs": [] },
"gitstatus_branch_detached": { "fg": "mediumpurple",    "bg": "gray2", "attrs": [] },
"gitstatus_tag":             { "fg": "darkcyan",        "bg": "gray2", "attrs": [] },
"gitstatus_behind":          { "fg": "gray10",          "bg": "gray2", "attrs": [] },
"gitstatus_ahead":           { "fg": "gray10",          "bg": "gray2", "attrs": [] },
"gitstatus_staged":          { "fg": "green",           "bg": "gray2", "attrs": [] },
"gitstatus_unmerged":        { "fg": "brightred",       "bg": "gray2", "attrs": [] },
"gitstatus_changed":         { "fg": "mediumorange",    "bg": "gray2", "attrs": [] },
"gitstatus_untracked":       { "fg": "brightestorange", "bg": "gray2", "attrs": [] },
"gitstatus_stashed":         { "fg": "darkblue",        "bg": "gray2", "attrs": [] },
"gitstatus:divider":         { "fg": "gray8",           "bg": "gray2", "attrs": [] }

接下来,编辑文件 ~/.config/powerline/themes/shell/default.json

改变:

"function": "powerline.segments.shell.jobnum",
"priority": 20

至:

"function": "powerline_gitstatus.gitstatus",
"priority": 40

最后,重启 powerline 守护进程:

powerline-daemon --replace

之后,GIT 特定信息应该在 powerline 中可见。

于 2020-04-30T14:19:55.993 回答