Powerline plain theme refactor

- Split functions and options in two files
- Import common functions from powerline theme
- Add README.md
pull/815/head
Eduardo Bellido Bellido 2016-10-30 01:13:05 +02:00
parent 47e6d57a82
commit 7427e7efc3
3 changed files with 114 additions and 104 deletions

View File

@ -0,0 +1,56 @@
# Powerline Theme
A colorful theme, where shows a lot information about your shell session.
## Provided Information
* Current path
* Current username and hostname
* Current time
* An indicator when connected by SSH
* An indicator when `sudo` has the credentials cached (see the `sudo` manpage for more info about this)
* An indicator when the current shell is inside the Vim editor
* Battery charging status (depends on the [../../plugins/available/battery.plugin.bash](battery plugin))
* SCM Repository status (e.g. Git, SVN)
* The current Python environment (Virtualenv, venv, and Conda are supported) in use
* The current Ruby environment (RVM) in use
* Last command exit code (only shown when the exit code is greater than 0)
## Configuration
This theme is pretty configurable, all the configuration is done by setting environment variables.
### User Information
By default, the username and hostname are shown, but you can change this behavior by setting the value of the following variable:
POWERLINE_PROMPT_USER_INFO_MODE="sudo"
For now, the only supported value is `sudo`, which hides the username and hostname, and shows an indicator when `sudo` has the credentials cached. Other values have no effect at this time.
### Clock Format
You can change the format using the following variable:
THEME_CLOCK_FORMAT="%H:%M:%S"
The time/date is printed by the `date` command, so refer to its man page to change the format.
### Segment Order
The contents of the prompt can be "reordered", all the "segments" (every piece of information) can take any place. The currently available segments are:
* battery
* clock
* cwd
* in_vim
* python_venv
* rvm
* scm
* user_info
A variables can be defined to set the order of the prompt segments:
POWERLINE_PROMPT="user_info scm python_venv rvm cwd"
The example values above are the current default values, but if you want to remove anything from the prompt, simply remove the "string" that represents the segment from the variable.

View File

@ -0,0 +1,29 @@
. "$BASH_IT/themes/powerline/powerline.base.bash"
function __powerline_left_segment {
local OLD_IFS="${IFS}"; IFS="|"
local params=( $1 )
IFS="${OLD_IFS}"
LEFT_PROMPT+="${separator}$(set_color - ${params[1]}) ${params[0]} ${normal}"
LAST_SEGMENT_COLOR=${params[1]}
}
function __powerline_prompt_command {
local last_status="$?" ## always the first
LEFT_PROMPT=""
## left prompt ##
for segment in $POWERLINE_PROMPT; do
local info="$(__powerline_${segment}_prompt)"
[[ -n "${info}" ]] && __powerline_left_segment "${info}"
done
[[ "${last_status}" -ne 0 ]] && __powerline_left_segment $(__powerline_last_status_prompt ${last_status})
[[ -n "${LEFT_PROMPT}" ]] && LEFT_PROMPT+="$(set_color ${LAST_SEGMENT_COLOR} -) ${normal}"
PS1="${LEFT_PROMPT} "
## cleanup ##
unset LEFT_PROMPT
}

View File

@ -1,124 +1,49 @@
#!/usr/bin/env bash #!/usr/bin/env bash
SHELL_SSH_CHAR="⌁ " . "$BASH_IT/themes/powerline-plain/powerline-plain.base.bash"
SHELL_THEME_PROMPT_COLOR=32
SHELL_SSH_THEME_PROMPT_COLOR=208
VIRTUALENV_CHAR="ⓔ " USER_INFO_SSH_CHAR=${POWERLINE_USER_INFO_SSH_CHAR:="⌁ "}
VIRTUALENV_THEME_PROMPT_COLOR=25 USER_INFO_THEME_PROMPT_COLOR=32
USER_INFO_THEME_PROMPT_COLOR_SUDO=202
GEMSET_CHAR="ⓔ " PYTHON_VENV_CHAR=${POWERLINE_PYTHON_VENV_CHAR:="ⓔ "}
GEMSET_THEME_PROMPT_COLOR=25 CONDA_PYTHON_VENV_CHAR=${POWERLINE_CONDA_PYTHON_VENV_CHAR:="ⓔ "}
PYTHON_VENV_THEME_PROMPT_COLOR=35
SCM_NONE_CHAR="" SCM_NONE_CHAR=""
SCM_GIT_CHAR="⎇ " SCM_GIT_CHAR=${POWERLINE_SCM_GIT_CHAR:="⎇ "}
SCM_THEME_PROMPT_CLEAN="" SCM_THEME_PROMPT_CLEAN=""
SCM_THEME_PROMPT_DIRTY="" SCM_THEME_PROMPT_DIRTY=""
SCM_THEME_PROMPT_CLEAN_COLOR=25
SCM_THEME_PROMPT_DIRTY_COLOR=88
SCM_THEME_PROMPT_STAGED_COLOR=30
SCM_THEME_PROMPT_UNSTAGED_COLOR=92
SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_CLEAN_COLOR}
SCM_THEME_PROMPT_COLOR=238 RVM_THEME_PROMPT_PREFIX=""
SCM_THEME_PROMPT_CLEAN_COLOR=231 RVM_THEME_PROMPT_SUFFIX=""
SCM_THEME_PROMPT_DIRTY_COLOR=196 RBENV_THEME_PROMPT_PREFIX=""
SCM_THEME_PROMPT_STAGED_COLOR=220 RBENV_THEME_PROMPT_SUFFIX=""
SCM_THEME_PROMPT_UNSTAGED_COLOR=166 RUBY_THEME_PROMPT_COLOR=161
RUBY_CHAR=${POWERLINE_RUBY_CHAR:="ⓔ "}
CWD_THEME_PROMPT_COLOR=240 CWD_THEME_PROMPT_COLOR=240
LAST_STATUS_THEME_PROMPT_COLOR=52 LAST_STATUS_THEME_PROMPT_COLOR=52
function set_rgb_color { CLOCK_THEME_PROMPT_COLOR=240
if [[ "${1}" != "-" ]]; then
fg="38;5;${1}"
fi
if [[ "${2}" != "-" ]]; then
bg="48;5;${2}"
[[ -n "${fg}" ]] && bg=";${bg}"
fi
echo -e "\[\033[${fg}${bg}m\]"
}
function powerline_shell_prompt { BATTERY_AC_CHAR=${BATTERY_AC_CHAR:="+ "}
if [[ -n "${SSH_CLIENT}" ]]; then BATTERY_STATUS_THEME_PROMPT_GOOD_COLOR=70
SHELL_PROMPT="${bold_white}$(set_rgb_color - ${SHELL_SSH_THEME_PROMPT_COLOR}) ${SHELL_SSH_CHAR}\u@\h ${normal}" BATTERY_STATUS_THEME_PROMPT_LOW_COLOR=208
else BATTERY_STATUS_THEME_PROMPT_CRITICAL_COLOR=160
SHELL_PROMPT="${bold_white}$(set_rgb_color - ${SHELL_THEME_PROMPT_COLOR}) \u ${normal}"
fi
}
function powerline_virtualenv_prompt { THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:="%H:%M:%S"}
local environ=""
if [[ -n "$CONDA_DEFAULT_ENV" ]]; then IN_VIM_THEME_PROMPT_COLOR=245
environ="conda: $CONDA_DEFAULT_ENV" IN_VIM_THEME_PROMPT_TEXT="vim"
elif [[ -n "$VIRTUAL_ENV" ]]; then
environ=$(basename "$VIRTUAL_ENV")
fi
if [[ -n "$environ" ]]; then POWERLINE_PROMPT=${POWERLINE_PROMPT:="user_info scm python_venv ruby cwd"}
VIRTUALENV_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} ${VIRTUALENV_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}$(set_rgb_color - ${VIRTUALENV_THEME_PROMPT_COLOR}) ${VIRTUALENV_CHAR}$environ ${normal}"
LAST_THEME_COLOR=${VIRTUALENV_THEME_PROMPT_COLOR}
else
VIRTUALENV_PROMPT=""
fi
}
function powerline_gemset_prompt { safe_append_prompt_command __powerline_prompt_command
local gemset=$(rvm-prompt 2>/dev/null)
if [[ -n "$gemset" ]]; then
GEMSET_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} ${GEMSET_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}$(set_rgb_color - ${GEMSET_THEME_PROMPT_COLOR}) ${VIRTUALENV_CHAR}$gemset ${normal}"
LAST_THEME_COLOR=${GEMSET_THEME_PROMPT_COLOR}
else
GEMSET_PROMPT=""
fi
}
function powerline_scm_prompt {
scm_prompt_vars
if [[ "${SCM_NONE_CHAR}" != "${SCM_CHAR}" ]]; then
if [[ "${SCM_DIRTY}" -eq 3 ]]; then
SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_STAGED_COLOR} ${SCM_THEME_PROMPT_COLOR})"
elif [[ "${SCM_DIRTY}" -eq 2 ]]; then
SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_UNSTAGED_COLOR} ${SCM_THEME_PROMPT_COLOR})"
elif [[ "${SCM_DIRTY}" -eq 1 ]]; then
SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_DIRTY_COLOR} ${SCM_THEME_PROMPT_COLOR})"
else
SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_CLEAN_COLOR} ${SCM_THEME_PROMPT_COLOR})"
fi
if [[ "${SCM_GIT_CHAR}" == "${SCM_CHAR}" ]]; then
SCM_PROMPT+=" ${SCM_CHAR}${SCM_BRANCH}${SCM_STATE} "
fi
SCM_PROMPT="${SCM_PROMPT}${normal}"
else
SCM_PROMPT=""
fi
}
function powerline_cwd_prompt {
CWD_PROMPT="${THEME_PROMPT_SEPARATOR}${normal}$(set_rgb_color - ${CWD_THEME_PROMPT_COLOR}) \w ${normal}$(set_rgb_color ${CWD_THEME_PROMPT_COLOR} -)${normal}"
}
function powerline_last_status_prompt {
if [[ "$1" -eq 0 ]]; then
LAST_STATUS_PROMPT=""
else
LAST_STATUS_PROMPT="$(set_rgb_color - ${LAST_STATUS_THEME_PROMPT_COLOR}) ${LAST_STATUS} ${normal}$(set_rgb_color ${LAST_STATUS_THEME_PROMPT_COLOR} -)${THEME_PROMPT_SEPARATOR}${normal}"
fi
}
function powerline_prompt_command() {
local LAST_STATUS="$?"
powerline_shell_prompt
powerline_virtualenv_prompt
powerline_gemset_prompt
powerline_scm_prompt
powerline_cwd_prompt
powerline_last_status_prompt LAST_STATUS
PS1="${SHELL_PROMPT}${GEMSET_PROMPT}${VIRTUALENV_PROMPT}${SCM_PROMPT}${CWD_PROMPT}${LAST_STATUS_PROMPT} "
}
safe_append_prompt_command powerline_prompt_command