bon now

ありのままの現実を書き殴る吐き溜め。底辺SEの備忘録。
Written by bon who just a foolish IT Engineer.

PowerlineをmacOS High Sierraに入れる

Created Date: 2018/10/29 00:46
Updated Date: 2023/11/05 03:00

まず今回の記事の前提として、TerminalではなくiTerm2を使ってのと、シェルはZshである点に注意してほしい。

powerlineいれる

参考サイト:
Installation on OS X — Powerline beta documentation

brewでやるとPython3が入るので、Pytohn2系をどうしても使わなければならないっていう人は、 pyenv をつかってなんとかしてほしい。

1
2
> brew install python
> pip install --user git+git://github.com/powerline/powerline

パスを通しつつPowerlineの設定を.zshrcに書く

1
2
3
4
5
vi ~/.zshrc

export PATH=$PATH:~/Library/Python/3.6/bin
powerline-daemon -q
. ~/Python/3.6/lib/python/site-packages/powerline/bindings/zsh/powerline.zsh

オリジナルのconfigを作る

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
vi ~/.config/powerline/themes/shell/mytheme.json

{
    "segments": {
        "left": [
      {
        "function": "powerline.segments.common.time.date"
      },
      {
        "function": "powerline.segments.common.time.date",
        "priority": 1,
        "name": "time",
        "args": {
          "format": "%H:%M",
          "istime": true
        }
      },
            {
                "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.segments.common.vcs.branch",
                "priority": 40
            },
            {
                "function": "powerline.segments.shell.cwd",
                "priority": 10
            },
            {
                "function": "powerline.segments.shell.jobnum",
                "priority": 20
            },
            {
                "function": "powerline.segments.shell.last_status",
                "priority": 10
      }
    ]
    }
}

ここまでだと出力されるPowerlineの表示に改行が入らずカレントディレクトリのパスが長くなると見づらいため、以下ファイルを修正する。

1
2
3
4
5
6
vi ~/Library/Python/3.6/lib/python/site-packages/powerline/bindings/zsh/powerline.zsh

# 以下の行に1行だけ改行を入れる
typeset -g PS1='$("$POWERLINE_COMMAND" $=POWERLINE_COMMAND_ARGS shell aboveleft '$add_args')
'
typeset -g RPS1='$("$POWERLINE_COMMAND" $=POWERLINE_COMMAND_ARGS shell right '$add_args')'

以上。

余談

Shellだけの見た目を変えたいのなら、 powerline-shellのほうがいいのかもしれない……。
GitHub - b-ryan/powerline-shell: A beautiful and useful prompt for your shell

local_offer
folder work