Docker machine name segment for Powerline

Some time ago I got several docker machines to use. I thought that it’d be nice to identify to which docker machine I’m connected at the moment. As far as I use Powerline status bar, a segment for it is the way to go. I didn’t find anything ready to use, so I had to create my own.

From the beginning I thought that I need to find or develop a proper segment in python, like powerline-taskwarrior which I created before. BTW, you can see it in the animation — it shows my current active task there and it’s id in green segment.

However, it turned out that there is much easier way to show docker machine name. This name is usually stored in DOCKER_MACHINE_NAME environment variable. There is a built-in segment to show any environment variable value by it’s name. It’s name powerline.segments.common.env.environment.

In my configuration it looks like this:

1
2
3
4
5
6
7
8
9
"right": [
  {
    "function": "powerline.segments.common.env.environment",
    "priority": 10,
    "args": {
      "variable": "DOCKER_MACHINE_NAME"
    }
  }
]

Super simple!