date
command formatThis is an old revision of the document!
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.
Sequence | description | Example/Preview |
---|---|---|
\d | The date (+%a\ %b\ %d format) 1) | Mon Jun 13 |
\D{format} | The date in the desired format (in strftime format) 2) | |
\t | The time, 24-hour (+%k:%M:%S format) 3) | 22:42:01 |
\T | The time, 12-hour (+%l:%M:%S format) 4) | 10:42:01 |
\@ | The time, 12-hour, with AM/PM (+%l:%M\ %p format) 5) | 10:42 PM or 10:42 |
\A | The time, 24-hour (+%k:%M format) 6) | 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 Control Sequences (see bellow) |
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[
Attrm
”. Attr
can
be replaced by one or more attributes (see bellow).
E.g.:
\e[31mRed Text
\e[42mGreen background
\e[1mBold text
\e[1;31;42mBold and Red text, Green background
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: colors.
Bold | Underlined | Inverted | Default formating and color |
---|---|---|---|
1 | 4 | 7 | 0 |
Fore more information about formatting see: formatting.
Debian default prompt (no color):
${debian_chroot:+($debian_chroot)}\u@\h:\w\$
Debian default colored prompt:
${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$
Demo 1:
\[\e]0;[\w]\a\r\e[1;38;5;118;48;5;16m\] \u \[\e[38;5;16;48;5;118m\] \h \[\e[0m\] \$
Demo 2:
\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\]
Discussion