修改 mysql/oracle/bash/vimrc/cmd 提示符格式与颜色

(1)修改mysql提示符:

MySQL 客户端的默认提示符是 "mysql>",基本上没什么实际作用。其实可以修改这个提示符,让它显示一些有用的信息,例如当前所在的数据库等。修改方法有四种,其中前两种只对当前连接有效,后两种则对所有连接有效。

我的建议:vi /etc/my.cnf

[mysql]
prompt=\\u@\\h: \\d \\r:\\m:\\s>

效果:

mysql -uroot -proot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.22-log Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

root@localhost : (none) 07:15:23>use mysql
Database changed
root@localhost : mysql 07:15:30>
root@localhost : mysql 07:16:52>
 1、连接客户端时通过参数指定。

mysql --prompt="(\u@\h) [\d]> "  

 这样提示符就会变成 (user@host) [database]>

还有更多可以可以参考官方文档 4.5.1.2. mysql Commands

 2、连接上客户端后,通过 prompt 命令修改。

prompt (\u@\h) [\d]>  

 3、在 MySQL 的配置文件中配置。

[mysql]  

prompt=(\\u@\\h) [\\d]>\\_  

 4、通过环境变量配置。

export MYSQL_PS1="(\u@\h) [\d]> "  

  其中\h表示主机而\d表示数据库,更多设置如下(以下摘自MySQL手册) 

 \v  服务器版本 

\d  当前的数据库 

\h  服务器主机 

\p  当前的TCP/IP端口或套接字文件 

\u  你的用户名 

\U  你的全user_name@host_name账户名 

\\  ‘\’反斜线字符 

\n  新行字符 

\t  Tab字符 

\   空格(反斜线后面的空格) 

\_  空格 

\R  当前的时间,24-小时军用时间(0-23) 

\r  当前的时间,标准12-小时(1-12) 

\m  当前时间的分钟 

\y  当前的年,两位 

\Y  当前的年,四位 

\D  当前的日期 

\s  当前时间的秒 

\w  当前周的天,3字符格式(Mon,T ,...) 

\P  am/pm 

\o  当前的月,数字格式 

\O  当前的月,3字符格式(Jan,Feb,...) 

\c  随发出的每个语句递增的计数 

\S  分号 

\'  单引号 

\"  双引号

以上内容在window及linux环境下测试通过,请放心使用。

REF:

http://renial.iteye.com/blog/773675

http://blog.163.com/yang_jianli/blog/static/1619900062011283527540/

(2)oracle提示符修改:

修改 C:\oracle\product\11.2.0\dbhome\sqlplus\admin\glogin.sql

SET SQLPROMPT "_USER'@'_CONNECT_IDENTIFIER> " 
set serveroutput on
--显示当前时间
set time on 
--显示语句执行时间
set timing on  
--DEFINE _EDITOR=vim
set linesize 140

效果:

21:36:57 SCOTT@orcl> select * from test1 minus select * from test2;

        ID NAME
---------- ----------
        11 dongruan
       111    yg

REF: http://blog.csdn.net/tianlesoftware/article/details/6412769

(3)修改 linux bash shell vimrc 提示符:

请参考:http://www.linuxfocus.org/ChineseGB/May2004/article335.shtml

ip2=`ip a 2>/dev/null|grep 'eth0$'|grep -Po '(\d{1,3}.\d{1,3})(?=/)'`
ip2=`ip a 2>/dev/null|grep 'eth0$'|grep -Po '((\d{1,3}.){3}\d{1,3})(?=/)'`
alias june='eval "PS1=\"\[\e[36;1m\]\u\[\e[0m\]@\[\e[33;1m\]\h\[\e[40;35;9m $ip2 \e[0m\]\e[40;34;1m\t \e[0m\[\e[31;1m\]\w \[\e[0m\]>\n\""'

  

vimrc 配置范例:

https://github.com/acumon/misc/blob/master/.vimrc

https://github.com/joedicastro/dotfiles/tree/master/vim

man page 颜色范例:

(1)配色 1:

export LESS_TERMCAP_mb=$'\e[01;31m'
export LESS_TERMCAP_md=$'\e[01;35m'
export LESS_TERMCAP_me=$'\e[0m'
export LESS_TERMCAP_se=$'\e[0m'
export LESS_TERMCAP_so=$'\e[01;33m'
export LESS_TERMCAP_ue=$'\e[0m'
export LESS_TERMCAP_us=$'\e[04;36m'

(2)配色 2:

export LESS_TERMCAP_mb=$'\E[01;31m'
export LESS_TERMCAP_md=$'\E[01;31m'
export LESS_TERMCAP_me=$'\E[0m'
export LESS_TERMCAP_se=$'\E[0m'
export LESS_TERMCAP_so=$'\E[01;44;33m'
export LESS_TERMCAP_ue=$'\E[0m'
export LESS_TERMCAP_us=$'\E[01;32m'

.bashrc 完整范例:

# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

export LESS_TERMCAP_mb=$'\E[01;31m'
export LESS_TERMCAP_md=$'\E[01;31m'
export LESS_TERMCAP_me=$'\E[0m'
export LESS_TERMCAP_se=$'\E[0m'
export LESS_TERMCAP_so=$'\E[01;44;33m'
export LESS_TERMCAP_ue=$'\E[0m'
export LESS_TERMCAP_us=$'\E[01;32m'
export HISTSIZE=5000
export HISTTIMEFORMAT='[%F %T] '
shopt -s histappend
export PROMPT_COMMAND=
export EDITOR=vim
export LANG=zh_CN.utf8
export PATH=$PATH:.:/opt/soft/python-2.7.11/bin

IP=`/sbin/ip a 2>/dev/null|grep -iE '(em1|eth0)$'|grep -Po '((\d{1,3}.){3}\d{1,3})(?=/)'`
#HOST_NAME=dop_online${IP##*.}
. .hostname
#alias june='eval "PS1=\"\[\e[36;1m\]\u\[\e[0m\]@\[\e[33;1m\]\h\[\e[40;35;9m $ip \e[0m\]\e[40;34;1m\t \e[0m\[\e[31;1m\]\w \[\e[0m\]>\n\""'
#export PS1='[\u@\h \W]\$'
export PS1="\[\e[36;1m\]\u\[\e[0m\]@\[\e[33;1m\]$HOST_NAME\[\e[40;35;9m $IP \e[0m\]\e[40;34;1m\t \e[0m\[\e[31;1m\]\w \[\e[0m\]>\n"

alias rp='realpath'
alias grep='grep --color'
alias ls='ls --color=tty'
alias vi='vim'
alias cmd='cd /opt/script/rpcMonitor && python exec_cmd.py'
alias lh='ls -ld `pwd`/.[^.]*'

#export KRB5CCNAME=/tmp/krb5cc_pub_$$
#trap kdestroy 0 1 2 3 5 15
kinit -k -t /etc/krb5.keytab

myScp(){
    [[ $1 == "" ]] || [[ $2 == "" ]] && echo "请输入源文件与目标文件路径,如:myScp ~/a.txt /work" && return
    for ip in `cat ~/.ip_list`
    do
        echo -e "\n\n==========>>>>>>>>>>>>$ip:"
        rsync -avz $1 work@$ip:$2
    done
}

#baseDir=/root/tmp
#cd $baseDir
#userDir=`echo $SSH_CLIENT|awk '{print $1}'`
changeDir(){
    echo "--------------------------------------------------------------------"
    echo -e "\e[41;37;1m 欢迎登录,系统使用注意事项如下:  \e[0m" 
    echo -e "\e[41;37;1m 1、第一次登录请在 /home/work 下新建自己名字的目录(比如 mkdir -p ~/your_name ),私人文件请都放在自己的目录下。\e[0m" 
    echo -e "\e[41;37;1m 2、应用、服务请部署到 /opt 下对应的目录,比如 web soft script log 等等。\e[0m" 
    echo -e "\e[41;37;1m 3、由于一台机器会多人使用,请勿随意放置文件、安装程序,有需要请联系 your_name 统一规划。\e[0m" 
    echo "--------------------------------------------------------------------"
}
[[ $- == *i* ]] && changeDir

(4)修改 windows cmd 提示符:

新建 prompt 环境变量,具体含义 help prompt

具体效果步骤请参考:

http://hi.baidu.com/leejun_2005/item/0e29f4bad4bca5a0ebba9373

http://hi.baidu.com/leejun_2005/item/4459eb7a2c314e3b70442353

(5)bash color 详解

Escape sequences

You’ve probably seen things like \e[32m or \x1b[1;31m. These are ANSI escape codes used for defining a color. All ANSI escape sequences start with, well, ESC. There’re several ways of encoding an ESC:

Shell\e
ASCII Hex\0x1B
ASCII Oct\033

So \x1b[31;4m\e[31;4m and \033[31;4m are different ways to write the same sequence. Let’s look at the structure of this sequence.

\x1b[ is a Control Sequence Introducer that consists of hexadecimal ASCII ESC character code and a [.

31;4 is a list of instructions separated by ;. Usually this list is formatted as follows:

[<PREFIX>];[<COLOR>];[<TEXT DECORATION>]

For example 31;4 means “no prefix, color - red, underline”. <PREFIX> is used for 256 color mode. More on color modes later.

Finally m indicates the end of control sequence so terminal would know not to interpret text after mas a color code.

The following command should print “hello” in red underscore text:

> echo "\x1b[31;4mHello\x1b[0m"

\x1b[0m means “reset all attributes”.

declare -A colors
#curl www.bunlongheng.com/code/colors.png

# Reset
colors[Color_Off]='\033[0m'       # Text Reset

# Regular Colors
colors[Black]='\033[0;30m'        # Black
colors[Red]='\033[0;31m'          # Red
colors[Green]='\033[0;32m'        # Green
colors[Yellow]='\033[0;33m'       # Yellow
colors[Blue]='\033[0;34m'         # Blue
colors[Purple]='\033[0;35m'       # Purple
colors[Cyan]='\033[0;36m'         # Cyan
colors[White]='\033[0;37m'        # White

# Bold
colors[BBlack]='\033[1;30m'       # Black
colors[BRed]='\033[1;31m'         # Red
colors[BGreen]='\033[1;32m'       # Green
colors[BYellow]='\033[1;33m'      # Yellow
colors[BBlue]='\033[1;34m'        # Blue
colors[BPurple]='\033[1;35m'      # Purple
colors[BCyan]='\033[1;36m'        # Cyan
colors[BWhite]='\033[1;37m'       # White

# Underline
colors[UBlack]='\033[4;30m'       # Black
colors[URed]='\033[4;31m'         # Red
colors[UGreen]='\033[4;32m'       # Green
colors[UYellow]='\033[4;33m'      # Yellow
colors[UBlue]='\033[4;34m'        # Blue
colors[UPurple]='\033[4;35m'      # Purple
colors[UCyan]='\033[4;36m'        # Cyan
colors[UWhite]='\033[4;37m'       # White

# Background
colors[On_Black]='\033[40m'       # Black
colors[On_Red]='\033[41m'         # Red
colors[On_Green]='\033[42m'       # Green
colors[On_Yellow]='\033[43m'      # Yellow
colors[On_Blue]='\033[44m'        # Blue
colors[On_Purple]='\033[45m'      # Purple
colors[On_Cyan]='\033[46m'        # Cyan
colors[On_White]='\033[47m'       # White

# High Intensity
colors[IBlack]='\033[0;90m'       # Black
colors[IRed]='\033[0;91m'         # Red
colors[IGreen]='\033[0;92m'       # Green
colors[IYellow]='\033[0;93m'      # Yellow
colors[IBlue]='\033[0;94m'        # Blue
colors[IPurple]='\033[0;95m'      # Purple
colors[ICyan]='\033[0;96m'        # Cyan
colors[IWhite]='\033[0;97m'       # White

# Bold High Intensity
colors[BIBlack]='\033[1;90m'      # Black
colors[BIRed]='\033[1;91m'        # Red
colors[BIGreen]='\033[1;92m'      # Green
colors[BIYellow]='\033[1;93m'     # Yellow
colors[BIBlue]='\033[1;94m'       # Blue
colors[BIPurple]='\033[1;95m'     # Purple
colors[BICyan]='\033[1;96m'       # Cyan
colors[BIWhite]='\033[1;97m'      # White

# High Intensity backgrounds
colors[On_IBlack]='\033[0;100m'   # Black
colors[On_IRed]='\033[0;101m'     # Red
colors[On_IGreen]='\033[0;102m'   # Green
colors[On_IYellow]='\033[0;103m'  # Yellow
colors[On_IBlue]='\033[0;104m'    # Blue
colors[On_IPurple]='\033[0;105m'  # Purple
colors[On_ICyan]='\033[0;106m'    # Cyan
colors[On_IWhite]='\033[0;107m'   # White


color=${colors[$input_color]}
white=${colors[White]}
# echo $white



for i in "${!colors[@]}"
do
  echo -e "$i = ${colors[$i]}I love you$white"
done

——END——

Refer:

[1] 小应用之:shell 日志工具 logdotsh 

https://github.com/dangoakachan/logdotsh

[2] xterm-256color 终端的 256 色模式

http://blogread.cn/it/article/3830?f=wb

[3] Tutorial: How to Color Man Pages & How It Works

http://www.tuxarena.com/2012/04/tutorial-colored-man-pages-how-it-works/

[4] 彩色的命令行 —— 使用 ANSI 色彩代码

http://www.linuxfocus.org/ChineseGB/May2004/article335.shtml

[5] How to change the output color of echo in Linux

https://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux

[6] Bash tips: Colors and formatting (ANSI/VT100 Control sequences)

http://misc.flogisoft.com/bash/tip_colors_and_formatting

[7] Colors In Terminal

http://jafrog.com/2013/11/23/colors-in-terminal.html

转载于:https://my.oschina.net/leejun2005/blog/77499

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值