Powerline Prompt Too Long

I’ve been using Powerline to make my shell prompt and the status line in VIM show lots of useful details for years. Deep paths in shell prompts can be an issue but the way it trims them by default usually works fine. Things got ugly a while ago when the GIT branchnames I work on got long. I finally took the time to address it this weekend.

I use the Gitstatus segment to include details from GIT in my prompt and I use GitLab for my projects. GitLab’s process for creating branches from issues uses the issue’s ID and name, munged, to produce the branch name so we end up with some unnecessarily long names; i.e. 555_we_should_not_do_foo. Yes, there’s a way to edit the default but it takes an extra step and we don’t usually do it.

So, I decided to adjust Powerline. With the default Powerline from the usual repository for Ubuntu plus the Gitstatus add on, the /usr/share/powerline/conig_files/themes/shell/default_leftonly.json file is what’s controlling my shell prompt. I copied that file to ~/.config/powerline/themes/shell/default_leftonly.json so I could tweak things. I ended up adding args for the powerline_gitstatus.gitstatus and powerline.segments.shell.cwd segments.

{
  "segments": {
    "left": [
      ...
      {
        "function": "powerline_gitstatus.gitstatus",
        "priority": 40,
        "args": {
          "formats": {
            "branch": "\ue0a0 {0:.10}"
          }
        }
      },
      {
        "function": "powerline.segments.shell.cwd",
        "priority": 10,
        "args": {
          "use_path_separator" : true,
          "dir_shorten_len" : 3,
          "dir_limit_depth" : 2
        }
      },
      ...
    ]
  }
}

The branch string is passed used with Python’s string format() method. The default configs use {} but I adjusted it to {:.10} to it only show the first 10 characters of the branch name. That’s more than enough to get the leading issue number which is all I need usually.

The options under cwd helped get me the rest of the way toward when I wanted. use_path_separator set true means I get slashes instead of spaces and Powerline’s “arrows” between path elements. dir_shorten_len set to 3 means the names of dirctories above the current one get truncated to three characters and dir_limie_depth set to 2 means it only shows the current and parent directories.

I can use a 80-column terminal again now :)

comments powered by Disqus