2

According to the documentary, powerline use ~/.config/powerline/config.json for configurations. Since I don't quite like the layout of $PS1 by default, I made some change in keyword cwd as following. However, the customization wasn't applied. Did I do something wrong? Generally, how to customize a segment in powerline?

{
    "powerline":{
        "segments":{
            "shell":{
                "cwd":{
                    "dir_shorten_len": 4,
                    "dir_limit_depth": 3
                }
            }
        }
    }
}
4

You need to modify one of the theme config files in config-directory/themes/ (presumably ~/.config/powerline/themes/ on your system)

One way to do it is to put something like this in config-directory/themes/shell/__main__.json

{
    "segment_data": {
        "cwd": {
            "args": {
                "dir_shorten_len": 4,
                "dir_limit_depth": 3
            }
        }
    }
}

That sets the default arguments for the cwd function when called from the shell extension, but you can still override with a different argument in the theme config file.

e.g., config-directory/themes/shell/default.json:

{
    "segments": {
        "left": [
            ...other-segments...
            {
                "function": "powerline.segments.shell.cwd",
                "priority": 10,
                "args": {
                    "dir_shorten_len": 1,
                    "dir_limit_depth": 5
                }
            }
        ],
        "right": [
            ...right-segments...
        ]
    }
}

Also, in addition to powerline.segments.shell.cwd, there is also the more general powerline.segments.common.env.cwd. For that function, you could put default args in config-directory/themes/powerline.json, which would affect not only the shell extension, but any others that use powerline.segments.common.env.cwd.

Note that calls to powerline.segments.shell.cwd still respect powerline.segments.common.env.cwd default args, unless overridden somewhere more specific.

3
  • Thanks. It works. And do you know some good material to learn about setting powerline properly?
    – Chong
    Mar 19 '16 at 16:50
  • 2
    I've just been reading the official docs (powerline.readthedocs.org/en/latest/index.html) and googling anything that's not clear in the docs, which aren't the easiest to follow unfortunately. That's how I came upon this post. At this point I'm considering switching back to vim-airline (github.com/vim-airline/vim-airline) and the agnoster zsh theme (gist.github.com/agnoster/3712874), which gives you something similar to powerline in vim/zsh at least.
    – Will Adams
    Mar 20 '16 at 9:40
  • 1
    Powerline has lots of cool features but it's a little too complicated (and a little slow) for something that just provides prompts. I like the idea of being able to write new segments in python, but I'm not sure if it's worth it.
    – Will Adams
    Mar 20 '16 at 9:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.