かわいいプロンプト (*'_')$
最終更新日
公開日
?kawaii=true
目次
Bashの場合
$HOME/.bashrc
に以下を追加する.
# ~/.bashrc
# 元々の.bashrcの内容がここら辺にあるとして
function custom_ps1() {
if [ $? -eq 0 ]; then
local face="\e[36m(*'_')\e[m"
else
local face="\e[33m(*;_;)\e[m"
fi
PS1='\[\033[32m\]'
PS1+='\u'
PS1+='\[\033[0m\]'
PS1+=':'
PS1+='\[\033[36m\]'
PS1+='\w'
PS1+='\[\033[33m\]'
PS1+='$(__git_ps1 "[%s]")'
PS1+='\[\033[0m\]'
PS1+="${face}\$ "
export PS1
}
PROMPT_COMMAND=custom_ps1
実行例
ubuntu:~/hoge/piyo[main](*'_')$ errorCMD
errorCMD: command not found
ubuntu:~/hoge/piyo[main](*;_;)$ echo "success"
success
ubuntu:~/hoge/piyo[main](*'_')$ cd $HOME
ubuntu:~(*'_')$
Zshの場合
$HOME/.zshrc
に以下を追加する.
# ~/.zshrc
# 元々の.zshrcの内容がここら辺にあるとして
# prompt
setopt prompt_subst
# %(?.succeeded.failed)
PROMPT_FACE="%(?.(*'_').(*;_;%))"
PROMPT_FACE_COLOR="%(?.%F{green}.%F{red})"
PROMPT_SYM_BG_COLOR="%(?.%{${reset_color}%}.%{$bg[red]%})"
PROMPT=$'\n'"%F{green}%n%f($(arch)):%~${PROMPT_FACE_COLOR}${PROMPT_FACE}%f ${PROMPT_SYM_BG_COLOR}%#%{${reset_color}%} "
RPROMPT="${vcs_info_msg_0_}"
# right-side prompt
# vcs
autoload -Uz vcs_info
zstyle ':vcs_info:git:*' check-for-changes true
zstyle ':vcs_info:git:*' stagedstr "+"
zstyle ':vcs_info:git:*' unstagedstr "-"
zstyle ':vcs_info:*' formats "%F{cyan}%c%u[%b]%f"
zstyle ':vcs_info:*' actionformats '%F{cyan}[%b|%a]%f'
precmd_vcs() {
vcs_info
RPROMPT="${vcs_info_msg_0_}"
}
precmd_functions+=( precmd_vcs )
実行例
mbp:~/hoge/piyo(*'_')$ errorCMD
zsh: command not found: errorCMD
mbp:~/hoge/piyo(*;_;)$ echo "success"
success
mbp:~/hoge/piyo(*'_')$ cd $HOME
mbp:~(*'_')$
コマンドの実行結果に応じて顔と色が変わる.いいね :+1: