Skip to content

Instantly share code, notes, and snippets.

@ecormaksin
Last active March 25, 2020 14:50
Show Gist options
  • Save ecormaksin/5ddf6068da12c6dbc47ce99006151489 to your computer and use it in GitHub Desktop.
Save ecormaksin/5ddf6068da12c6dbc47ce99006151489 to your computer and use it in GitHub Desktop.
# 以下を`/etc/bashrc_customize_ps`などで保存し、各ユーザーの`~/.bashrc`に`. /etc/bashrc_customize_ps`を追加後、`source ~/.bashrc`で反映
function ps1_ls() {
[[ $_PWD == $PWD ]] || { _PWD=$PWD; ls; }
}
function ps1_newline() {
if [[ -z "${PS1_NEWLINE_LOGIN}" ]]; then
PS1_NEWLINE_LOGIN=true
else
printf '\n'
fi
}
function ps1_customize() {
ps1_ls
ps1_newline
}
function ps1_git_branch() {
git symbolic-ref HEAD 2>/dev/null >/dev/null &&
echo "($(git symbolic-ref HEAD 2>/dev/null | sed 's/^refs\/heads\///'))"
}
PROMPT_COMMAND=ps1_customize
if [ -n "$ps1_git_branch"]; then
PS1_GIT_BRANCH='\[\e[1;33m\]$(ps1_git_branch "(%s)")\[\e[0m\]'
else
PS1_GIT_BRANCH=
fi
# ※以下の行は管理者の場合もあるので、それぞれに記載した方がよいかもしれない。
export PS1="\[\e[1;32m\]\u@\h \[\e[36m\]\D{%y/%m/%d %H:%M:%S}\[\e[0m\]$PS1_GIT_BRANCH \w\n\$ "
# 管理者用
export PS1="\[\e[1;31m\]\u@\h \[\e[36m\]\D{%y/%m/%d %H:%M:%S}\[\e[0m\]$PS1_GIT_BRANCH \w\n# "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment