2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Vim/Neovim】powerline-shell の導入

Posted at

インストール

pip経由でインストールする。

terminal
pip3 install powerline-shell

インストールしたら、
.zshrcに下記のスクリプトを記入
(ドキュメントの設定をそのまま利用)

.zshrc
function powerline_precmd() {
    PS1="$(powerline-shell --shell zsh $?)"
}

function install_powerline_precmd() {
  for s in "${precmd_functions[@]}"; do
    if [ "$s" = "powerline_precmd" ]; then
      return
    fi
  done
  precmd_functions+=(powerline_precmd)
}

if [ "$TERM" != "linux" ]; then
    install_powerline_precmd
fi

設定をカスタマイズする

terminal
mkdir -p ~/.config/powerline-shell && \
powerline-shell --generate-config > ~/.config/powerline-shell/config.json

デフォルトだと、下記の設定になっている。

config.json
{
  "segments": [
    "virtual_env",
    "username",
    "hostname",
    "ssh",
    "cwd",
    "git",
    "hg",
    "jobs",
    "root"
  ]
}

こんなにいらないので、
少し変更してみた。

config.json
{
  "segments": [
    "cwd",
    "git",
    "ruby_version",
    "node_version",
    "time"
  ]
}

cwdが現在のパス、
あとはその名の通りである。

Screen Shot 2022-09-20 at 22.33.17.png

デザインテーマを変えるときは、
それを読み込ませる。

config.json
{
  "segments": [
    "cwd",
    "git",
    "ruby_version",
    "node_version",
    "time"
  ],
  "theme": "~/Myapp/powerline-shell/powerline_shell/themes/my_theme.py"
}

my_theme.pyはドキュメントのを借りて、
試しにこんな感じにしてみる。

my_theme.py
class DefaultColor(object):
    """
    This class should have the default colors for every segment.
    Please test every new segment with this theme first.
    """
    # RESET is not a real color code. It is used as in indicator
    # within the code that any foreground / background color should
    # be cleared
    # URL:"https://www.ditig.com/256-colors-cheat-sheet"
    RESET = -1

    USERNAME_FG = 250
    USERNAME_BG = 240
    USERNAME_ROOT_BG = 124

    HOSTNAME_FG = 250
    HOSTNAME_BG = 238

    HOME_SPECIAL_DISPLAY = True
    HOME_BG = 52  # blueish
    HOME_FG = 0  # white
    PATH_BG = 18  # dark grey
    PATH_FG = 250  # light grey
    CWD_FG = 254  # nearly-white grey
    SEPARATOR_FG = 244

    READONLY_BG = 124
    READONLY_FG = 254

    SSH_BG = 166  # medium orange
    SSH_FG = 254

    REPO_CLEAN_BG = 148  # a light green color
    REPO_CLEAN_FG = 0  # black
    REPO_DIRTY_BG = 161  # pink/red
    REPO_DIRTY_FG = 15  # white

    JOBS_FG = 39
    JOBS_BG = 238

    CMD_PASSED_BG = 236
    CMD_PASSED_FG = 15
    CMD_FAILED_BG = 161
    CMD_FAILED_FG = 15

    SVN_CHANGES_BG = 148
    SVN_CHANGES_FG = 22  # dark green

    GIT_AHEAD_BG = 240
    GIT_AHEAD_FG = 250
    GIT_BEHIND_BG = 240
    GIT_BEHIND_FG = 250
    GIT_STAGED_BG = 22
    GIT_STAGED_FG = 15
    GIT_NOTSTAGED_BG = 130
    GIT_NOTSTAGED_FG = 15
    GIT_UNTRACKED_BG = 52
    GIT_UNTRACKED_FG = 15
    GIT_CONFLICTED_BG = 9
    GIT_CONFLICTED_FG = 15

    GIT_STASH_BG = 221
    GIT_STASH_FG = 0

    VIRTUAL_ENV_BG = 35  # a mid-tone green
    VIRTUAL_ENV_FG = 00

    BATTERY_NORMAL_BG = 22
    BATTERY_NORMAL_FG = 7
    BATTERY_LOW_BG = 196
    BATTERY_LOW_FG = 7

    AWS_PROFILE_FG = 39
    AWS_PROFILE_BG = 238

    TIME_FG = 250
    TIME_BG = 238


class Color(DefaultColor):
    """
    This subclass is required when the user chooses to use 'default' theme.
    Because the segments require a 'Color' class for every theme.
    """
    pass

Screen Shot 2022-09-20 at 22.39.50.png

少し設定をいじってみた

my_theme.py
from powerline_shell.themes.default import DefaultColor


class Color(DefaultColor):
    HOME_SPECIAL_DISPLAY = False
    PATH_FG = 250
    PATH_BG = 0
    CWD_FG = 9
    SEPARATOR_FG = 19

    CMD_PASSED_FG = 101
    CMD_PASSED_BG = 210
    CMD_FAILED_FG = 140
    CMD_FAILED_BG = 111

    TIME_FG = 0
    TIME_BG = 250

Screen Shot 2022-09-20 at 22.59.40.png

色の設定は要改善といったところだが、
永遠に終わらなそうなので、一旦保留で。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?