Last active
January 15, 2019 08:01
-
-
Save gotnix/6896891 to your computer and use it in GitHub Desktop.
Bash Prompt, RHEL/CentOS 的路径为 /etc/profile.d/file_name.sh,openSUSE 不同。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # local6.* /var/log/bash.log | |
| # | |
| # 历史文件的行数 | |
| readonly HISTFILESIZE=5000 | |
| # history 命令显示的行数 | |
| readonly HISTSIZE=500 | |
| # 历史命令的时间格式 | |
| readonly HISTTIMEFORMAT='%F %T ' | |
| # 连续重复的历史命令只记录一条, | |
| # erasedups 可以清除文件中所有重复的历史命令 | |
| readonly HISTCONTROL=ignoredups | |
| # 追加方式记录历史命令,防止多个会话之间互相覆盖。 | |
| # 实时追加需要在 PROMPT_COMMAND 中有 `history -a' | |
| shopt -s histappend | |
| # 历史命令写入 syslog | |
| readonly PROMPT_COMMAND='logger -p local6.notice -t bash -i "USER=$USER,PPID=$PPID,FROM=$SSH_CLIENT,PWD=$PWD,COMMAND=$(history 1 | { read p d t c; echo $c; }) "' | |
| alias vi='/usr/bin/vim' | |
| alias grep='grep --color=auto' | |
| alias shutdown='shutdown -k now' | |
| alias reboot='reboot -w' | |
| alias halt='halt -w' | |
| alias poweroff='poweroff -w' | |
| alias rz='rz --binary --escape --rename --bufsize=64k --zmodem' | |
| alias sz='sz --binary --rename --bufsize=64k --zmodem' | |
| unset PS1 EDITOR VISUAL TIME_STYLE | |
| EDITOR="/usr/bin/vim" | |
| VISUAL=${EDITOR:=/usr/bin/vim} | |
| TIME_STYLE='long-iso' | |
| WAN_IP=$(/sbin/ip addr show | awk --re-interval -F ' ' '$NF ~ /e(m1|th0)/ {gsub(/\/[0-9]{1,2}/,"",$2); {printf "%s ", $2}}') | |
| if [[ ${UID} = 0 ]] ; then | |
| PS1='\n[\[\e[1;31m\]\u\[\e[0m\]@\[\e[1;35m\]${WAN_IP}\[\e[0m\]:\[\e[1;36m\]\w\[\e[0m\]] \[\e[1;34m\]{ ?:$?, !:\!, %:\j, T:\t }\[\e[0m\]\n\[\e[1;31m\]\$\[\e[0m\] \[\e[0;32;1m\]»\[\e[0m\] ' | |
| else | |
| PS1='\n[\[\e[1;33m\]\u\[\e[0m\]@\[\e[1;35m\]${WAN_IP}\[\e[0m\]:\[\e[1;36m\]\w\[\e[0m\]] \[\e[1;34m\]{ ?:$?, !:\!, %:\j, T:\t }\[\e[0m\]\n\[\e[1;33m\]\$\[\e[0m\] \[\e[0;32;1m\]»\[\e[0m\] ' | |
| fi | |
| export PATH PS1 EDITOR VISUAL TIME_STYLE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment