0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

zsh の Powerlevel10k で、プロンプトにホスト名を追加する

Posted at

契機

複数のホストを何台も ssh で入っていると、どこへログインしているかわからなくなることがある。zsh の Powerlevel10k だと、右側に「ユーザ名@ホスト名」が表示されるが遠いので見難い。
コマンドを入力する左側へ表示させたい。

image.png

変更箇所

左側に表示させたいんだけどーー。と思って眺めているとそれっぽいのがあった。

.p10k.zsh
  typeset -g POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(
    # =========================[ Line #1 ]=========================
    os_icon                 # os identifier
    dir                     # current directory
    vcs                     # git status
    # =========================[ Line #2 ]=========================
    newline                 # \n
    # prompt_char           # prompt symbol
  )

ここにホスト名を追加したらいいじゃぁないですか。host を追加。

.p10k.zsh
  typeset -g POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(
    # =========================[ Line #1 ]=========================
    os_icon                 # os identifier
    host                    # hostname 👈 追加
    dir                     # current directory
    vcs                     # git status
    # =========================[ Line #2 ]=========================
    newline                 # \n
    # prompt_char           # prompt symbol
  )

source .zsh するといい感じ?
image.png

色とかアイコンを変更したいなということで context の上あたりに設定を追加。
細かい内容は context のところを参照。

.p10k.zsh
  ##################################[ host: hostname ]##########################
########
  typeset -g POWERLEVEL9K_HOST_FOREGROUND=123
  typeset -g POWERLEVEL9K_HOST_BACKGROUND=30
  typeset -g POWERLEVEL9K_HOST_TEMPLATE='%m'

  typeset -g POWERLEVEL9K_HOST_VISUAL_IDENTIFIER_EXPANSION='💻'

  ##################################[ context: user@hostname ]##################
################

再度 source .zsh。うん、良いですね。
image.png

完成!
なんか、画像が減色されて色がわかりにくいですねぇ...orz

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?