【问题标题】:Configure powerline to display git status配置 powerline 以显示 git 状态
【发布时间】:2020-02-17 07:03:41
【问题描述】:

我已经安装了 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,但我不知道该放在哪里。

如果有人能指导我完成这件事,我将不胜感激。

【问题讨论】:

    标签: powerline


    【解决方案1】:

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

    创建一个包含~/.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"
        }
      }
    }
    
    

    【讨论】:

      【解决方案2】:

      我也费了很大劲才找到正确的配置。一旦做对了,我写了这个Article 指导一个人完成电力线的设置。包括安装正确的字体和配置 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
      

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

      【讨论】:

      • 如果链接过期,您的回答对任何人都没有帮助。请将最重要的信息编辑到您的答案中,以便在没有链接的情况下也有用。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      • 1970-01-01
      • 2017-10-29
      • 2014-11-11
      • 1970-01-01
      • 2012-12-23
      • 2021-09-12
      相关资源
      最近更新 更多