version 0.4 with PROMPT_USERHOST and colorpre and colorsuf
drop container and PROMPT_ERROR
This commit is contained in:
parent
81ed607e32
commit
c475f4e18b
72
README.md
72
README.md
@ -6,7 +6,7 @@ The prompt color theme can be customized simply by setting
|
|||||||
the `PROMPT_COLOR` envvar, and optionally `PROMPT_DIR_COLOR`.
|
the `PROMPT_COLOR` envvar, and optionally `PROMPT_DIR_COLOR`.
|
||||||
|
|
||||||
For example `PROMPT_COLOR='2;7'` is dim inverse-video
|
For example `PROMPT_COLOR='2;7'` is dim inverse-video
|
||||||
and `PROMPT_COLOR='1;33;53'` is bright/bold yellow with overline.
|
or `PROMPT_COLOR='44'` gives a blue background.
|
||||||
|
|
||||||
`PROMPT_DIR_COLOR` similarly changes the color of the working directory,
|
`PROMPT_DIR_COLOR` similarly changes the color of the working directory,
|
||||||
which otherwise defaults to `PROMPT_COLOR`.
|
which otherwise defaults to `PROMPT_COLOR`.
|
||||||
@ -34,11 +34,22 @@ PROMPT_COLOR="$ANSI_COLOR"
|
|||||||
|
|
||||||
See <https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters> for ANSI codes details.
|
See <https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters> for ANSI codes details.
|
||||||
|
|
||||||
## More variables
|
## Configurable variables
|
||||||
|
bash-color-prompt's PS1 has the following general structure:
|
||||||
|
`[PROMPT_START] PROMPT_USERHOST^PROMPT_SEPARATOR PROMPT_DIRECTORY^[PROMPT_END]`
|
||||||
|
(`^` means color reset) described below:
|
||||||
|
|
||||||
### `PROMPT_START` (optional)
|
### `PROMPT_START` (optional)
|
||||||
Displayed at the start of the prompt.
|
Displayed at the start of the prompt.
|
||||||
|
|
||||||
|
### `PROMPT_USERHOST`
|
||||||
|
Default: `PROMPT_USERHOST='\u@\h'`
|
||||||
|
|
||||||
|
Defaults to `PROMPT_COLOR`.
|
||||||
|
|
||||||
|
See the PROMPTING section of `man bash` or `info bash` for
|
||||||
|
the available backslash-escaped special characters.
|
||||||
|
|
||||||
### `PROMPT_SEPARATOR`
|
### `PROMPT_SEPARATOR`
|
||||||
Default: `PROMPT_SEPARATOR=':'`
|
Default: `PROMPT_SEPARATOR=':'`
|
||||||
|
|
||||||
@ -49,9 +60,7 @@ Default: `PROMPT_DIRECTORY='\w'`
|
|||||||
|
|
||||||
eg you can change it to `'\W'`
|
eg you can change it to `'\W'`
|
||||||
|
|
||||||
### `PROMPT_ERROR`
|
Defaults to `PROMPT_DIR_COLOR` if set or `PROMPT_COLOR`.
|
||||||
Set (eg `PROMPT_ERROR=1`) if you want to append red error exit code to
|
|
||||||
the prompt.
|
|
||||||
|
|
||||||
### `PROMPT_END`
|
### `PROMPT_END`
|
||||||
Displayed at the end of the prompt (before `\$`).
|
Displayed at the end of the prompt (before `\$`).
|
||||||
@ -72,15 +81,52 @@ 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`.
|
Use the `prompt_default_os` function to use `ANSI_COLOR` from `/etc/os-release`.
|
||||||
|
|
||||||
## Sourcing
|
## Multiline prompt example
|
||||||
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.
|
|
||||||
|
|
||||||
```shellsession
|
|
||||||
$ prompt_color_force=1
|
|
||||||
$ source /etc/profile.d/bash-color-prompt.sh
|
|
||||||
```
|
```
|
||||||
|
PROMPT_START='\t\n'
|
||||||
|
PROMPT_COLOR='30;43'
|
||||||
|
PROMPT_DIR_COLOR='44'
|
||||||
|
PROMPT_SEPARATOR='\n'
|
||||||
|
```
|
||||||
|
You can also set say `PS0='\t'` to timestamp the start of commands.
|
||||||
|
|
||||||
|
## Git branch integration
|
||||||
|
```
|
||||||
|
function prompt_command {
|
||||||
|
ref=$(/usr/bin/git rev-parse --abbrev-ref HEAD 2> /dev/null)
|
||||||
|
git_branch=${ref:+:$ref}
|
||||||
|
}
|
||||||
|
PROMPT_COMMAND=prompt_command
|
||||||
|
PROMPT_END='${git_branch@P}'
|
||||||
|
```
|
||||||
|
|
||||||
|
## Container support
|
||||||
|
Basic container support can be setup with say:
|
||||||
|
```
|
||||||
|
PROMPT_START='${container:+⬢ }'
|
||||||
|
```
|
||||||
|
though putting it in `PROMPT_USERHOST` might make more sense.
|
||||||
|
|
||||||
|
## Show exit code for error in red
|
||||||
|
```
|
||||||
|
PROMPT_END="${colorpre@P}31${colorsuf@P}'${?#0}'"%{colorreset}"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Sourcing
|
||||||
|
Set `prompt_color_force`
|
||||||
|
(before sourcing `/etc/bashrc` or `bash-color-prompt.sh` directly)
|
||||||
|
to turn on bash-color-prompt unconditionally,
|
||||||
|
otherwise by default it is only setup cautiously
|
||||||
|
if `$TERM` ends in "color" *and* PS1 is the fedora or bash default.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
```shellsession
|
||||||
|
if [ -t 0 ]; then
|
||||||
|
prompt_color_force=1
|
||||||
|
source /etc/profile.d/bash-color-prompt.sh
|
||||||
|
fi
|
||||||
|
```
|
||||||
|
can be added to `~/.bashrc` to turn on bash-color-prompt "everywhere".
|
||||||
|
|
||||||
## Contribute
|
## Contribute
|
||||||
Please open issues against
|
Please open issues against
|
||||||
|
@ -6,9 +6,14 @@
|
|||||||
# only set for color terminals and if PS1 unchanged from bash or fedora defaults
|
# only set for color terminals and if PS1 unchanged from bash or fedora defaults
|
||||||
if [ '(' "$PS1" = "[\u@\h \W]\\$ " -o "$PS1" = "\\s-\\v\\\$ " ')' -a "${TERM: -5}" = "color" -o -n "${prompt_color_force}" ]; then
|
if [ '(' "$PS1" = "[\u@\h \W]\\$ " -o "$PS1" = "\\s-\\v\\\$ " ')' -a "${TERM: -5}" = "color" -o -n "${prompt_color_force}" ]; then
|
||||||
|
|
||||||
PROMPT_SEPARATOR=':'
|
PROMPT_COLOR="${PROMPT_COLOR:-32}"
|
||||||
PROMPT_DIRECTORY='\w'
|
PROMPT_USERHOST="${PROMPT_USERHOST:-\u@\h}"
|
||||||
PS1='${PROMPT_START@P}\[\e[${PROMPT_COLOR:-32}m\]${container:+⬢ }\u@\h\[\e[0m\]${PROMPT_SEPARATOR@P}\[\e[${PROMPT_DIR_COLOR:-${PROMPT_COLOR:-32}}m\]${PROMPT_DIRECTORY@P}${PROMPT_ERROR:+\[\e[0;31m\]${?#0}}\[\e[0m\]${PROMPT_END@P}\$ '
|
PROMPT_SEPARATOR="${PROMPT_SEPARATOR:-:}"
|
||||||
|
PROMPT_DIRECTORY="${PROMPT_DIRECTORY:-\w}"
|
||||||
|
colorpre='\[\e['
|
||||||
|
colorsuf='m\]'
|
||||||
|
colorreset="${colorpre}0${colorsuf}"
|
||||||
|
PS1='${PROMPT_START@P}'"${colorpre}"'${PROMPT_COLOR}'"${colorsuf}"'${PROMPT_USERHOST@P}'"${colorreset}"'${PROMPT_SEPARATOR@P}'"${colorpre}"'${PROMPT_DIR_COLOR:-${PROMPT_COLOR}}'"${colorsuf}"'${PROMPT_DIRECTORY@P}'"${colorreset}"'${PROMPT_END@P}\$'"${colorreset} "
|
||||||
|
|
||||||
prompt_default() {
|
prompt_default() {
|
||||||
PROMPT_COLOR="$1"
|
PROMPT_COLOR="$1"
|
||||||
@ -21,7 +26,7 @@ if [ '(' "$PS1" = "[\u@\h \W]\\$ " -o "$PS1" = "\\s-\\v\\\$ " ')' -a "${TERM: -5
|
|||||||
|
|
||||||
prompt_traditional() {
|
prompt_traditional() {
|
||||||
PROMPT_COLOR="${1:-0}"
|
PROMPT_COLOR="${1:-0}"
|
||||||
PROMPT_DIR_COLOR="${2}"
|
PROMPT_DIR_COLOR="$2"
|
||||||
PROMPT_SEPARATOR=' '
|
PROMPT_SEPARATOR=' '
|
||||||
PROMPT_DIRECTORY='\W'
|
PROMPT_DIRECTORY='\W'
|
||||||
PROMPT_START='['
|
PROMPT_START='['
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
Name: shell-color-prompt
|
Name: shell-color-prompt
|
||||||
Version: 0.3
|
Version: 0.4
|
||||||
Release: 2%{?dist}
|
Release: 1%{?dist}
|
||||||
Summary: Color prompt for bash shell
|
Summary: Color prompt for bash shell
|
||||||
|
|
||||||
License: GPL-2.0-or-later
|
License: GPL-2.0-or-later
|
||||||
@ -41,7 +41,13 @@ install -m 644 -D -t %{buildroot}%{profiledir} bash-color-prompt.sh
|
|||||||
|
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
* Mon Nov 13 2023 Jens Petersen <petersen@redhat.com> - 0.3-2
|
* Mon Nov 13 2023 Jens Petersen <petersen@redhat.com> - 0.4-1
|
||||||
|
- define PROMPT_COLOR
|
||||||
|
- add PROMPT_USERHOST default variable
|
||||||
|
- add colorpre and colorsuf variables
|
||||||
|
- drop PROMPT_EPROR
|
||||||
|
- drop built-in container support for now
|
||||||
|
- reset color after $ prompt
|
||||||
- only define default functions if setting PS1
|
- only define default functions if setting PS1
|
||||||
|
|
||||||
* Mon Nov 13 2023 Jens Petersen <petersen@redhat.com> - 0.3-1
|
* Mon Nov 13 2023 Jens Petersen <petersen@redhat.com> - 0.3-1
|
||||||
|
Loading…
Reference in New Issue
Block a user