This shows you the differences between two versions of the page.
bash:tip_customize_the_shell_prompt [2011/06/22 11:48] flozz [Special sequences] |
bash:tip_customize_the_shell_prompt [2017/09/01 12:24] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Bash tips: Customize the shell prompt ====== | ||
- | |||
- | FIXME | ||
- | |||
- | |||
- | |||
- | ===== Prompt Helper ===== | ||
- | |||
- | **Prompt Helper** is a Javascript script that helps you to customize your prompt by displaying your modification in real time. | ||
- | It does not support all the features of a shell, but it is sufficient for doing what we want to. | ||
- | |||
- | <html></p> | ||
- | <!--Prompt Helper--> | ||
- | <div id="ph_prompt_helper" style="border: silver dashed 1px;">You need Javascript for using Prompt Helper.</div> | ||
- | <script src="/scripts/prompt_helper.js" type="text/javascript"></script> | ||
- | <!-- /Prompt Helper --> | ||
- | <p></html> | ||
- | |||
- | |||
- | ===== Special sequences ===== | ||
- | |||
- | ^ Sequence ^ description ^ Example/Preview ^ | ||
- | | \d | The date (''+%a\ %b\ %d'' format) ((''date'' command format)) | ''Mon Jun 13'' | | ||
- | | \D{//format//} | The date in the desired //format// (in ''strftime'' format) ((Not supported by Prompt Helper)) | | | ||
- | | \t | The time, 24-hour (''+%k:%M:%S'' format) ((''date'' command format)) | ''22:42:01'' | | ||
- | | \T | The time, 12-hour (''+%l:%M:%S'' format) ((''date'' command format)) | ''10:42:01'' | | ||
- | | \@ | The time, 12-hour, with AM/PM (''+%l:%M\ %p'' format) ((''date'' command format)) | ''10:42 PM'' or ''10:42'' | | ||
- | | \A | The time, 24-hour (''+%k:%M'' format) ((''date'' command format)) | ''22:42'' | | ||
- | | \h | The host name | ''hostname'' | | ||
- | | \H | The full host name (with the domain name) | ''hostname.domain'' | | ||
- | | \j | The number of suspended processes in the current shell (<Ctrl>+Z) | ''0'' | | ||
- | | \l | The name of the shell's terminal device | ''tty1'' or ''1'' | | ||
- | | \s | The name of the shell executable | ''bash'' | | ||
- | | \u | The current user name | ''username'' | | ||
- | | \v | The version of the shell (short) | ''4.1'' | | ||
- | | \V | The version of the shell (with the patch level) | ''4.1.5'' | | ||
- | | \w | The path of the working directory | ''~/Documents'' or ''/usr/bin'' | | ||
- | | \W | The name of the working directory | ''Documents'' or ''bin'' | | ||
- | | \! | The current command number in the history | ''538'' | | ||
- | | \# | The command number (from the start of the shell) | ''42'' | | ||
- | | \$ | If the current user is root, displays a ''#'', else displays a ''$'' | ''$'' or ''#'' | | ||
- | | \[ | Start a sequence of non-printing characters | | | ||
- | | \] | End a sequence of non-printing characters | | | ||
- | | \a \\ \007 | The ASCII bell character | | | ||
- | | \n | Start a new line | | | ||
- | | \r | Carriage return | | | ||
- | | ''\''''\'' | A single backslash | ''\'' | | ||
- | | \e \\ \033 | The ASCII ''Escape'' character. Used by some [[bash:tip_customize_the_shell_prompt#control_sequences_e_033_x1b|Control Sequences]] (see bellow) | | | ||
- | |||
- | |||
- | |||
- | ===== Control Sequences (\e, \033) ===== | ||
- | |||
- | Here we will see only a part of the formating and color sequences. For using colors in your shell you can | ||
- | use sequences like "''\e[''<html><span style="color: red;"><em>Attr</em></span></html>''m''". ''Attr'' can | ||
- | be replaced by one or more attributes (see bellow). | ||
- | |||
- | __E.g.:__ | ||
- | <code>\e[31mRed Text</code> | ||
- | <code>\e[42mGreen background</code> | ||
- | <code>\e[1mBold text</code> | ||
- | <code>\e[1;31;42mBold and Red text, Green background</code> | ||
- | |||
- | |||
- | ==== Colors ==== | ||
- | |||
- | ^ ^ Black ^ Red ^ Green ^ Yellow ^ Blue ^ Magenta ^ Cyan ^ White ^ Default color ^ | ||
- | ^ Foreground | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 39 | | ||
- | ^ Background | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 49 | | ||
- | |||
- | Fore more information about colors see: [[bash:tip_colors_and_formatting#colors]]. | ||
- | |||
- | |||
- | ==== Formatting ==== | ||
- | ^ Bold ^ Underlined ^ Inverted ^ Default formating and color ^ | ||
- | | 1 | 4 | 7 | 0 | | ||
- | |||
- | Fore more information about formatting see: [[bash:tip_colors_and_formatting#formatting]]. | ||
- | |||
- | |||
- | |||
- | ===== Example of prompts ===== | ||
- | |||
- | Debian default prompt (no color): | ||
- | <code>${debian_chroot:+($debian_chroot)}\u@\h:\w\$ </code> | ||
- | |||
- | Debian default colored prompt: | ||
- | <code>${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ </code> | ||
- | |||
- | Demo 1: | ||
- | <code>\[\e]0;[\w]\a\r\e[1;38;5;118;48;5;16m\] \u \[\e[38;5;16;48;5;118m\] \h \[\e[0m\] \$ </code> | ||
- | |||
- | Demo 2: | ||
- | <code>\n\[\e[0;38;5;118m\]┏━━━━┫\[\e[1;48;5;118;1;38;5;16m\] \u@\h \[\e[0;38;5;118m\]┣━━┫\[\e[1;48;5;118;1;38;5;16m\] \W \[\e[0;38;5;118m\]┣━━━━━\n┃\n┗━━\$❱\[\e[0m\] </code> | ||
- | ===== Links ===== | ||
- | |||
- | * [[bash:tip_colors_and_formatting|Bash tips: Colors and formatting]] | ||
- | * [[http://www.gnu.org/software/bash/manual/bashref.html#Printing-a-Prompt|Bash manual: Printing a prompt]] | ||
- | * [[http://www.funtoo.org/wiki/Prompt_Magic|Funtoo: Prompt magic]] | ||
- | |||