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

ターミナルのコマンドプロンプト(派手系)

Posted at

ターミナルのプロンプトのメモです。特徴は下記。

  • 表示項目: ユーザー名、ホスト名、ディレクトリ名、ブランチ名、仮想環境名
  • カラーリング: 明るい系の黄色、緑、青
  • 目的: 疲れた時でもどのホストのどこで何してるか一目で理解できるようにする

イメージ画像

image.png

.bashrc

PS1='\[\e[1;36m\]$(__git_ps1 "(%s)")\[\e[0;32m\]\u\[\e[1;32m\]@\h\[\e[1;33m\]:\W\[\e[00m\]\$ '

.zshrc

長くなった。

# git情報
autoload -Uz vcs_info
zstyle ':vcs_info:git:*' formats '(%b)'
zstyle ':vcs_info:*' enable git

# コマンド実行前に情報更新
precmd () {
  # 1行目にカレントディレクトリ。プロンプトは2行目
  local left='%F{045}${vcs_info_msg_0_}%f%F{034}%n%f%F{047}%B@%m%b%f:%F{226}%~%f'

  # ブランチ名
  vcs_info

  # Python venv
  VIRTUAL_ENV_DISABLE_PROMPT=1
  if [[ -n "$VIRTUAL_ENV" ]]; then
    venv="($(basename $VIRTUAL_ENV)) "
  else
    venv=""
  fi

  print -P $left
}

# 256非対応なターミナル用プロンプト
export PROMPT="${vcs_info_msg_0_}%n@%m:%2~%#"

# 256対応版
if [[ "$TERM" == *-256color || "$TERM" == "xterm-color" ]]; then
  PROMPT='%B%F{214}${venv}%f%b%# '
  RPROMPT='%F{248}%D{%Y/%m/%d} %*%f' # 右端に日時
fi
0
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
0
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?