Adding support for BASH_IT_COLORSCHEME variable + colorschemes

pull/1609/head
Konstantin Gredeskoul 2020-05-29 23:12:40 -07:00
parent 04ad8e982e
commit 1fe7e51b3c
No known key found for this signature in database
GPG Key ID: F64DECB748F527EB
7 changed files with 75 additions and 0 deletions

View File

@ -212,6 +212,45 @@ You can see theme screenshots on [wiki/Themes](https://github.com/Bash-it/bash-i
**NOTE**: Bash-it and some themes use UTF-8 characters, so to avoid strange behavior in your terminal, set your locale to `LC_ALL=en_US.UTF-8` or the equivalent to your language if it isn't American English.
### Color Schemes
In addition to the several dozen themes, you can alter the coloring of the prompt components using an optional color scheme. The color scheme definitions are located in `$BASH_IT/colorschemes` folder, and follow a naming convention `<name>.colorscheme.bash`. You can set the color scheme with `BASH_IT_COLORSCHEME` variable, by assigning it the `<name>` portion of the color scheme filename.
#### Why use color schema?
If you are using iTerm, for instance, then you have access to an environment variable iTerm sets, called `ITERM_PROFILE`. This allows you to choose a different prompt coloring depending on, say, if you are using a light iTerm color theme or a dark one. Here is an example:
```bash
# Set this variable before loading bash_it.sh
if [[ "${ITERM_PROFILE}" =~ "Light" ]]; then
export BASH_IT_COLORSCHEME=light
else
export BASH_IT_COLORSCHEME=dark
fi
source "${BASH_IT}"/bash_it.sh
```
You may place color scheme files in the following three locations (they are searched in this order) — in the example below we assume your color scheme is called "salmon":
1. In your home directory:
`~/.salmon.colorscheme.bash`
2. In Bash-It's `custom` folder:
`${BASH_IT}/custom/salmon.colorscheme.bash`
3. In Bash-It's colorscheme folder:
`${BASH_IT}/colorschemes/salmon.colorscheme.bash`
Here is an example of the light terminal theme with a "light" BASH_IT color scheme:
![light](images/light-colorscheme.png)
And here is a dark terminal theme with a "dark" `BASH_IT` color scheme:
![dark](images/dark-colorscheme.png)
## Uninstalling
To uninstall Bash-it, run the `uninstall.sh` script found in the `$BASH_IT` directory:

View File

@ -0,0 +1,8 @@
CLOCK_THEME_PROMPT_COLOR=92
CWD_THEME_PROMPT_COLOR=29
HOST_THEME_PROMPT_COLOR=6
SCM_THEME_PROMPT_CLEAN_COLOR=4
SCM_THEME_PROMPT_DIRTY_COLOR=214
SCM_THEME_PROMPT_STAGED_COLOR=30
SCM_THEME_PROMPT_UNSTAGED_COLOR=129
USER_INFO_THEME_PROMPT_COLOR=196

View File

@ -0,0 +1,9 @@
CLOCK_THEME_PROMPT_COLOR=214
CWD_THEME_PROMPT_COLOR=123
HOST_THEME_PROMPT_COLOR=9
RUBY_THEME_PROMPT_COLOR=202
SCM_THEME_PROMPT_CLEAN_COLOR=50
SCM_THEME_PROMPT_DIRTY_COLOR=9
SCM_THEME_PROMPT_STAGED_COLOR=121
SCM_THEME_PROMPT_UNSTAGED_COLOR=210
USER_INFO_THEME_PROMPT_COLOR=46

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

View File

@ -513,6 +513,8 @@ function __check_precmd_conflict() {
function safe_append_prompt_command {
local prompt_re
prompt_colorscheme
if [ "${__bp_imported}" == "defined" ]; then
# We are using bash-preexec
if ! __check_precmd_conflict "${1}" ; then
@ -542,3 +544,19 @@ function _save-and-reload-history() {
local autosave=${1:-0}
[[ $autosave -eq 1 ]] && history -a && history -c && history -r
}
function prompt_colorscheme {
[[ -z "${BASH_IT_COLORSCHEME}" ]] && return
local -a colorscheme_locations=(
"${HOME}/.${BASH_IT_COLORSCHEME}.colorscheme.bash"
"$BASH_IT/custom/${BASH_IT_COLORSCHEME}.colorscheme.bash"
"$BASH_IT/colorschemes/${BASH_IT_COLORSCHEME}.colorscheme.bash"
)
for scheme_file in ${colorscheme_locations[@]}; do
if [[ -f ${scheme_file} ]]; then
source "${scheme_file}"
fi
done
}

View File

@ -92,3 +92,4 @@ POWERLINE_LEFT_PROMPT=${POWERLINE_LEFT_PROMPT:="scm python_venv ruby node cwd"}
POWERLINE_RIGHT_PROMPT=${POWERLINE_RIGHT_PROMPT:="in_vim clock battery user_info"}
safe_append_prompt_command __powerline_prompt_command