diff --git a/README.md b/README.md index adb783e6..ac6df5c0 100644 --- a/README.md +++ b/README.md @@ -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 `.colorscheme.bash`. You can set the color scheme with `BASH_IT_COLORSCHEME` variable, by assigning it the `` 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: diff --git a/colorschemes/dark.colorscheme.bash b/colorschemes/dark.colorscheme.bash new file mode 100644 index 00000000..9a8503e2 --- /dev/null +++ b/colorschemes/dark.colorscheme.bash @@ -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 diff --git a/colorschemes/light.colorscheme.bash b/colorschemes/light.colorscheme.bash new file mode 100644 index 00000000..f90a30fa --- /dev/null +++ b/colorschemes/light.colorscheme.bash @@ -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 diff --git a/images/dark-colorscheme.png b/images/dark-colorscheme.png new file mode 100644 index 00000000..08768272 Binary files /dev/null and b/images/dark-colorscheme.png differ diff --git a/images/light-colorscheme.png b/images/light-colorscheme.png new file mode 100644 index 00000000..05503f20 Binary files /dev/null and b/images/light-colorscheme.png differ diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 44ccb402..f0864cf4 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -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 +} diff --git a/themes/powerline-multiline/powerline-multiline.theme.bash b/themes/powerline-multiline/powerline-multiline.theme.bash index 54651cb6..583905fc 100644 --- a/themes/powerline-multiline/powerline-multiline.theme.bash +++ b/themes/powerline-multiline/powerline-multiline.theme.bash @@ -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 +