Portál AbcLinuxu, 21. května 2025 05:13
When executing interactively, bash displays the primary prompt PS1 when it is ready to read a command, and the secondary prompt PS2 when it needs more input to complete a command. Bash allows these prompt strings to be cus- tomized by inserting a number of backslash-escaped special characters that are decoded as follows:
~/.bashrc
(zmeny sa prejavia lokalne). Najdeme zmienku o PS1 (primary prompt) ktora v povodnom stave v distribucii Debian GNU/Linux (dalej len ako Debian) vyzera napr. takto: #PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
. Nasu cast kodu budeme vkladat az za tuto definiciu. Pokial ste este nerobili ziadne zmeny v .bashrc
mozete tam najst aj nasledovny komentar: # set a fancy prompt (non-color, unless we know we "want" color)
(stale plati pre Debian). Tento komentar je vyznamovo dolezity, kedze sa dozvedame ze sa jedna o nefarebny prompt. Tomuto je prisposobena aj cast kodu ktoru budeme vkladat.case "$TERM" in xterm*|aterm*|rxvt*|urxvt*) . ~/.prompt_xterm ;; screen*) . ~/.prompt_xterm PROMPT_COMMAND='echo -ne "\033k\033\\"' ;; *) ;; esac
~/.prompt_xterm
. Hviezdicka v nazve xterm* je wildcard, co znamena ze nahradza neurcitu cast retazca. Znak |
je logicke OR (alebo). V druhej podmienke sa nastavi este aj premenna $PROMPT_COMMAND kvoli programu screen, v druhej obsahovej casti budeme vidiet ako to vyuzijeme pre hardstatus..prompt_xterm
:TITLEBAR="\[\033]0;$TERM - \u@\h:\w\007\]" PS1="$TITLEBAR\[\033[01;30m\][\[\033[00m\] \[\033[01;37m\]\h\[\033[00m\] \[\033[01;30m\]\w\[\033[00m\] \[\033[01;30m\]]\[\033[00m\]\n \[\033[00;37m\]($TERM)\[\033[00m\] \[\033[01;36m\]\u\[\033[00m\] \\$ "
\[\033[01;36m\]\u
- zobrazi meno uzivatela farbou CYAN (tyrkisova), nejake tie farebne kombinacie ste si mohli osvojit aj z predch. zapisku ls a dircolors..prompt_xterm
od vas "ocakava" ze si ho prisposobite. Obsah ktory ste mohli zhliadnut patri mojmu .prompt_xterm
a to ze bol uvedeny ako priklad neznamena ze je to finalna podoba :).bashrc
by uz nemala nasledovat ziadna dalsia definicia $PS1 aby ste si jej obsah neprepisali, samozrejme tato poznamka pre pokrocilych uzivatelov nema zmysel..bashrc
kadejake ine nespomenute vychytavky (napr. aj distribucne), zakomponujte si ich podla svojich potrieb..bashrc
(ako priklad)# ~/.bashrc: executed by bash(1) for non-login shells. # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) # for examples # If not running interactively, don't do anything [ -z "$PS1" ] && return # don't put duplicate lines in the history. See bash(1) for more options export HISTCONTROL=ignoredups export HISTCONTROL=ignoreboth # check the window size after each command and, if necessary, # update the values of LINES and COLUMNS. shopt -s checkwinsize # make less more friendly for non-text input files, see lesspipe(1) [ -x /usr/bin/lesspipe ] && eval "$(lesspipe)" # set variable identifying the chroot you work in (used in the prompt below) #if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then # debian_chroot=$(cat /etc/debian_chroot) #fi # set a fancy prompt (non-color, unless we know we "want" color) #PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' PS1='[ \h \w ]\n ($TERM) \u \$ ' # If this is an xterm set the title to user@host:dir case "$TERM" in xterm*|aterm*|rxvt*|urxvt*) # PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}"' . ~/.prompt_xterm ;; screen*) . ~/.prompt_xterm PROMPT_COMMAND='echo -ne "\033k\033\\"' ;; *) ;; esac # Alias definitions. # You may want to put all your additions into a separate file like # ~/.bash_aliases, instead of adding them here directly. # See /usr/share/doc/bash-doc/examples in the bash-doc package. if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi # enable color support of ls and also add handy aliases if [ "$TERM" != "dumb" ]; then eval "`dircolors -b`" alias ls='ls --color=auto' #alias dir='ls --color=auto --format=vertical' #alias vdir='ls --color=auto --format=long' fi
.screenrc
:hardstatus alwayslastline hardstatus string '%{=b .W}%H (%{-b .B}%l%{=b .W}) %{= .K}| %{=b .R}%Y-%m-%d %{=b .Y}%c %{= .K}| %{=b .G}*%n%f %t %{= .K}| %{=b .k}%W' shelltitle "$ |bash" startup_message off nethack on vbell off
STRING ESCAPES Screen provides an escape mechanism to insert information like the cur- rent time into messages or file names. The escape character is '%' with one exception: inside of a window's hardstatus '^%' ('^E') is used instead. Here is the full list of supported escapes: % the escape character itself a either 'am' or 'pm' A either 'AM' or 'PM' c current time HH:MM in 24h format C current time HH:MM in 12h format d day number D weekday name f flags of the window F sets %? to true if the window has the focus h hardstatus of the window H hostname of the system l current load of the system m month number M month name n window number s seconds t window title u all other users on this window w all window numbers and names. With '-' quailifier: up to the current window; with '+' qualifier: starting with the window after the current one. W all window numbers and names except the current one y last two digits of the year number Y full year number ? the part to the next '%?' is displayed only if a '%' escape inside the part expands to a non-empty string : else part of '%?' = pad the string to the display's width (like TeX's hfill). If a number is specified, pad to the percentage of the window's width. A '0' qualifier tells screen to treat the number as absolute position. You can specify to pad relative to the last absolute pad position by adding a '+' qualifier or to pad rela- tive to the right margin by using '-'. The padding truncates the string if the specified position lies before the current posi- tion. Add the 'L' qualifier to change this. < same as '%=' but just do truncation, do not fill with spaces > mark the current text position for the next truncation. When screen needs to do truncation, it tries to do it in a way that the marked position gets moved to the specified percentage of the output area. (The area starts from the last absolute pad position and ends with the position specified by the truncation operator.) The 'L' qualifier tells screen to mark the truncated parts with '...'. { attribute/color modifier string terminated by the next "}" ` Substitute with the output of a 'backtick' command. The length qualifier is misused to identify one of the commands. The 'c' and 'C' escape may be qualified with a '0' to make screen use zero instead of space as fill character. The '0' qualifier also makes the '=' escape use absolute positions. The 'n' and '=' escapes under- stand a length qualifier (e.g. '%3n'), 'D' and 'M' can be prefixed with 'L' to generate long names, 'w' and 'W' also show the window flags if 'L' is given. An attribute/color modifier is is used to change the attributes or the color settings. Its format is "[attribute modifier] [color descrip- tion]". The attribute modifier must be prefixed by a change type indi- cator if it can be confused with a color desciption. The following change types are known: + add the specified set to the current attributes - remove the set from the current attributes ! invert the set in the current attributes = change the current attributes to the specified set The attribute set can either be specified as a hexadecimal number or a combination of the following letters: d dim u underline b bold r reverse s standout B blinking Colors are coded either as a hexadecimal number or two letters specify- ing the desired background and foreground color (in that order). The following colors are known: k black r red g green y yellow b blue m magenta c cyan w white d default color . leave color unchanged The capitalized versions of the letter specify bright colors. You can also use the pseudo-color 'i' to set just the brightness and leave the color unchanged. A one digit/letter color description is treated as foreground or back- ground color dependant on the current attributes: if reverse mode is set, the background color is changed instead of the foreground color. If you don't like this, prefix the color with a ".". If you want the same behaviour for two-letter color descriptions, also prefix them with a ".". As a special case, "%{-}" restores the attributes and colors that were set before the last change was made (i.e. pops one level of the color- change stack). Examples: "G" set color to bright green "+b r" use bold red "= yd" clear all attributes, write in default color on yellow back- ground. %-Lw%{= BW}%50>%n%f* %t%{-}%+Lw%< The available windows centered at the current window and trun- cated to the available width. The current window is displayed white on blue. This can be used with "hardstatus alwayslast- line". %?%F%{.R.}%?%3n %t%? [%h]%? The window number and title and the window's hardstatus, if one is set. Also use a red background if this is the active focus. Useful for "caption string".
shelltitle "$ |bash"
zabezpecuje ze pokial nebol dodany retazec pre pomenovanie okna tak nazov okna bude explicitne bash
. Spominany retazec nie je nic ine ako escape sekvencia PROMPT_COMMAND='echo -ne "\033k\033\\"'
(ktoru sme si uz spominali) a nazov vykonavaneho programu.
Tiskni
Sdílej:
screen
u při tab completion?
vbell off
v .screenrc
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.