hgtesta (owner)

Forks

Revisions

gist: 122503 Download_button fork
public
Public Clone URL: git://gist.github.com/122503.git
Embed All Files: show embed
Text only #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
Bash prompts
============
 
(o que eu utilizo)
\[\033[0;33m\][\!]`if [[ $? = 0 ]]; then echo \[\033[32m\]; else echo \[\033[31m\]; fi`[\u.\h: `if [[ 12 > 18 ]]; then echo \W; else echo \w; fi`]$\[\033[0m\]
 
 
(simples, sem cores)
PS1="\u@\h:\w/ > "
 
if [ "$PS1" ]; then
  # Is this terminal able to use this prompt?
  case $TERM in
    xterm*|rxvt*|cygwin*)
      # Am I root?
      if [ $UID = 0 ]; then
        PS1='\[\e]0;\w | \u@\h\a\][\[\e[1;31m\]\u@\h \[\e[33m\]\W\[\e[0m\]]# '
      else
        PS1='\[\e]0;\w | \u@\h\a\][\[\e[32m\]\u@\h \[\e[33m\]\W\[\e[0m\]]$ '
      fi
      ;;
  esac
fi
 
 
Caracteres Especiais
====================
Bash allows these prompt strings to be customized by inserting a
number of backslash-escaped special characters that are
decoded as follows:
 
  \a an ASCII bell character (07)
  \d the date in "Weekday Month Date" format (e.g., "Tue May 26")
  \D{format} the format is passed to strftime(3) and the result
             is inserted into the prompt string an empty format
             results in a locale-specific time representation.
             The braces are required
  \e an ASCII escape character (033)
  \h the hostname up to the first `.'
  \H the hostname
  \j the number of jobs currently managed by the shell
  \l the basename of the shell's terminal device name
  \n newline
  \r carriage return
  \s the name of the shell, the basename of $0 (the portion following
             the final slash)
  \t the current time in 24-hour HH:MM:SS format
  \T the current time in 12-hour HH:MM:SS format
  \@ the current time in 12-hour am/pm format
  \A the current time in 24-hour HH:MM format
  \u the username of the current user
  \v the version of bash (e.g., 2.00)
  \V the release of bash, version + patch level (e.g., 2.00.0)
  \w the current working directory, with $HOME abbreviated with a tilde
  \W the basename of the current working directory, with $HOME
             abbreviated with a tilde
  \! the history number of this command
  \# the command number of this command
  \$ if the effective UID is 0, a #, otherwise a $
  \nnn the character corresponding to the octal number nnn
  \\ a backslash
  \[ begin a sequence of non-printing characters, which could be used
             to embed a terminal control sequence into the prompt
  \] end a sequence of non-printing characters
 
Cores
=====
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
 
0 Normal (default)
1 Bold
4 Underlined
5 Blink (appears as Bold)
7 Inverse
8 Invisible (hidden)
2 2 Normal (neither bold nor faint)
2 4 Not underlined
2 5 Steady (not blinking)
2 7 Positive (not inverse)
2 8 Visible (not hidden)
3 0 Set foreground color to Black
3 1 Set foreground color to Red
3 2 Set foreground color to Green
3 3 Set foreground color to Yellow
3 4 Set foreground color to Blue
3 5 Set foreground color to Magenta
3 6 Set foreground color to Cyan
3 7 Set foreground color to White
3 9 Set foreground color to default (original)
4 0 Set background color to Black
4 1 Set background color to Red
4 2 Set background color to Green
4 3 Set background color to Yellow
4 4 Set background color to Blue
4 5 Set background color to Magenta
4 6 Set background color to Cyan
4 7 Set background color to White
4 9 Set background color to default (original).
 
(cores mais vivas)
9 0 Set foreground color to Black
9 1 Set foreground color to Red
9 2 Set foreground color to Green
9 3 Set foreground color to Yellow
9 4 Set foreground color to Blue
9 5 Set foreground color to Magenta
9 6 Set foreground color to Cyan
9 7 Set foreground color to White
1 0 0 Set background color to Black
1 0 1 Set background color to Red
1 0 2 Set background color to Green
1 0 3 Set background color to Yellow
1 0 4 Set background color to Blue
1 0 5 Set background color to Magenta
1 0 6 Set background color to Cyan
1 0 7 Set background color to White
 
If xterm is compiled with the 16-color support disabled, it supports the following, from rxvt:
1 0 0 Set foreground and background color to default
(redirado de http://rtfm.etla.org/xterm/ctlseq.html)
 
Links
=====
http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html
http://www.nparikh.org/unix/prompt.php
http://www.ibm.com/developerworks/linux/library/l-tip-prompt/
http://networking.ringofsaturn.com/Unix/Bash-prompts.php
http://rtfm.etla.org/xterm/ctlseq.html
 
Efeitos
=======
PS1='[\u@TEST \w]\n \#\$ \n\
\[\
\e[1mBold Text\e[m\n\
\e[4mUnderline Text\e[m\n\
\e[5mBlink Text\e[m\n\
\e[7mInverse Text\e[m\]\n\
Should be normal text'
 
Dicas
=====
Remove Color
Echo \e[00m to remove text color modifications
\[ begins a sequence of non-printing characters
\] ends a sequence of non-printing characters
 
##################################################
# Fancy PWD display function
##################################################
# The home directory (HOME) is replaced with a ~
# The last pwdmaxlen characters of the PWD are displayed
# Leading partial directory names are striped off
# /home/me/stuff -> ~/stuff if USER=me
# /usr/share/big_dir_name -> ../share/big_dir_name if pwdmaxlen=20
##################################################
bash_prompt_command() {
    # How many characters of the $PWD should be kept
    local pwdmaxlen=25
    # Indicate that there has been dir truncation
    local trunc_symbol=".."
    local dir=${PWD##*/}
    pwdmaxlen=$(( ( pwdmaxlen < ${#dir} ) ? ${#dir} : pwdmaxlen ))
    NEW_PWD=${PWD/#$HOME/\~}
    local pwdoffset=$(( ${#NEW_PWD} - pwdmaxlen ))
    if [ ${pwdoffset} -gt "0" ]
    then
        NEW_PWD=${NEW_PWD:$pwdoffset:$pwdmaxlen}
        NEW_PWD=${trunc_symbol}/${NEW_PWD#*/}
    fi
}
 
 
Idéias
======
Cor vermelha para sudo