攻城狮论坛

IE-LAB

作者: MS.boring
查看: 20|回复: 1

主题标签Tag

more +今日重磅推荐Recommend No.1

论坛活动~"闲书换金币" 11本书免费送论坛活动~"闲书换金币" 11本书免费送

more +随机图赏Gallery

泰克许国军老师云计算NA公开课视频HCNA-Cloud 华为大数据云计算视频教程泰克许国军老师云计算NA公开课视频HCNA-Cloud 华为大数据云计算视频教程
华为全套HCIE安全视频教程Security LVC公开课 陈世杰 彭定学 王锐 阮维 戴鑫 合力讲演华为全套HCIE安全视频教程Security LVC公开课 陈世杰 彭定学 王锐 阮维 戴鑫 合力讲演
hillstone虚拟化安全培训HCSA-V--云界云格 虚拟化视频教程 专业原厂级讲师hillstone虚拟化安全培训HCSA-V--云界云格 虚拟化视频教程 专业原厂级讲师
Yeslab Hans 2017年最新录制HCNA-HNTD v2.1进阶课程视频33讲Yeslab Hans 2017年最新录制HCNA-HNTD v2.1进阶课程视频33讲
16个方向,全方位学习. Linux运维工程师、架构师全套教程。包含PPT 案例 视频 作业16个方向,全方位学习. Linux运维工程师、架构师全套教程。包含PPT 案例 视频 作业
【2017年-第1期】泰克HCNA华为 安全直通车【最新视频教程】+【扩展资料】【2017年-第1期】泰克HCNA华为 安全直通车【最新视频教程】+【扩展资料】
2017年最新 数据库系统概论(新技术篇)(中国人民大学)教授级大学视频教程2017年最新 数据库系统概论(新技术篇)(中国人民大学)教授级大学视频教程
多位F5工程师的杰作业-F5部署红宝书多位F5工程师的杰作业-F5部署红宝书
超级详细 为了CCIE而录制的CCNA视频教程《CCNA鸿篇巨制版54集》CCIE魔鬼训练营超级详细 为了CCIE而录制的CCNA视频教程《CCNA鸿篇巨制版54集》CCIE魔鬼训练营
华为防火墙视频教程 原理一日通 网络设备防火墙工作原理 设计理念 售前售后攻城狮必备华为防火墙视频教程 原理一日通 网络设备防火墙工作原理 设计理念 售前售后攻城狮必备
教主秦柯 华为防火墙视频50集 USG防火墙进阶讲解 华为防火墙典型配置案例 IPSec教主秦柯 华为防火墙视频50集 USG防火墙进阶讲解 华为防火墙典型配置案例 IPSec
华为安全原厂培训视频教程 新HCNA-Security-中小型企业网安全技术指南(53集)华为安全原厂培训视频教程 新HCNA-Security-中小型企业网安全技术指南(53集)

[电脑技巧] Bash prompt HOWTO 提示符

[复制链接]
查看: 20|回复: 1
开通VIP 免金币+免回帖+批量下载+无广告
这里找到更多的颜色代码,甚至可以让字符反相和闪烁!
As mentioned before, non-printingescape sequences have to be enclosed in \[\033[ and \]. For colour escape sequences, theyshould also be followed by a lowercase m.
If you try out the following promptsin an xterm and find that you aren't seeing the colours named, check out your ~/.Xdefaults file(and possibly its bretheren) for lines like XTerm*Foreground: BlanchedAlmond.This can be commented out by placing an exclamation mark ("!") infront of it. Of course, this will also be dependent on what terminal emulatoryou're using. This is the likeliest place that your term foreground colourswould be overridden.
To include blue text in the prompt:
PS1="\[\033[34m\][\$(date+%H%M)][\u@\h:\w]$ "
The problem withthis prompt is that the blue colour that starts with the 34 colour code isnever switched back to the regular colour, so any text you type after the promptis still in the colour of the prompt. This is also a dark shade of blue, socombining it with the bold code might help:
  
PS1="\[\033[1;34m\][\$(date  +%H%M)][\u@\h:\w]$\[\033[0m\] "
  
The prompt is nowin light blue, and it ends by switching the colour back to nothing (whateverforeground colour you had previously).
Here are the restof the colour equivalences:
  
Black        0;30     Dark Gray     1;30
  
Blue         0;34     Light Blue    1;34
  
Green        0;32     Light Green   1;32
  
Cyan         0;36     Light Cyan    1;36
  
Red          0;31     Light Red     1;31
  
Purple       0;35     Light Purple  1;35
  
Brown        0;33     Yellow        1;33
  
Light Gray   0;37     White         1;37
  
Daniel Dui(ddui@iee.org) points out that to be strictly accurate, we must mention thatthe list above is for colours at the console. In an xterm, the code 1;31 isn't"Light Red," but "Bold Red." This is true of all thecolours.
You can also setbackground colours by using 44 for Blue background, 41 for a Red background,etc. There are no bold background colours. Combinations can be used, like LightRed text on a Blue background: \[\033[44;1;31m\], although settingthe colours separately seems to work better (ie. \[\033[44m\]\[\033[1;31m\]). Other codesavailable include 4: Underscore, 5: Blink, 7: Inverse, and 8: Concealed.
  
file:///C:/Users/ADMINI~1/AppData/Local/Temp/msohtmlclip1/01/clip_image001.gif
  
  
Many people (myself included) object strongly to the "blink"  attribute because it's extremely distracting and irritating. Fortunately, it  doesn't work in any terminal emulators that I'm aware of - but it will still  work on the console.
  
  
file:///C:/Users/ADMINI~1/AppData/Local/Temp/msohtmlclip1/01/clip_image001.gif
  
  
If you were wondering (as I did) "What use is a 'Concealed'  attribute?!" - I saw it used in an example shell script (not a prompt)  to allow someone to type in a password without it being echoed to the screen.  However, this attribute doesn't seem to be honoured by many terms other than  "Xterm."
  
Based on a promptcalled "elite2" in the Bashprompt package (which I have modified towork better on a standard console, rather than with the special xterm fontsrequired to view the original properly), this is a prompt I've used a lot:
  
  
function elite
  
{
  
  
local GRAY="\[\033[1;30m\]"
  
local LIGHT_GRAY="\[\033[0;37m\]"
  
local CYAN="\[\033[0;36m\]"
  
local LIGHT_CYAN="\[\033[1;36m\]"
  
local NO_COLOUR="\[\033[0m\]"
  
  
case $TERM in
  
    xterm*|rxvt*)
  
         local TITLEBAR='\[\033]0;\u@\h:\w\007\]'
  
         ;;
  
     *)
  
         local TITLEBAR=""
  
         ;;
  
esac
  
  
local temp=$(tty)
  
local GRAD1=${temp:5}
  
PS1="$TITLEBAR\
  
$GRAY-$CYAN-$LIGHT_CYAN(\
  
$CYAN\u$GRAY@$CYAN\h\
  
$LIGHT_CYAN)$CYAN-$LIGHT_CYAN(\
  
$CYAN\#$GRAY/$CYAN$GRAD1\
  
$LIGHT_CYAN)$CYAN-$LIGHT_CYAN(\
  
$CYAN\$(date +%H%M)$GRAY/$CYAN\$(date  +%d-%b-%y)\
  
$LIGHT_CYAN)$CYAN-$GRAY-\
  
$LIGHT_GRAY\n\
  
$GRAY-$CYAN-$LIGHT_CYAN(\
  
$CYAN\$$GRAY:$CYAN\w\
  
$LIGHT_CYAN)$CYAN-$GRAY-$LIGHT_GRAY "
  
PS2="$LIGHT_CYAN-$CYAN-$GRAY-$NO_COLOUR  "
  
}
  
I define thecolours as temporary shell variables in the name of readability. It's easier towork with. The "GRAD1" variable is a check to determine what terminalyou're on. Like the test to determine if you're working in an Xterm, it onlyneeds to be done once. The prompt you see look like this, except in colour:
  
--(giles@gcsu202014)-(30/pts/6)-(0816/01-Aug-01)--
  
--($:~/tmp)--
  
To help myselfremember what colours are available, I wrote a script that output all thecolours to the screen. Daniel Crisman has supplied a much nicer version which Iinclude below:
  
#!/bin/bash
  
#
  
#    This file echoes a bunch of color codes to the
  
#    terminal to demonstrate what's available.  Each
  
#    line is the color code of one forground color,
  
#    out of 17 (default + 16 escapes), followed by a
  
#    test use of that color on all nine background
  
#    colors (default + 8 escapes).
  
#
  
  
T='gYw'    # The test text
  
  
echo -e "\n                 40m      41m     42m     43m\
  
      44m     45m     46m      47m";
  
  
for FGs in '    m' '    1m' '  30m' '1;30m' '  31m' '1;31m' '  32m' \
  
            '1;32m' '  33m' '1;33m' '  34m' '1;34m' '  35m' '1;35m' \
  
            '  36m' '1;36m' '  37m' '1;37m';
  
  do  FG=${FGs// /}
  
   echo -en " $FGs \033[$FG   $T  "
  
  for  BG in 40m 41m 42m 43m 44m 45m 46m 47m;
  
     do echo -en "$EINS \033[$FG\033[$BG  $T   \033[0m";
  
   done
  
   echo;
  
done
  
echo
  

            
  
ANSI Escape Sequences: Colours and Cursor Movement
  
      
Cursor Movement
  
* [3 u. z, M$ ?/ X) ~9 T9 Y% C
CCNA考试 官方正规报名 仅需1500元
回复 论坛版权

使用道具 举报

MS.boring [Lv2 初出茅庐] 发表于 2017-9-1 09:56:18 | 显示全部楼层
此帖仅作者可见

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

官方QQ群

QQ|无图浏览|手机版|网站地图|攻城狮论坛 ( 京ICP备12049419号 )|网站地图

GMT+8, 2017-9-25 03:16 , Processed in 0.292388 second(s), 18 queries , Gzip On, Memcache On.

Powered by Discuz! X3.2 © 2001-2013 Comsenz Inc.

Designed by ARTERY.cn