[root@GCE-Node1_www.dwhd.org ~]# awk '/mariadb/' .bashrc alias mysql=$(echo -e '/usr/local/mariadb-galera/bin/mysql -uroot -p****** -h127.0.0.1 -S/tmp/mysql.sock -D mysql --prompt="\x1B[31m\\u\x1B[34m@\x1B[0m[\D]:\x1B[32mGCE-Node1_www.dwhd.org\x1B[0m:\x1B[31m(\d)\x1B[36m\x1B[0m> "') [root@GCE-Node1_www.dwhd.org ~]# alias mysql=$(echo -e '/usr/local/mariadb-galera/bin/mysql -uroot -p****** -h127.0.0.1 -S/tmp/mysql.sock -D mysql --prompt="\x1B[31m\\u\x1B[34m@\x1B[0m[\D]:\x1B[32mGCE-Node1_www.dwhd.org\x1B[0m:\x1B[31m(\d)\x1B[0m> "')
分部拆解說明
alias mysql=$() #設置別名 echo -e '/usr/local/mariadb-galera/bin/mysql -uroot -p******* -h127.0.0.1 -S/tmp/mysql.sock -D mysql --prompt="\x1B[31m\\u\x1B[34m@\x1B[0m[\D]:\x1B[32mGCE-Node1_www.dwhd.org\x1B[0m:\x1B[31m(\d)\x1B[0m> "' #將mysql命令設置為指定的內容 --prompt="\x1B[31m\ \u\ \x1B[34m@\ \x1B[0m[\D]:\ \x1B[32mGCE-Node1_www.dwhd.org\ \x1B[0m:\ \x1B[31m(\d)\ \x1B[0m> " #上面這樣拆分就可以看出 指定\u 為紅色,指定@為藍色,指定[\D]:為白色,指定GCE-Node1_www.dwhd.org為綠色,指定:為白色,指定(\d)為紅色,指定> 為白色。 ##具體的代碼大家搜下谷歌就知道,這裡就不細說了
以為這樣就結束?看看下面的,執行結果也來彩色顯示
實現方法:
[root@GCE-Node1_www.dwhd.org ~]# cd /usr/local/src [root@GCE-Node1_www.dwhd.org /usr/local/src]# git clone https://github.com/garabik/grc.git [root@GCE-Node1_www.dwhd.org /usr/local/src]# cd grc [root@GCE-Node1_www.dwhd.org /usr/local/src/grc]# bash install.sh [root@GCE-Node1_www.dwhd.org /usr/local/src/grc]# cat >> ~/.bashrc <<-EOF if [ -f /usr/local/bin/grc ]; then alias ping="grc --colour=auto ping" alias traceroute="grc --colour=auto traceroute" alias make="grc --colour=auto make" alias diff="grc --colour=auto diff" alias cvs="grc --colour=auto cvs" alias netstat="grc --colour=auto netstat" fi EOF cat >> ~/.my.cnf<<-EOF [mysql] pager = grcat ~/.grcat EOF cat >> ~/.grcat <<-EOF #default word color #regexp=[\w.,\:\-_/]+ regexp=.+ colours=green - #table borders regexp=[+\-]+[+\-]|[|] colours=red - #data in ( ) and ' ' regexp=\([\w\d,']+\) colours=white - #numeric regexp=\s[\d\.]+\s*($|(?=\|)) colours=yellow - #date regexp=\d{4}-\d{2}-\d{2} colours=cyan - #time regexp=\d{2}:\d{2}:\d{2} colours=cyan - #IP regexp=(\d{1,3}\.){3}\d{1,3}(:\d{1,5})? colours=cyan - #schema regexp=`\w+` colours=yellow - #email regexp=[\w\.\-_]+@[\w\.\-_]+ colours=magenta - #row delimeter when using \G key regexp=[*]+.+[*]+ count=stop colours=white - #column names when using \G key regexp=^\s*\w+: colours=white EOF [root@GCE-Node1_www.dwhd.org /usr/local/src/grc]# cd && . ~/.bashrc