MySQL 客戶端的默認提示符是 "mysql>",基本上沒什麼實際做用。其實能夠修改這個提示符,讓它顯示一些有用的信息,例如當前所在的數據庫等。修改方法有四種,其中前兩種只對當前鏈接有效,後兩種則對全部鏈接有效。html
個人建議:vi /etc/my.cnfpython
[mysql] prompt=\\u@\\h: \\d \\r:\\m:\\s>
效果:mysql
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>
mysql --prompt="(\u@\h) [\d]> " linux
這樣提示符就會變成 (user@host) [database]>git
還有更多能夠能夠參考官方文檔 4.5.1.2. mysql Commandsgithub
prompt (\u@\h) [\d]> web
[mysql] sql
prompt=(\\u@\\h) [\\d]>\\_ shell
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/
修改 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
請參考: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 一、第一次登陸請在 /home/work 下新建本身名字的目錄(好比 mkdir -p ~/your_name ),私人文件請都放在本身的目錄下。\e[0m" echo -e "\e[41;37;1m 二、應用、服務請部署到 /opt 下對應的目錄,好比 web soft script log 等等。\e[0m" echo -e "\e[41;37;1m 三、因爲一臺機器會多人使用,請勿隨意放置文件、安裝程序,有須要請聯繫 your_name 統一規劃。\e[0m" echo "--------------------------------------------------------------------" } [[ $- == *i* ]] && changeDir
新建 prompt 環境變量,具體含義 help prompt
具體效果步驟請參考:
http://hi.baidu.com/leejun_2005/item/0e29f4bad4bca5a0ebba9373
http://hi.baidu.com/leejun_2005/item/4459eb7a2c314e3b70442353
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 anESC
:
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 ASCIIESC
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 afterm
as 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——
[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