2023-08-21 15:42:22 +00:00
|
|
|
# Simple colored bash prompt
|
2023-08-21 15:39:54 +00:00
|
|
|
|
2023-11-13 03:12:05 +00:00
|
|
|
Defined in `/etc/profile.d/bash-color-prompt.sh`
|
|
|
|
|
2023-08-21 15:42:22 +00:00
|
|
|
The prompt color theme can be customized simply by setting
|
2023-11-10 06:01:38 +00:00
|
|
|
the `PROMPT_COLOR` envvar, and optionally `PROMPT_DIR_COLOR`.
|
2023-08-21 15:42:22 +00:00
|
|
|
|
|
|
|
For example `PROMPT_COLOR='2;7'` is dim inverse-video
|
|
|
|
and `PROMPT_COLOR='1;33;53'` is bright/bold yellow with overline.
|
|
|
|
|
2023-11-10 07:47:22 +00:00
|
|
|
`PROMPT_DIR_COLOR` similarly changes the color of the working directory,
|
2023-11-10 06:01:38 +00:00
|
|
|
which otherwise defaults to `PROMPT_COLOR`.
|
|
|
|
|
2023-11-13 03:12:05 +00:00
|
|
|
## Coloring Examples
|
2023-11-10 07:47:22 +00:00
|
|
|
|
2023-11-13 03:12:05 +00:00
|
|
|
```shell
|
|
|
|
PROMPT_COLOR=0 # disable colors/attribs
|
|
|
|
PROMPT_COLOR=1 # bold prompt
|
|
|
|
PROMPT_COLOR=2 # dim prompt
|
|
|
|
PROMPT_COLOR=4 # underline prompt
|
|
|
|
PROMPT_COLOR='2;7' # dim reverse video
|
|
|
|
PROMPT_COLOR='42' # green background
|
|
|
|
PROMPT_COLOR='53' # overline separator
|
|
|
|
PROMPT_COLOR='1;33;44' # bold yellow on blue
|
|
|
|
PROMPT_COLOR='43;30' # black on yellow
|
|
|
|
PROMPT_COLOR='1;32' # bold green
|
|
|
|
PROMPT_COLOR='' # unset defaults to green
|
|
|
|
```
|
|
|
|
|
|
|
|
```shell
|
|
|
|
eval $(grep ANSI_COLOR /etc/os-release)
|
|
|
|
PROMPT_COLOR="$ANSI_COLOR"
|
|
|
|
```
|
|
|
|
|
|
|
|
See <https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters> for ANSI codes details.
|
|
|
|
|
|
|
|
## More variables
|
|
|
|
|
|
|
|
### `PROMPT_START` (optional)
|
|
|
|
Displayed at the start of the prompt.
|
|
|
|
|
|
|
|
### `PROMPT_SEPARATOR`
|
|
|
|
Default: `PROMPT_SEPARATOR=':'`
|
2023-11-09 14:49:51 +00:00
|
|
|
|
2023-11-13 03:12:05 +00:00
|
|
|
eg you can change it to `'\n` or `' \t\n'
|
2023-11-09 14:49:51 +00:00
|
|
|
|
2023-11-13 03:12:05 +00:00
|
|
|
### `PROMPT_DIRECTORY`
|
|
|
|
Default: `PROMPT_DIRECTORY='\w'`
|
|
|
|
|
|
|
|
eg you can change it to `'\W'`
|
|
|
|
|
|
|
|
### `PROMPT_ERROR`
|
|
|
|
Set (eg `PROMPT_ERROR=1`) if you want to append red error exit code to
|
|
|
|
the prompt.
|
|
|
|
|
|
|
|
### `PROMPT_END`
|
|
|
|
Displayed at the end of the prompt (before `\$`).
|
|
|
|
|
|
|
|
## Traditional Red Hat prompt
|
|
|
|
```
|
|
|
|
PROMPT_START='['
|
|
|
|
PROMPT_END=']'
|
|
|
|
PROMPT_SEPARATOR=' '
|
|
|
|
PROMPT_DIRECTORY='\W'
|
|
|
|
PROMPT_COLOR='0'
|
|
|
|
```
|
|
|
|
|
2023-11-13 03:36:28 +00:00
|
|
|
## Defaults functions
|
|
|
|
The traditional Red Hat prompt can be set with the `prompt_traditional` function.
|
|
|
|
|
|
|
|
The prompt can be reset to default with the `prompt_default` function.
|
|
|
|
|
|
|
|
Use the `prompt_default_os` function to use `ANSI_COLOR` from `/etc/os-release`.
|
|
|
|
|
2023-11-13 03:12:05 +00:00
|
|
|
## Sourcing
|
|
|
|
Set `prompt_color_force` (before source'ing) to force usage/updating of color
|
|
|
|
PS1: by default it is only setup cautiously if `$TERM` ends in "color"
|
|
|
|
*and* PS1 is the fedora or bash default.
|
2023-11-09 14:49:51 +00:00
|
|
|
|
2023-11-13 03:12:05 +00:00
|
|
|
```shellsession
|
|
|
|
$ prompt_color_force=1
|
|
|
|
$ source /etc/profile.d/bash-color-prompt.sh
|
|
|
|
```
|
2023-08-21 15:42:22 +00:00
|
|
|
|
2023-11-13 03:12:05 +00:00
|
|
|
## Contribute
|
|
|
|
Please open issues against
|
|
|
|
[shell-color-prompt](https://src.fedoraproject.org/rpms/shell-color-prompt).
|
2023-11-13 03:36:28 +00:00
|
|
|
|
|
|
|
shell-color is distributed under the GPL license version 2 or later.
|