From eb92e2f84517bd872bef51c5094e8f7a80f94613 Mon Sep 17 00:00:00 2001 From: Eduardo Bellido Bellido Date: Sat, 31 Oct 2015 23:53:52 +0100 Subject: [PATCH 01/10] Add support to change the order of the prompt info in the Powerline Multiline theme --- .../powerline-multiline.theme.bash | 75 +++++++++++-------- 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/themes/powerline-multiline/powerline-multiline.theme.bash b/themes/powerline-multiline/powerline-multiline.theme.bash index 7b690683..7ec80335 100644 --- a/themes/powerline-multiline/powerline-multiline.theme.bash +++ b/themes/powerline-multiline/powerline-multiline.theme.bash @@ -72,7 +72,7 @@ function powerline_shell_prompt { else SHELL_PROMPT="${USER}" fi - RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${#SHELL_PROMPT} + 2 )) + RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${#SHELL_PROMPT} + 3 )) SHELL_PROMPT="$(set_rgb_color - ${SHELL_PROMPT_COLOR}) ${SHELL_PROMPT} ${normal}" LAST_THEME_COLOR=${SHELL_PROMPT_COLOR} (( SEGMENT_AT_RIGHT += 1 )) @@ -80,7 +80,7 @@ function powerline_shell_prompt { "sudo") if [[ "${SHELL_PROMPT_COLOR}" == "${SHELL_THEME_PROMPT_COLOR_SUDO}" ]]; then SHELL_PROMPT="!" - RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${#SHELL_PROMPT} + 2 )) + RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${#SHELL_PROMPT} + 3 )) SHELL_PROMPT="$(set_rgb_color - ${SHELL_PROMPT_COLOR}) ${SHELL_PROMPT} ${normal}" LAST_THEME_COLOR=${SHELL_PROMPT_COLOR} (( SEGMENT_AT_RIGHT += 1 )) @@ -90,46 +90,46 @@ function powerline_shell_prompt { } function powerline_rvm_prompt { - local environ="" + local RVM_PROMPT="" if command_exists rvm; then - rvm_prompt=$(rvm_version_prompt) - if [[ "${rvm_prompt}" != $(rvm strings default) ]]; then - RVM_PROMPT="$(set_rgb_color - ${RVM_THEME_PROMPT_COLOR}) ${RVM_CHAR}${rvm_prompt} ${normal}" + RVM_PROMPT=$(rvm_version_prompt) + if [[ "${RVM_PROMPT}" != $(rvm strings default) ]]; then + RVM_PROMPT="$(set_rgb_color - ${RVM_THEME_PROMPT_COLOR}) ${RVM_CHAR}${RVM_PROMPT} ${normal}" if [[ "${SEGMENT_AT_LEFT}" -gt 0 ]]; then RVM_PROMPT=$(set_rgb_color ${LAST_THEME_COLOR} ${RVM_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}${RVM_PROMPT} fi LAST_THEME_COLOR=${RVM_THEME_PROMPT_COLOR} + LEFT_PROMPT+="${RVM_PROMPT}" (( SEGMENT_AT_LEFT += 1 )) - else - RVM_PROMPT="" fi fi } function powerline_virtualenv_prompt { - local environ="" + local VIRTUALENV_PROMPT="" if [[ -n "$CONDA_DEFAULT_ENV" ]]; then - environ="$CONDA_DEFAULT_ENV" + VIRTUALENV_PROMPT="$CONDA_DEFAULT_ENV" VIRTUALENV_CHAR=${CONDA_VIRTUALENV_CHAR} elif [[ -n "$VIRTUAL_ENV" ]]; then - environ=$(basename "$VIRTUAL_ENV") + VIRTUALENV_PROMPT=$(basename "$VIRTUAL_ENV") fi - if [[ -n "$environ" ]]; then - VIRTUALENV_PROMPT="$(set_rgb_color - ${VIRTUALENV_THEME_PROMPT_COLOR}) ${VIRTUALENV_CHAR}$environ ${normal}" + if [[ -n "$VIRTUALENV_PROMPT" ]]; then + VIRTUALENV_PROMPT="$(set_rgb_color - ${VIRTUALENV_THEME_PROMPT_COLOR}) ${VIRTUALENV_CHAR}${VIRTUALENV_PROMPT} ${normal}" if [[ "${SEGMENT_AT_LEFT}" -gt 0 ]]; then VIRTUALENV_PROMPT=$(set_rgb_color ${LAST_THEME_COLOR} ${VIRTUALENV_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}${VIRTUALENV_PROMPT} fi LAST_THEME_COLOR=${VIRTUALENV_THEME_PROMPT_COLOR} + LEFT_PROMPT+="${VIRTUALENV_PROMPT}" (( SEGMENT_AT_LEFT += 1 )) - else - VIRTUALENV_PROMPT="" fi } function powerline_scm_prompt { + local SCM_PROMPT="" + scm_prompt_vars if [[ "${SCM_NONE_CHAR}" != "${SCM_CHAR}" ]]; then if [[ "${SCM_DIRTY}" -eq 3 ]]; then @@ -142,23 +142,28 @@ function powerline_scm_prompt { SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_CLEAN_COLOR} fi if [[ "${SCM_GIT_CHAR}" == "${SCM_CHAR}" ]]; then - SCM_PROMPT=" ${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}" + SCM_PROMPT+=" ${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}" fi SCM_PROMPT="$(set_rgb_color - ${SCM_THEME_PROMPT_COLOR})${SCM_PROMPT} ${normal}" + if [[ "${SEGMENT_AT_LEFT}" -gt 0 ]]; then + SCM_PROMPT=$(set_rgb_color ${LAST_THEME_COLOR} ${SCM_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}${SCM_PROMPT} + fi + LEFT_PROMPT+="${SCM_PROMPT}" LAST_THEME_COLOR=${SCM_THEME_PROMPT_COLOR} (( SEGMENT_AT_LEFT += 1 )) - else - SCM_PROMPT="" fi } function powerline_cwd_prompt { - CWD_PROMPT="$(set_rgb_color - ${CWD_THEME_PROMPT_COLOR}) \w ${normal}$(set_rgb_color ${CWD_THEME_PROMPT_COLOR} -)${normal}$(set_rgb_color ${CWD_THEME_PROMPT_COLOR} -)${THEME_PROMPT_SEPARATOR}${normal}" + local CWD_PROMPT="" + #CWD_PROMPT="$(set_rgb_color - ${CWD_THEME_PROMPT_COLOR}) \w ${normal}$(set_rgb_color ${CWD_THEME_PROMPT_COLOR} -)${normal}$(set_rgb_color ${CWD_THEME_PROMPT_COLOR} -)${THEME_PROMPT_SEPARATOR}${normal}" + CWD_PROMPT="$(set_rgb_color - ${CWD_THEME_PROMPT_COLOR}) \w ${normal}$(set_rgb_color ${CWD_THEME_PROMPT_COLOR} -)${normal}" if [[ "${SEGMENT_AT_LEFT}" -gt 0 ]]; then CWD_PROMPT=$(set_rgb_color ${LAST_THEME_COLOR} ${CWD_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}${CWD_PROMPT} - SEGMENT_AT_LEFT=0 fi LAST_THEME_COLOR=${CWD_THEME_PROMPT_COLOR} + LEFT_PROMPT+="${CWD_PROMPT}" + (( SEGMENT_AT_LEFT += 1 )) } function powerline_last_status_prompt { @@ -204,7 +209,7 @@ function powerline_battery_status_prompt { BATTERY_PROMPT+=$(set_rgb_color ${LAST_THEME_COLOR} ${BATTERY_STATUS_THEME_PROMPT_COLOR})${THEME_PROMPT_LEFT_SEPARATOR}${normal} (( RIGHT_PROMPT_LENGTH += SEGMENT_AT_RIGHT )) else - BATTERY_STATUS+=" " + BATTERY_STATUS+=" " fi RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${#BATTERY_STATUS} + 2 )) LAST_THEME_COLOR=${BATTERY_STATUS_THEME_PROMPT_COLOR} @@ -231,22 +236,28 @@ function powerline_in_vim_prompt { function powerline_prompt_command() { local LAST_STATUS="$?" local MOVE_CURSOR_RIGHTMOST='\033[500C' + + LEFT_PROMPT="" + RIGHT_PROMPT="" SEGMENT_AT_LEFT=0 SEGMENT_AT_RIGHT=0 - RIGHT_PROMPT_LENGTH=1 - RIGHT_PROMPT="" + RIGHT_PROMPT_LENGTH=0 + LAST_THEME_COLOR="" ## left prompt ## - powerline_scm_prompt - powerline_virtualenv_prompt - powerline_rvm_prompt - powerline_cwd_prompt - powerline_last_status_prompt LAST_STATUS - - LEFT_PROMPT="${SCM_PROMPT}${VIRTUALENV_PROMPT}${RVM_PROMPT}${CWD_PROMPT}${MOVE_CURSOR_RIGHTMOST}" + if [[ -z "${THEME_RIGHT_SEGMENTS}" ]]; then + powerline_scm_prompt + powerline_virtualenv_prompt + powerline_rvm_prompt + powerline_cwd_prompt + else + for f in $THEME_RIGHT_SEGMENTS; do + $f + done + fi + [[ -n "${LEFT_PROMPT}" ]] && LEFT_PROMPT+="$(set_rgb_color ${LAST_THEME_COLOR} -)${THEME_PROMPT_SEPARATOR}${normal}" ## right prompt ## - LAST_THEME_COLOR="-" powerline_shell_prompt powerline_battery_status_prompt powerline_clock_prompt @@ -259,6 +270,8 @@ function powerline_prompt_command() { RIGHT_PROMPT+="${IN_VIM_PROMPT}${CLOCK_PROMPT}${BATTERY_PROMPT}${SHELL_PROMPT}${normal}" fi + powerline_last_status_prompt LAST_STATUS + PS1="${LEFT_PROMPT}${RIGHT_PROMPT}\n${LAST_STATUS_PROMPT}${PROMPT_CHAR} " } From 51f5614de58e30eb8e5ad5d792b817f51d0f8b60 Mon Sep 17 00:00:00 2001 From: Eduardo Bellido Bellido Date: Sat, 23 Jan 2016 21:02:07 +0100 Subject: [PATCH 02/10] Add support to change the segment order of the left and right prompt --- .../powerline-multiline.theme.bash | 155 +++++++++--------- 1 file changed, 81 insertions(+), 74 deletions(-) diff --git a/themes/powerline-multiline/powerline-multiline.theme.bash b/themes/powerline-multiline/powerline-multiline.theme.bash index 7ec80335..28887ea4 100644 --- a/themes/powerline-multiline/powerline-multiline.theme.bash +++ b/themes/powerline-multiline/powerline-multiline.theme.bash @@ -3,9 +3,9 @@ THEME_PROMPT_SEPARATOR="" THEME_PROMPT_LEFT_SEPARATOR="" -SHELL_SSH_CHAR=${SHELL_SSH_CHAR:=" "} -SHELL_THEME_PROMPT_COLOR=32 -SHELL_THEME_PROMPT_COLOR_SUDO=202 +USER_INFO_SSH_CHAR=${USER_INFO_SSH_CHAR:=" "} +USER_INFO_THEME_PROMPT_COLOR=32 +USER_INFO_THEME_PROMPT_COLOR_SUDO=202 VIRTUALENV_CHAR=${POWERLINE_VIRTUALENV_CHAR:="❲p❳ "} CONDA_VIRTUALENV_CHAR=${POWERLINE_CONDA_VIRTUALENV_CHAR:="❲c❳ "} @@ -42,11 +42,12 @@ BATTERY_STATUS_THEME_PROMPT_CRITICAL_COLOR=160 THEME_PROMPT_CLOCK_FORMAT=${THEME_PROMPT_CLOCK_FORMAT:="%H:%M:%S"} -THEME_PROMPT_USERINFO_MODE=${THEME_PROMPT_USERINFO_MODE:="default"} - IN_VIM_PROMPT_COLOR=35 IN_VIM_PROMPT_TEXT="vim" +THEME_LEFT_SEGMENTS="scm virtualenv rvm cwd" +THEME_RIGHT_SEGMENTS="in_vim clock battery user_info" + function set_rgb_color { if [[ "${1}" != "-" ]]; then @@ -59,34 +60,41 @@ function set_rgb_color { echo -e "\[\033[${fg}${bg}m\]" } -function powerline_shell_prompt { - SHELL_PROMPT="" - SHELL_PROMPT_COLOR=${SHELL_THEME_PROMPT_COLOR} +function powerline_user_info_prompt { + local offset=2 + local USER_INFO="" + local USER_INFO_PROMPT="" + USER_INFO_PROMPT_COLOR=${USER_INFO_THEME_PROMPT_COLOR} if sudo -n uptime 2>&1 | grep -q "load"; then - SHELL_PROMPT_COLOR=${SHELL_THEME_PROMPT_COLOR_SUDO} + USER_INFO_PROMPT_COLOR=${USER_INFO_THEME_PROMPT_COLOR_SUDO} fi - case "${THEME_PROMPT_USERINFO_MODE}" in - "default") - if [[ -n "${SSH_CLIENT}" ]]; then - SHELL_PROMPT="${SHELL_SSH_CHAR}${USER}@${HOSTNAME}" - else - SHELL_PROMPT="${USER}" - fi - RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${#SHELL_PROMPT} + 3 )) - SHELL_PROMPT="$(set_rgb_color - ${SHELL_PROMPT_COLOR}) ${SHELL_PROMPT} ${normal}" - LAST_THEME_COLOR=${SHELL_PROMPT_COLOR} - (( SEGMENT_AT_RIGHT += 1 )) - ;; + case "${THEME_PROMPT_USER_INFO_MODE}" in "sudo") - if [[ "${SHELL_PROMPT_COLOR}" == "${SHELL_THEME_PROMPT_COLOR_SUDO}" ]]; then - SHELL_PROMPT="!" - RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${#SHELL_PROMPT} + 3 )) - SHELL_PROMPT="$(set_rgb_color - ${SHELL_PROMPT_COLOR}) ${SHELL_PROMPT} ${normal}" - LAST_THEME_COLOR=${SHELL_PROMPT_COLOR} - (( SEGMENT_AT_RIGHT += 1 )) + if [[ "${USER_INFO_PROMPT_COLOR}" == "${USER_INFO_THEME_PROMPT_COLOR_SUDO}" ]]; then + USER_INFO="!" + fi + ;; + *) + if [[ -n "${SSH_CLIENT}" ]]; then + USER_INFO="${USER_INFO_SSH_CHAR}${USER}@${HOSTNAME}" + else + USER_INFO="${USER}" fi ;; esac + if [[ -n "${USER_INFO}" ]]; then + if [[ "${SEGMENT_AT_RIGHT}" -eq 0 ]]; then + USER_INFO_PROMPT="$(set_rgb_color ${USER_INFO_PROMPT_COLOR} -)${THEME_PROMPT_LEFT_SEPARATOR}${normal}" + else + USER_INFO_PROMPT="$(set_rgb_color ${USER_INFO_PROMPT_COLOR} ${LAST_THEME_COLOR})${THEME_PROMPT_LEFT_SEPARATOR}${normal}" + (( offset += 1 )) + fi + USER_INFO_PROMPT+="$(set_rgb_color - ${USER_INFO_PROMPT_COLOR}) ${USER_INFO} ${normal}" + RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${#USER_INFO} + ${offset} )) + LAST_THEME_COLOR=${USER_INFO_PROMPT_COLOR} + RIGHT_PROMPT+="${USER_INFO_PROMPT}" + (( SEGMENT_AT_RIGHT += 1 )) + fi } function powerline_rvm_prompt { @@ -175,59 +183,69 @@ function powerline_last_status_prompt { } function powerline_clock_prompt { - if [[ -z "${THEME_PROMPT_CLOCK_FORMAT}" ]]; then - CLOCK_PROMPT="" - else - local CLOCK=" $(date +"${THEME_PROMPT_CLOCK_FORMAT}") " - - CLOCK_PROMPT=$(set_rgb_color - ${CLOCK_THEME_PROMPT_COLOR})${CLOCK}${normal} - if [[ "${SEGMENT_AT_RIGHT}" -gt 0 ]]; then - CLOCK_PROMPT+=$(set_rgb_color ${LAST_THEME_COLOR} ${CLOCK_THEME_PROMPT_COLOR})${THEME_PROMPT_LEFT_SEPARATOR}${normal} - (( RIGHT_PROMPT_LENGTH += SEGMENT_AT_RIGHT - 1 )) - fi + local offset=0 + local CLOCK=" $(date +"${THEME_PROMPT_CLOCK_FORMAT}") " + + if [[ $? -eq 0 ]]; then + local CLOCK_PROMPT="" RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${#CLOCK} )) + if [[ "${SEGMENT_AT_RIGHT}" -eq 0 ]]; then + CLOCK_PROMPT=$(set_rgb_color ${CLOCK_THEME_PROMPT_COLOR} -) + else + CLOCK_PROMPT=$(set_rgb_color ${CLOCK_THEME_PROMPT_COLOR} ${LAST_THEME_COLOR}) + (( offset += 1 )) + fi + CLOCK_PROMPT+=${THEME_PROMPT_LEFT_SEPARATOR}${normal}$(set_rgb_color - ${CLOCK_THEME_PROMPT_COLOR})${CLOCK}${normal} LAST_THEME_COLOR=${CLOCK_THEME_PROMPT_COLOR} + RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${offset} )) + RIGHT_PROMPT+="${CLOCK_PROMPT}" (( SEGMENT_AT_RIGHT += 1 )) fi } -function powerline_battery_status_prompt { - BATTERY_STATUS="$(battery_percentage 2> /dev/null)" +function powerline_battery_prompt { + local offset=3 + local BATTERY_STATUS="$(battery_percentage 2> /dev/null)" if [[ -z "${BATTERY_STATUS}" ]] || [[ "${BATTERY_STATUS}" = "-1" ]] || [[ "${BATTERY_STATUS}" = "no" ]]; then - BATTERY_PROMPT="" + true else + local BATTERY_PROMPT="" if [[ "$((10#${BATTERY_STATUS}))" -le 5 ]]; then - BATTERY_STATUS_THEME_PROMPT_COLOR="${BATTERY_STATUS_THEME_PROMPT_CRITICAL_COLOR}" + BATTERY_STATUS_THEME_PROMPT_COLOR="${BATTERY_STATUS_THEME_PROMPT_CRITICAL_COLOR}" elif [[ "$((10#${BATTERY_STATUS}))" -le 25 ]]; then BATTERY_STATUS_THEME_PROMPT_COLOR="${BATTERY_STATUS_THEME_PROMPT_LOW_COLOR}" else BATTERY_STATUS_THEME_PROMPT_COLOR="${BATTERY_STATUS_THEME_PROMPT_GOOD_COLOR}" fi [[ "$(ac_adapter_connected)" ]] && BATTERY_STATUS="${BATTERY_AC_CHAR}${BATTERY_STATUS}" - BATTERY_PROMPT="$(set_rgb_color - ${BATTERY_STATUS_THEME_PROMPT_COLOR}) ${BATTERY_STATUS}% " - if [[ "${SEGMENT_AT_RIGHT}" -gt 0 ]]; then - BATTERY_PROMPT+=$(set_rgb_color ${LAST_THEME_COLOR} ${BATTERY_STATUS_THEME_PROMPT_COLOR})${THEME_PROMPT_LEFT_SEPARATOR}${normal} - (( RIGHT_PROMPT_LENGTH += SEGMENT_AT_RIGHT )) + if [[ "${SEGMENT_AT_RIGHT}" -eq 0 ]]; then + BATTERY_PROMPT=$(set_rgb_color ${BATTERY_STATUS_THEME_PROMPT_COLOR} -)${THEME_PROMPT_LEFT_SEPARATOR}${normal} else - BATTERY_STATUS+=" " + BATTERY_PROMPT=$(set_rgb_color ${BATTERY_STATUS_THEME_PROMPT_COLOR} ${LAST_THEME_COLOR})${THEME_PROMPT_LEFT_SEPARATOR}${normal} + (( offset +=1 )) fi - RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${#BATTERY_STATUS} + 2 )) + BATTERY_PROMPT+="$(set_rgb_color - ${BATTERY_STATUS_THEME_PROMPT_COLOR}) ${BATTERY_STATUS}% ${normal}" + RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${#BATTERY_STATUS} + ${offset} )) LAST_THEME_COLOR=${BATTERY_STATUS_THEME_PROMPT_COLOR} + RIGHT_PROMPT+="${BATTERY_PROMPT}" (( SEGMENT_AT_RIGHT += 1 )) fi } function powerline_in_vim_prompt { - if [ -z "$VIMRUNTIME" ]; then - IN_VIM_PROMPT="" - else - IN_VIM_PROMPT="$(set_rgb_color - ${IN_VIM_PROMPT_COLOR}) ${IN_VIM_PROMPT_TEXT} " - if [[ "${SEGMENT_AT_RIGHT}" -gt 0 ]]; then - IN_VIM_PROMPT+=$(set_rgb_color ${LAST_THEME_COLOR} ${IN_VIM_PROMPT_COLOR})${THEME_PROMPT_LEFT_SEPARATOR}${normal} - (( RIGHT_PROMPT_LENGTH += SEGMENT_AT_RIGHT )) + local offset=2 + local IN_VIM_PROMPT="" + if [ -n "$VIMRUNTIME" ]; then + if [[ "${SEGMENT_AT_RIGHT}" -eq 0 ]]; then + IN_VIM_PROMPT+=$(set_rgb_color ${IN_VIM_PROMPT_COLOR} -)${THEME_PROMPT_LEFT_SEPARATOR}${normal} + else + IN_VIM_PROMPT+=$(set_rgb_color ${IN_VIM_PROMPT_COLOR} ${LAST_THEME_COLOR})${THEME_PROMPT_LEFT_SEPARATOR}${normal} + (( offset += 1 )) fi - RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${#IN_VIM_PROMPT_TEXT} )) + IN_VIM_PROMPT+="$(set_rgb_color - ${IN_VIM_PROMPT_COLOR}) ${IN_VIM_PROMPT_TEXT} ${normal}" + RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${#IN_VIM_PROMPT_TEXT} + ${offset})) LAST_THEME_COLOR=${IN_VIM_PROMPT_COLOR} + RIGHT_PROMPT+="${IN_VIM_PROMPT}" (( SEGMENT_AT_RIGHT += 1 )) fi } @@ -245,29 +263,18 @@ function powerline_prompt_command() { LAST_THEME_COLOR="" ## left prompt ## - if [[ -z "${THEME_RIGHT_SEGMENTS}" ]]; then - powerline_scm_prompt - powerline_virtualenv_prompt - powerline_rvm_prompt - powerline_cwd_prompt - else - for f in $THEME_RIGHT_SEGMENTS; do - $f - done - fi + for segment in $THEME_LEFT_SEGMENTS; do + "powerline_${segment}_prompt" + done [[ -n "${LEFT_PROMPT}" ]] && LEFT_PROMPT+="$(set_rgb_color ${LAST_THEME_COLOR} -)${THEME_PROMPT_SEPARATOR}${normal}" ## right prompt ## - powerline_shell_prompt - powerline_battery_status_prompt - powerline_clock_prompt - powerline_in_vim_prompt - - if [[ "${SEGMENT_AT_RIGHT}" -gt 0 ]]; then + if [[ -n "${THEME_RIGHT_SEGMENTS}" ]]; then LEFT_PROMPT+="${MOVE_CURSOR_RIGHTMOST}" - [[ "${SEGMENT_AT_RIGHT}" -eq 1 ]] && (( RIGHT_PROMPT_LENGTH-=1 )) - RIGHT_PROMPT="\033[${RIGHT_PROMPT_LENGTH}D$(set_rgb_color ${LAST_THEME_COLOR} -)${THEME_PROMPT_LEFT_SEPARATOR}${normal}" - RIGHT_PROMPT+="${IN_VIM_PROMPT}${CLOCK_PROMPT}${BATTERY_PROMPT}${SHELL_PROMPT}${normal}" + for segment in $THEME_RIGHT_SEGMENTS; do + "powerline_${segment}_prompt" + done + LEFT_PROMPT+="\033[${RIGHT_PROMPT_LENGTH}D" fi powerline_last_status_prompt LAST_STATUS From 1009b2372459c05ccfbe88be04f79424f7fababd Mon Sep 17 00:00:00 2001 From: Eduardo Bellido Bellido Date: Mon, 25 Jan 2016 20:01:00 +0100 Subject: [PATCH 03/10] Minor fixes --- themes/powerline-multiline/powerline-multiline.theme.bash | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/themes/powerline-multiline/powerline-multiline.theme.bash b/themes/powerline-multiline/powerline-multiline.theme.bash index 28887ea4..cb63f1e9 100644 --- a/themes/powerline-multiline/powerline-multiline.theme.bash +++ b/themes/powerline-multiline/powerline-multiline.theme.bash @@ -42,7 +42,7 @@ BATTERY_STATUS_THEME_PROMPT_CRITICAL_COLOR=160 THEME_PROMPT_CLOCK_FORMAT=${THEME_PROMPT_CLOCK_FORMAT:="%H:%M:%S"} -IN_VIM_PROMPT_COLOR=35 +IN_VIM_PROMPT_COLOR=245 IN_VIM_PROMPT_TEXT="vim" THEME_LEFT_SEGMENTS="scm virtualenv rvm cwd" @@ -185,7 +185,7 @@ function powerline_last_status_prompt { function powerline_clock_prompt { local offset=0 local CLOCK=" $(date +"${THEME_PROMPT_CLOCK_FORMAT}") " - + if [[ $? -eq 0 ]]; then local CLOCK_PROMPT="" RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${#CLOCK} )) @@ -237,7 +237,7 @@ function powerline_in_vim_prompt { local IN_VIM_PROMPT="" if [ -n "$VIMRUNTIME" ]; then if [[ "${SEGMENT_AT_RIGHT}" -eq 0 ]]; then - IN_VIM_PROMPT+=$(set_rgb_color ${IN_VIM_PROMPT_COLOR} -)${THEME_PROMPT_LEFT_SEPARATOR}${normal} + IN_VIM_PROMPT+="$(set_rgb_color ${IN_VIM_PROMPT_COLOR} -)${THEME_PROMPT_LEFT_SEPARATOR}${normal}" else IN_VIM_PROMPT+=$(set_rgb_color ${IN_VIM_PROMPT_COLOR} ${LAST_THEME_COLOR})${THEME_PROMPT_LEFT_SEPARATOR}${normal} (( offset += 1 )) From 64e6f354dcd37fe0a2e350736d4536ef4a7be905 Mon Sep 17 00:00:00 2001 From: Eduardo Bellido Bellido Date: Mon, 25 Jan 2016 20:01:37 +0100 Subject: [PATCH 04/10] Add Powerline Multiline theme README.md --- themes/powerline-multiline/README.md | 63 ++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 themes/powerline-multiline/README.md diff --git a/themes/powerline-multiline/README.md b/themes/powerline-multiline/README.md new file mode 100644 index 00000000..d0f6bfb8 --- /dev/null +++ b/themes/powerline-multiline/README.md @@ -0,0 +1,63 @@ +# Powerline Multiline Theme + +Colorfull multiline theme, the first line shows information about your shell session (divided into two parts, left and right), the second one is where the shell commands are introduced. + +## Information provided + +* Current path +* Current username and hostname +* 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 battery plugin) +* Repository status +* The current Python enviroment (Virtualenv, venv, and Conda are supported) in use +* The current Ruby enviroment (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 at the right side, but you can change this behavior setting the value of the following variable: + + THEME_PROMPT_USER_INFO_MODE + +for now, the only supported value is `sudo`, that hides the username and hostname, and shows an indicator when the sudo has the credentials cached. Any other value has no effect. + +### Clock format + +By default, the current time is shown at the right side, you can change the format with the variable: + + THEME_PROMPT_CLOCK_FORMAT="%H:%M:%S" + +the date is printed by the `date` command, so refer to its man page to change the format. + +### Segment order + +Both prompt sides can be "reordered", all the "segments" (every piece of information) can take any place, the only restriction (for now), is that some segments only can be placed at left, and others only at right. + +Current available left "segments": + +* scm +* virtualenv +* rvm +* cwd + +Current available right "segments": + +* in_vim +* clock +* battery +* user_info + +Two variables can be defined to set the order of the prompt segments: + + THEME_LEFT_SEGMENTS="scm virtualenv rvm cwd" + THEME_RIGHT_SEGMENTS="in_vim clock battery user_info" + +if you want to remove something else from the prompt, simply remove the "string" that represents the segment from the corresponding variable. + + From dfbd065bc1e8ca2fa31da53f239d719796c3c1a6 Mon Sep 17 00:00:00 2001 From: Eduardo Bellido Bellido Date: Mon, 25 Jan 2016 21:49:50 +0100 Subject: [PATCH 05/10] Fix indentation --- .../powerline-multiline.theme.bash | 355 +++++++++--------- 1 file changed, 177 insertions(+), 178 deletions(-) diff --git a/themes/powerline-multiline/powerline-multiline.theme.bash b/themes/powerline-multiline/powerline-multiline.theme.bash index cb63f1e9..33640057 100644 --- a/themes/powerline-multiline/powerline-multiline.theme.bash +++ b/themes/powerline-multiline/powerline-multiline.theme.bash @@ -50,236 +50,235 @@ THEME_RIGHT_SEGMENTS="in_vim clock battery user_info" function set_rgb_color { - 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\]" + 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_user_info_prompt { - local offset=2 - local USER_INFO="" - local USER_INFO_PROMPT="" - USER_INFO_PROMPT_COLOR=${USER_INFO_THEME_PROMPT_COLOR} - if sudo -n uptime 2>&1 | grep -q "load"; then - USER_INFO_PROMPT_COLOR=${USER_INFO_THEME_PROMPT_COLOR_SUDO} - fi - case "${THEME_PROMPT_USER_INFO_MODE}" in - "sudo") - if [[ "${USER_INFO_PROMPT_COLOR}" == "${USER_INFO_THEME_PROMPT_COLOR_SUDO}" ]]; then - USER_INFO="!" - fi - ;; - *) - if [[ -n "${SSH_CLIENT}" ]]; then - USER_INFO="${USER_INFO_SSH_CHAR}${USER}@${HOSTNAME}" - else - USER_INFO="${USER}" - fi - ;; - esac - if [[ -n "${USER_INFO}" ]]; then - if [[ "${SEGMENT_AT_RIGHT}" -eq 0 ]]; then - USER_INFO_PROMPT="$(set_rgb_color ${USER_INFO_PROMPT_COLOR} -)${THEME_PROMPT_LEFT_SEPARATOR}${normal}" - else - USER_INFO_PROMPT="$(set_rgb_color ${USER_INFO_PROMPT_COLOR} ${LAST_THEME_COLOR})${THEME_PROMPT_LEFT_SEPARATOR}${normal}" - (( offset += 1 )) - fi - USER_INFO_PROMPT+="$(set_rgb_color - ${USER_INFO_PROMPT_COLOR}) ${USER_INFO} ${normal}" - RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${#USER_INFO} + ${offset} )) - LAST_THEME_COLOR=${USER_INFO_PROMPT_COLOR} - RIGHT_PROMPT+="${USER_INFO_PROMPT}" - (( SEGMENT_AT_RIGHT += 1 )) + local offset=2 + local USER_INFO="" + local USER_INFO_PROMPT="" + USER_INFO_PROMPT_COLOR=${USER_INFO_THEME_PROMPT_COLOR} + if sudo -n uptime 2>&1 | grep -q "load"; then + USER_INFO_PROMPT_COLOR=${USER_INFO_THEME_PROMPT_COLOR_SUDO} + fi + case "${THEME_PROMPT_USER_INFO_MODE}" in + "sudo") + if [[ "${USER_INFO_PROMPT_COLOR}" == "${USER_INFO_THEME_PROMPT_COLOR_SUDO}" ]]; then + USER_INFO="!" + fi + ;; + *) + if [[ -n "${SSH_CLIENT}" ]]; then + USER_INFO="${USER_INFO_SSH_CHAR}${USER}@${HOSTNAME}" + else + USER_INFO="${USER}" + fi + ;; + esac + if [[ -n "${USER_INFO}" ]]; then + if [[ "${SEGMENT_AT_RIGHT}" -eq 0 ]]; then + USER_INFO_PROMPT="$(set_rgb_color ${USER_INFO_PROMPT_COLOR} -)${THEME_PROMPT_LEFT_SEPARATOR}${normal}" + else + USER_INFO_PROMPT="$(set_rgb_color ${USER_INFO_PROMPT_COLOR} ${LAST_THEME_COLOR})${THEME_PROMPT_LEFT_SEPARATOR}${normal}" + (( offset += 1 )) fi + USER_INFO_PROMPT+="$(set_rgb_color - ${USER_INFO_PROMPT_COLOR}) ${USER_INFO} ${normal}" + RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${#USER_INFO} + ${offset} )) + LAST_THEME_COLOR=${USER_INFO_PROMPT_COLOR} + RIGHT_PROMPT+="${USER_INFO_PROMPT}" + (( SEGMENT_AT_RIGHT += 1 )) + fi } function powerline_rvm_prompt { - local RVM_PROMPT="" + local RVM_PROMPT="" - if command_exists rvm; then - RVM_PROMPT=$(rvm_version_prompt) - if [[ "${RVM_PROMPT}" != $(rvm strings default) ]]; then - RVM_PROMPT="$(set_rgb_color - ${RVM_THEME_PROMPT_COLOR}) ${RVM_CHAR}${RVM_PROMPT} ${normal}" - if [[ "${SEGMENT_AT_LEFT}" -gt 0 ]]; then - RVM_PROMPT=$(set_rgb_color ${LAST_THEME_COLOR} ${RVM_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}${RVM_PROMPT} - fi - LAST_THEME_COLOR=${RVM_THEME_PROMPT_COLOR} - LEFT_PROMPT+="${RVM_PROMPT}" - (( SEGMENT_AT_LEFT += 1 )) - fi + if command_exists rvm; then + RVM_PROMPT=$(rvm_version_prompt) + if [[ "${RVM_PROMPT}" != $(rvm strings default) ]]; then + RVM_PROMPT="$(set_rgb_color - ${RVM_THEME_PROMPT_COLOR}) ${RVM_CHAR}${RVM_PROMPT} ${normal}" + if [[ "${SEGMENT_AT_LEFT}" -gt 0 ]]; then + RVM_PROMPT=$(set_rgb_color ${LAST_THEME_COLOR} ${RVM_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}${RVM_PROMPT} + fi + LAST_THEME_COLOR=${RVM_THEME_PROMPT_COLOR} + LEFT_PROMPT+="${RVM_PROMPT}" + (( SEGMENT_AT_LEFT += 1 )) fi + fi } function powerline_virtualenv_prompt { - local VIRTUALENV_PROMPT="" + local VIRTUALENV_PROMPT="" - if [[ -n "$CONDA_DEFAULT_ENV" ]]; then - VIRTUALENV_PROMPT="$CONDA_DEFAULT_ENV" - VIRTUALENV_CHAR=${CONDA_VIRTUALENV_CHAR} - elif [[ -n "$VIRTUAL_ENV" ]]; then - VIRTUALENV_PROMPT=$(basename "$VIRTUAL_ENV") - fi + if [[ -n "$CONDA_DEFAULT_ENV" ]]; then + VIRTUALENV_PROMPT="$CONDA_DEFAULT_ENV" + VIRTUALENV_CHAR=${CONDA_VIRTUALENV_CHAR} + elif [[ -n "$VIRTUAL_ENV" ]]; then + VIRTUALENV_PROMPT=$(basename "$VIRTUAL_ENV") + fi - if [[ -n "$VIRTUALENV_PROMPT" ]]; then - VIRTUALENV_PROMPT="$(set_rgb_color - ${VIRTUALENV_THEME_PROMPT_COLOR}) ${VIRTUALENV_CHAR}${VIRTUALENV_PROMPT} ${normal}" - if [[ "${SEGMENT_AT_LEFT}" -gt 0 ]]; then - VIRTUALENV_PROMPT=$(set_rgb_color ${LAST_THEME_COLOR} ${VIRTUALENV_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}${VIRTUALENV_PROMPT} - fi - LAST_THEME_COLOR=${VIRTUALENV_THEME_PROMPT_COLOR} - LEFT_PROMPT+="${VIRTUALENV_PROMPT}" - (( SEGMENT_AT_LEFT += 1 )) + if [[ -n "$VIRTUALENV_PROMPT" ]]; then + VIRTUALENV_PROMPT="$(set_rgb_color - ${VIRTUALENV_THEME_PROMPT_COLOR}) ${VIRTUALENV_CHAR}${VIRTUALENV_PROMPT} ${normal}" + if [[ "${SEGMENT_AT_LEFT}" -gt 0 ]]; then + VIRTUALENV_PROMPT=$(set_rgb_color ${LAST_THEME_COLOR} ${VIRTUALENV_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}${VIRTUALENV_PROMPT} fi + LAST_THEME_COLOR=${VIRTUALENV_THEME_PROMPT_COLOR} + LEFT_PROMPT+="${VIRTUALENV_PROMPT}" + (( SEGMENT_AT_LEFT += 1 )) + fi } function powerline_scm_prompt { - local SCM_PROMPT="" + local SCM_PROMPT="" - scm_prompt_vars - if [[ "${SCM_NONE_CHAR}" != "${SCM_CHAR}" ]]; then - if [[ "${SCM_DIRTY}" -eq 3 ]]; then - SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_STAGED_COLOR} - elif [[ "${SCM_DIRTY}" -eq 2 ]]; then - SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_UNSTAGED_COLOR} - elif [[ "${SCM_DIRTY}" -eq 1 ]]; then - SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_DIRTY_COLOR} - else - SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_CLEAN_COLOR} - fi - if [[ "${SCM_GIT_CHAR}" == "${SCM_CHAR}" ]]; then - SCM_PROMPT+=" ${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}" - fi - SCM_PROMPT="$(set_rgb_color - ${SCM_THEME_PROMPT_COLOR})${SCM_PROMPT} ${normal}" - if [[ "${SEGMENT_AT_LEFT}" -gt 0 ]]; then - SCM_PROMPT=$(set_rgb_color ${LAST_THEME_COLOR} ${SCM_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}${SCM_PROMPT} - fi - LEFT_PROMPT+="${SCM_PROMPT}" - LAST_THEME_COLOR=${SCM_THEME_PROMPT_COLOR} - (( SEGMENT_AT_LEFT += 1 )) + scm_prompt_vars + if [[ "${SCM_NONE_CHAR}" != "${SCM_CHAR}" ]]; then + if [[ "${SCM_DIRTY}" -eq 3 ]]; then + SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_STAGED_COLOR} + elif [[ "${SCM_DIRTY}" -eq 2 ]]; then + SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_UNSTAGED_COLOR} + elif [[ "${SCM_DIRTY}" -eq 1 ]]; then + SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_DIRTY_COLOR} + else + SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_CLEAN_COLOR} fi + if [[ "${SCM_GIT_CHAR}" == "${SCM_CHAR}" ]]; then + SCM_PROMPT+=" ${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}" + fi + SCM_PROMPT="$(set_rgb_color - ${SCM_THEME_PROMPT_COLOR})${SCM_PROMPT} ${normal}" + if [[ "${SEGMENT_AT_LEFT}" -gt 0 ]]; then + SCM_PROMPT=$(set_rgb_color ${LAST_THEME_COLOR} ${SCM_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}${SCM_PROMPT} + fi + LEFT_PROMPT+="${SCM_PROMPT}" + LAST_THEME_COLOR=${SCM_THEME_PROMPT_COLOR} + (( SEGMENT_AT_LEFT += 1 )) + fi } function powerline_cwd_prompt { - local CWD_PROMPT="" - #CWD_PROMPT="$(set_rgb_color - ${CWD_THEME_PROMPT_COLOR}) \w ${normal}$(set_rgb_color ${CWD_THEME_PROMPT_COLOR} -)${normal}$(set_rgb_color ${CWD_THEME_PROMPT_COLOR} -)${THEME_PROMPT_SEPARATOR}${normal}" - CWD_PROMPT="$(set_rgb_color - ${CWD_THEME_PROMPT_COLOR}) \w ${normal}$(set_rgb_color ${CWD_THEME_PROMPT_COLOR} -)${normal}" - if [[ "${SEGMENT_AT_LEFT}" -gt 0 ]]; then - CWD_PROMPT=$(set_rgb_color ${LAST_THEME_COLOR} ${CWD_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}${CWD_PROMPT} - fi - LAST_THEME_COLOR=${CWD_THEME_PROMPT_COLOR} - LEFT_PROMPT+="${CWD_PROMPT}" - (( SEGMENT_AT_LEFT += 1 )) + local CWD_PROMPT="" + CWD_PROMPT="$(set_rgb_color - ${CWD_THEME_PROMPT_COLOR}) \w ${normal}$(set_rgb_color ${CWD_THEME_PROMPT_COLOR} -)${normal}" + if [[ "${SEGMENT_AT_LEFT}" -gt 0 ]]; then + CWD_PROMPT=$(set_rgb_color ${LAST_THEME_COLOR} ${CWD_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}${CWD_PROMPT} + fi + LAST_THEME_COLOR=${CWD_THEME_PROMPT_COLOR} + LEFT_PROMPT+="${CWD_PROMPT}" + (( SEGMENT_AT_LEFT += 1 )) } 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}" - fi + if [[ "$1" -eq 0 ]]; then + LAST_STATUS_PROMPT="" + else + LAST_STATUS_PROMPT="$(set_rgb_color ${LAST_STATUS_THEME_PROMPT_COLOR} -) ${LAST_STATUS} ${normal}" + fi } function powerline_clock_prompt { - local offset=0 - local CLOCK=" $(date +"${THEME_PROMPT_CLOCK_FORMAT}") " + local offset=0 + local CLOCK=" $(date +"${THEME_PROMPT_CLOCK_FORMAT}") " - if [[ $? -eq 0 ]]; then - local CLOCK_PROMPT="" - RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${#CLOCK} )) - if [[ "${SEGMENT_AT_RIGHT}" -eq 0 ]]; then - CLOCK_PROMPT=$(set_rgb_color ${CLOCK_THEME_PROMPT_COLOR} -) - else - CLOCK_PROMPT=$(set_rgb_color ${CLOCK_THEME_PROMPT_COLOR} ${LAST_THEME_COLOR}) - (( offset += 1 )) - fi - CLOCK_PROMPT+=${THEME_PROMPT_LEFT_SEPARATOR}${normal}$(set_rgb_color - ${CLOCK_THEME_PROMPT_COLOR})${CLOCK}${normal} - LAST_THEME_COLOR=${CLOCK_THEME_PROMPT_COLOR} - RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${offset} )) - RIGHT_PROMPT+="${CLOCK_PROMPT}" - (( SEGMENT_AT_RIGHT += 1 )) + if [[ $? -eq 0 ]]; then + local CLOCK_PROMPT="" + RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${#CLOCK} )) + if [[ "${SEGMENT_AT_RIGHT}" -eq 0 ]]; then + CLOCK_PROMPT=$(set_rgb_color ${CLOCK_THEME_PROMPT_COLOR} -) + else + CLOCK_PROMPT=$(set_rgb_color ${CLOCK_THEME_PROMPT_COLOR} ${LAST_THEME_COLOR}) + (( offset += 1 )) fi + CLOCK_PROMPT+=${THEME_PROMPT_LEFT_SEPARATOR}${normal}$(set_rgb_color - ${CLOCK_THEME_PROMPT_COLOR})${CLOCK}${normal} + LAST_THEME_COLOR=${CLOCK_THEME_PROMPT_COLOR} + RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${offset} )) + RIGHT_PROMPT+="${CLOCK_PROMPT}" + (( SEGMENT_AT_RIGHT += 1 )) + fi } function powerline_battery_prompt { - local offset=3 - local BATTERY_STATUS="$(battery_percentage 2> /dev/null)" - if [[ -z "${BATTERY_STATUS}" ]] || [[ "${BATTERY_STATUS}" = "-1" ]] || [[ "${BATTERY_STATUS}" = "no" ]]; then - true + local offset=3 + local BATTERY_STATUS="$(battery_percentage 2> /dev/null)" + if [[ -z "${BATTERY_STATUS}" ]] || [[ "${BATTERY_STATUS}" = "-1" ]] || [[ "${BATTERY_STATUS}" = "no" ]]; then + true + else + local BATTERY_PROMPT="" + if [[ "$((10#${BATTERY_STATUS}))" -le 5 ]]; then + BATTERY_STATUS_THEME_PROMPT_COLOR="${BATTERY_STATUS_THEME_PROMPT_CRITICAL_COLOR}" + elif [[ "$((10#${BATTERY_STATUS}))" -le 25 ]]; then + BATTERY_STATUS_THEME_PROMPT_COLOR="${BATTERY_STATUS_THEME_PROMPT_LOW_COLOR}" else - local BATTERY_PROMPT="" - if [[ "$((10#${BATTERY_STATUS}))" -le 5 ]]; then - BATTERY_STATUS_THEME_PROMPT_COLOR="${BATTERY_STATUS_THEME_PROMPT_CRITICAL_COLOR}" - elif [[ "$((10#${BATTERY_STATUS}))" -le 25 ]]; then - BATTERY_STATUS_THEME_PROMPT_COLOR="${BATTERY_STATUS_THEME_PROMPT_LOW_COLOR}" - else - BATTERY_STATUS_THEME_PROMPT_COLOR="${BATTERY_STATUS_THEME_PROMPT_GOOD_COLOR}" - fi - [[ "$(ac_adapter_connected)" ]] && BATTERY_STATUS="${BATTERY_AC_CHAR}${BATTERY_STATUS}" - if [[ "${SEGMENT_AT_RIGHT}" -eq 0 ]]; then - BATTERY_PROMPT=$(set_rgb_color ${BATTERY_STATUS_THEME_PROMPT_COLOR} -)${THEME_PROMPT_LEFT_SEPARATOR}${normal} - else - BATTERY_PROMPT=$(set_rgb_color ${BATTERY_STATUS_THEME_PROMPT_COLOR} ${LAST_THEME_COLOR})${THEME_PROMPT_LEFT_SEPARATOR}${normal} - (( offset +=1 )) - fi - BATTERY_PROMPT+="$(set_rgb_color - ${BATTERY_STATUS_THEME_PROMPT_COLOR}) ${BATTERY_STATUS}% ${normal}" - RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${#BATTERY_STATUS} + ${offset} )) - LAST_THEME_COLOR=${BATTERY_STATUS_THEME_PROMPT_COLOR} - RIGHT_PROMPT+="${BATTERY_PROMPT}" - (( SEGMENT_AT_RIGHT += 1 )) + BATTERY_STATUS_THEME_PROMPT_COLOR="${BATTERY_STATUS_THEME_PROMPT_GOOD_COLOR}" fi + [[ "$(ac_adapter_connected)" ]] && BATTERY_STATUS="${BATTERY_AC_CHAR}${BATTERY_STATUS}" + if [[ "${SEGMENT_AT_RIGHT}" -eq 0 ]]; then + BATTERY_PROMPT=$(set_rgb_color ${BATTERY_STATUS_THEME_PROMPT_COLOR} -)${THEME_PROMPT_LEFT_SEPARATOR}${normal} + else + BATTERY_PROMPT=$(set_rgb_color ${BATTERY_STATUS_THEME_PROMPT_COLOR} ${LAST_THEME_COLOR})${THEME_PROMPT_LEFT_SEPARATOR}${normal} + (( offset +=1 )) + fi + BATTERY_PROMPT+="$(set_rgb_color - ${BATTERY_STATUS_THEME_PROMPT_COLOR}) ${BATTERY_STATUS}% ${normal}" + RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${#BATTERY_STATUS} + ${offset} )) + LAST_THEME_COLOR=${BATTERY_STATUS_THEME_PROMPT_COLOR} + RIGHT_PROMPT+="${BATTERY_PROMPT}" + (( SEGMENT_AT_RIGHT += 1 )) + fi } function powerline_in_vim_prompt { local offset=2 local IN_VIM_PROMPT="" if [ -n "$VIMRUNTIME" ]; then - if [[ "${SEGMENT_AT_RIGHT}" -eq 0 ]]; then - IN_VIM_PROMPT+="$(set_rgb_color ${IN_VIM_PROMPT_COLOR} -)${THEME_PROMPT_LEFT_SEPARATOR}${normal}" - else - IN_VIM_PROMPT+=$(set_rgb_color ${IN_VIM_PROMPT_COLOR} ${LAST_THEME_COLOR})${THEME_PROMPT_LEFT_SEPARATOR}${normal} - (( offset += 1 )) - fi - IN_VIM_PROMPT+="$(set_rgb_color - ${IN_VIM_PROMPT_COLOR}) ${IN_VIM_PROMPT_TEXT} ${normal}" - RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${#IN_VIM_PROMPT_TEXT} + ${offset})) - LAST_THEME_COLOR=${IN_VIM_PROMPT_COLOR} - RIGHT_PROMPT+="${IN_VIM_PROMPT}" - (( SEGMENT_AT_RIGHT += 1 )) + if [[ "${SEGMENT_AT_RIGHT}" -eq 0 ]]; then + IN_VIM_PROMPT+="$(set_rgb_color ${IN_VIM_PROMPT_COLOR} -)${THEME_PROMPT_LEFT_SEPARATOR}${normal}" + else + IN_VIM_PROMPT+=$(set_rgb_color ${IN_VIM_PROMPT_COLOR} ${LAST_THEME_COLOR})${THEME_PROMPT_LEFT_SEPARATOR}${normal} + (( offset += 1 )) + fi + IN_VIM_PROMPT+="$(set_rgb_color - ${IN_VIM_PROMPT_COLOR}) ${IN_VIM_PROMPT_TEXT} ${normal}" + RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${#IN_VIM_PROMPT_TEXT} + ${offset})) + LAST_THEME_COLOR=${IN_VIM_PROMPT_COLOR} + RIGHT_PROMPT+="${IN_VIM_PROMPT}" + (( SEGMENT_AT_RIGHT += 1 )) fi } function powerline_prompt_command() { - local LAST_STATUS="$?" - local MOVE_CURSOR_RIGHTMOST='\033[500C' + local LAST_STATUS="$?" + local MOVE_CURSOR_RIGHTMOST='\033[500C' - LEFT_PROMPT="" - RIGHT_PROMPT="" - SEGMENT_AT_LEFT=0 - SEGMENT_AT_RIGHT=0 - RIGHT_PROMPT_LENGTH=0 - LAST_THEME_COLOR="" + LEFT_PROMPT="" + RIGHT_PROMPT="" + SEGMENT_AT_LEFT=0 + SEGMENT_AT_RIGHT=0 + RIGHT_PROMPT_LENGTH=0 + LAST_THEME_COLOR="" - ## left prompt ## - for segment in $THEME_LEFT_SEGMENTS; do - "powerline_${segment}_prompt" + ## left prompt ## + for segment in $THEME_LEFT_SEGMENTS; do + "powerline_${segment}_prompt" + done + [[ -n "${LEFT_PROMPT}" ]] && LEFT_PROMPT+="$(set_rgb_color ${LAST_THEME_COLOR} -)${THEME_PROMPT_SEPARATOR}${normal}" + + ## right prompt ## + if [[ -n "${THEME_RIGHT_SEGMENTS}" ]]; then + LEFT_PROMPT+="${MOVE_CURSOR_RIGHTMOST}" + for segment in $THEME_RIGHT_SEGMENTS; do + "powerline_${segment}_prompt" done - [[ -n "${LEFT_PROMPT}" ]] && LEFT_PROMPT+="$(set_rgb_color ${LAST_THEME_COLOR} -)${THEME_PROMPT_SEPARATOR}${normal}" + LEFT_PROMPT+="\033[${RIGHT_PROMPT_LENGTH}D" + fi - ## right prompt ## - if [[ -n "${THEME_RIGHT_SEGMENTS}" ]]; then - LEFT_PROMPT+="${MOVE_CURSOR_RIGHTMOST}" - for segment in $THEME_RIGHT_SEGMENTS; do - "powerline_${segment}_prompt" - done - LEFT_PROMPT+="\033[${RIGHT_PROMPT_LENGTH}D" - fi + powerline_last_status_prompt LAST_STATUS - powerline_last_status_prompt LAST_STATUS - - PS1="${LEFT_PROMPT}${RIGHT_PROMPT}\n${LAST_STATUS_PROMPT}${PROMPT_CHAR} " + PS1="${LEFT_PROMPT}${RIGHT_PROMPT}\n${LAST_STATUS_PROMPT}${PROMPT_CHAR} " } PROMPT_COMMAND=powerline_prompt_command From 6d4923aca81b443826d7a2593839b00afa8ea83e Mon Sep 17 00:00:00 2001 From: Eduardo Bellido Bellido Date: Wed, 27 Jan 2016 01:07:14 +0100 Subject: [PATCH 06/10] Now, segments can be placed at left or at right - Code refactor - Print code converted into functions - Remove unused variables - Improved conistence in naming, variable and functions --- .../powerline-multiline.theme.bash | 292 ++++++++---------- 1 file changed, 128 insertions(+), 164 deletions(-) diff --git a/themes/powerline-multiline/powerline-multiline.theme.bash b/themes/powerline-multiline/powerline-multiline.theme.bash index 33640057..edd7b82d 100644 --- a/themes/powerline-multiline/powerline-multiline.theme.bash +++ b/themes/powerline-multiline/powerline-multiline.theme.bash @@ -1,15 +1,12 @@ #!/usr/bin/env bash -THEME_PROMPT_SEPARATOR="" -THEME_PROMPT_LEFT_SEPARATOR="" - -USER_INFO_SSH_CHAR=${USER_INFO_SSH_CHAR:=" "} +USER_INFO_SSH_CHAR=${POWERLINE_USER_INFO_SSH_CHAR:=" "} USER_INFO_THEME_PROMPT_COLOR=32 USER_INFO_THEME_PROMPT_COLOR_SUDO=202 -VIRTUALENV_CHAR=${POWERLINE_VIRTUALENV_CHAR:="❲p❳ "} -CONDA_VIRTUALENV_CHAR=${POWERLINE_CONDA_VIRTUALENV_CHAR:="❲c❳ "} -VIRTUALENV_THEME_PROMPT_COLOR=35 +PYTHON_VENV_CHAR=${POWERLINE_PYTHON_VENV_CHAR:="❲p❳ "} +CONDA_PYTHON_VENV_CHAR=${POWERLINE_CONDA_PYTHON_VENV_CHAR:="❲c❳ "} +PYTHON_VENV_THEME_PROMPT_COLOR=35 SCM_NONE_CHAR="" SCM_GIT_CHAR=${POWERLINE_SCM_GIT_CHAR:=" "} @@ -40,13 +37,13 @@ BATTERY_STATUS_THEME_PROMPT_GOOD_COLOR=70 BATTERY_STATUS_THEME_PROMPT_LOW_COLOR=208 BATTERY_STATUS_THEME_PROMPT_CRITICAL_COLOR=160 -THEME_PROMPT_CLOCK_FORMAT=${THEME_PROMPT_CLOCK_FORMAT:="%H:%M:%S"} +THEME_PROMPT_CLOCK_FORMAT=${POWERLINE_PROMPT_CLOCK_FORMAT:="%H:%M:%S"} -IN_VIM_PROMPT_COLOR=245 -IN_VIM_PROMPT_TEXT="vim" +IN_VIM_THEME_PROMPT_COLOR=245 +IN_VIM_THEME_PROMPT_TEXT="vim" -THEME_LEFT_SEGMENTS="scm virtualenv rvm cwd" -THEME_RIGHT_SEGMENTS="in_vim clock battery user_info" +POWERLINE_LEFT_PROMPT="scm python_venv rvm cwd" +POWERLINE_RIGHT_PROMPT="in_vim clock battery user_info" function set_rgb_color { @@ -60,225 +57,192 @@ function set_rgb_color { echo -e "\[\033[${fg}${bg}m\]" } -function powerline_user_info_prompt { - local offset=2 - local USER_INFO="" - local USER_INFO_PROMPT="" - USER_INFO_PROMPT_COLOR=${USER_INFO_THEME_PROMPT_COLOR} +function __powerline_user_info_prompt { + local user_info="" + local color=${USER_INFO_THEME_PROMPT_COLOR} + if sudo -n uptime 2>&1 | grep -q "load"; then - USER_INFO_PROMPT_COLOR=${USER_INFO_THEME_PROMPT_COLOR_SUDO} + COLOR=${USER_INFO_THEME_PROMPT_COLOR_SUDO} fi - case "${THEME_PROMPT_USER_INFO_MODE}" in + case "${POWERLINE_PROMPT_USER_INFO_MODE}" in "sudo") - if [[ "${USER_INFO_PROMPT_COLOR}" == "${USER_INFO_THEME_PROMPT_COLOR_SUDO}" ]]; then - USER_INFO="!" + if [[ "${COLOR}" == "${USER_INFO_THEME_PROMPT_COLOR_SUDO}" ]]; then + user_info="!" fi ;; *) if [[ -n "${SSH_CLIENT}" ]]; then - USER_INFO="${USER_INFO_SSH_CHAR}${USER}@${HOSTNAME}" + user_info="${USER_INFO_SSH_CHAR}${USER}@${HOSTNAME}" else - USER_INFO="${USER}" + user_info="${USER}" fi ;; esac - if [[ -n "${USER_INFO}" ]]; then - if [[ "${SEGMENT_AT_RIGHT}" -eq 0 ]]; then - USER_INFO_PROMPT="$(set_rgb_color ${USER_INFO_PROMPT_COLOR} -)${THEME_PROMPT_LEFT_SEPARATOR}${normal}" - else - USER_INFO_PROMPT="$(set_rgb_color ${USER_INFO_PROMPT_COLOR} ${LAST_THEME_COLOR})${THEME_PROMPT_LEFT_SEPARATOR}${normal}" - (( offset += 1 )) - fi - USER_INFO_PROMPT+="$(set_rgb_color - ${USER_INFO_PROMPT_COLOR}) ${USER_INFO} ${normal}" - RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${#USER_INFO} + ${offset} )) - LAST_THEME_COLOR=${USER_INFO_PROMPT_COLOR} - RIGHT_PROMPT+="${USER_INFO_PROMPT}" - (( SEGMENT_AT_RIGHT += 1 )) - fi + [[ -n "${user_info}" ]] && echo "${user_info}|${COLOR}" } -function powerline_rvm_prompt { - local RVM_PROMPT="" +function __powerline_rvm_prompt { + local RVM="" if command_exists rvm; then - RVM_PROMPT=$(rvm_version_prompt) - if [[ "${RVM_PROMPT}" != $(rvm strings default) ]]; then - RVM_PROMPT="$(set_rgb_color - ${RVM_THEME_PROMPT_COLOR}) ${RVM_CHAR}${RVM_PROMPT} ${normal}" - if [[ "${SEGMENT_AT_LEFT}" -gt 0 ]]; then - RVM_PROMPT=$(set_rgb_color ${LAST_THEME_COLOR} ${RVM_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}${RVM_PROMPT} - fi - LAST_THEME_COLOR=${RVM_THEME_PROMPT_COLOR} - LEFT_PROMPT+="${RVM_PROMPT}" - (( SEGMENT_AT_LEFT += 1 )) - fi + RVM="$(rvm_version_prompt)" + [[ -n "${RVM}" ]] && echo "${RVM}|${RVM_THEME_PROMPT_COLOR}" fi } -function powerline_virtualenv_prompt { - local VIRTUALENV_PROMPT="" +function __powerline_python_venv_prompt { + local python_venv="" - if [[ -n "$CONDA_DEFAULT_ENV" ]]; then - VIRTUALENV_PROMPT="$CONDA_DEFAULT_ENV" - VIRTUALENV_CHAR=${CONDA_VIRTUALENV_CHAR} - elif [[ -n "$VIRTUAL_ENV" ]]; then - VIRTUALENV_PROMPT=$(basename "$VIRTUAL_ENV") + if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then + python_venv="${CONDA_DEFAULT_ENV}" + PYTHONV_VENV_CHAR=${CONDA_PYTHONVENV_CHAR} + elif [[ -n "${VIRTUAL_ENV}" ]]; then + python_venv=$(basename "${VIRTUAL_ENV}") fi - if [[ -n "$VIRTUALENV_PROMPT" ]]; then - VIRTUALENV_PROMPT="$(set_rgb_color - ${VIRTUALENV_THEME_PROMPT_COLOR}) ${VIRTUALENV_CHAR}${VIRTUALENV_PROMPT} ${normal}" - if [[ "${SEGMENT_AT_LEFT}" -gt 0 ]]; then - VIRTUALENV_PROMPT=$(set_rgb_color ${LAST_THEME_COLOR} ${VIRTUALENV_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}${VIRTUALENV_PROMPT} - fi - LAST_THEME_COLOR=${VIRTUALENV_THEME_PROMPT_COLOR} - LEFT_PROMPT+="${VIRTUALENV_PROMPT}" - (( SEGMENT_AT_LEFT += 1 )) - fi + [[ -n "${PYTHON_VENV}" ]] && echo "${python_venv}|${PYTHON_VENV_THEME_PROMPT_COLOR}" } -function powerline_scm_prompt { +function __powerline_scm_prompt { + local color="" local SCM_PROMPT="" scm_prompt_vars + if [[ "${SCM_NONE_CHAR}" != "${SCM_CHAR}" ]]; then if [[ "${SCM_DIRTY}" -eq 3 ]]; then - SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_STAGED_COLOR} + COLOR=${SCM_THEME_PROMPT_STAGED_COLOR} elif [[ "${SCM_DIRTY}" -eq 2 ]]; then - SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_UNSTAGED_COLOR} + COLOR=${SCM_THEME_PROMPT_UNSTAGED_COLOR} elif [[ "${SCM_DIRTY}" -eq 1 ]]; then - SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_DIRTY_COLOR} + COLOR=${SCM_THEME_PROMPT_DIRTY_COLOR} else - SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_CLEAN_COLOR} + COLOR=${SCM_THEME_PROMPT_CLEAN_COLOR} fi if [[ "${SCM_GIT_CHAR}" == "${SCM_CHAR}" ]]; then - SCM_PROMPT+=" ${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}" + SCM_PROMPT+="${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}" fi - SCM_PROMPT="$(set_rgb_color - ${SCM_THEME_PROMPT_COLOR})${SCM_PROMPT} ${normal}" - if [[ "${SEGMENT_AT_LEFT}" -gt 0 ]]; then - SCM_PROMPT=$(set_rgb_color ${LAST_THEME_COLOR} ${SCM_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}${SCM_PROMPT} - fi - LEFT_PROMPT+="${SCM_PROMPT}" - LAST_THEME_COLOR=${SCM_THEME_PROMPT_COLOR} - (( SEGMENT_AT_LEFT += 1 )) + echo "${SCM_PROMPT}|${COLOR}" fi } -function powerline_cwd_prompt { - local CWD_PROMPT="" - CWD_PROMPT="$(set_rgb_color - ${CWD_THEME_PROMPT_COLOR}) \w ${normal}$(set_rgb_color ${CWD_THEME_PROMPT_COLOR} -)${normal}" - if [[ "${SEGMENT_AT_LEFT}" -gt 0 ]]; then - CWD_PROMPT=$(set_rgb_color ${LAST_THEME_COLOR} ${CWD_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}${CWD_PROMPT} - fi - LAST_THEME_COLOR=${CWD_THEME_PROMPT_COLOR} - LEFT_PROMPT+="${CWD_PROMPT}" - (( SEGMENT_AT_LEFT += 1 )) +function __powerline_cwd_prompt { + echo "$(pwd | sed "s|^${HOME}|~|")|${CWD_THEME_PROMPT_COLOR}" } -function powerline_last_status_prompt { +function __powerline_clock_prompt { + echo "$(date +"${THEME_PROMPT_CLOCK_FORMAT}")|${CLOCK_THEME_PROMPT_COLOR}" +} + +function __powerline_battery_prompt { + local color="" + local battery_status="$(battery_percentage 2> /dev/null)" + + if [[ -z "${battery_status}" ]] || [[ "${battery_status}" = "-1" ]] || [[ "${battery_status}" = "no" ]]; then + true + else + if [[ "$((10#${battery_status}))" -le 5 ]]; then + color="${BATTERY_STATUS_THEME_PROMPT_CRITICAL_COLOR}" + elif [[ "$((10#${battery_status}))" -le 25 ]]; then + color="${BATTERY_STATUS_THEME_PROMPT_LOW_COLOR}" + else + color="${BATTERY_STATUS_THEME_PROMPT_GOOD_COLOR}" + fi + [[ "$(ac_adapter_connected)" ]] && battery_status="${BATTERY_AC_CHAR}${battery_status}" + echo "${battery_status}%|${color}" + fi +} + +function __powerline_in_vim_prompt { + if [ -n "$VIMRUNTIME" ]; then + echo "${IN_VIM_THEME_PROMPT_TEXT}|${IN_VIM_THEME_PROMPT_COLOR}" + fi +} + +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}" + LAST_STATUS_PROMPT="$(set_rgb_color ${LAST_STATUS_THEME_PROMPT_COLOR} -) ${1} ${normal}" fi } -function powerline_clock_prompt { - local offset=0 - local CLOCK=" $(date +"${THEME_PROMPT_CLOCK_FORMAT}") " +function __powerline_left_segment { + local OLD_IFS="${IFS}"; IFS="|" + local params=( $1 ) + IFS="${OLD_IFS}" + local separator_char="" + local separator="" - if [[ $? -eq 0 ]]; then - local CLOCK_PROMPT="" - RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${#CLOCK} )) - if [[ "${SEGMENT_AT_RIGHT}" -eq 0 ]]; then - CLOCK_PROMPT=$(set_rgb_color ${CLOCK_THEME_PROMPT_COLOR} -) - else - CLOCK_PROMPT=$(set_rgb_color ${CLOCK_THEME_PROMPT_COLOR} ${LAST_THEME_COLOR}) - (( offset += 1 )) - fi - CLOCK_PROMPT+=${THEME_PROMPT_LEFT_SEPARATOR}${normal}$(set_rgb_color - ${CLOCK_THEME_PROMPT_COLOR})${CLOCK}${normal} - LAST_THEME_COLOR=${CLOCK_THEME_PROMPT_COLOR} - RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${offset} )) - RIGHT_PROMPT+="${CLOCK_PROMPT}" - (( SEGMENT_AT_RIGHT += 1 )) + if [[ "${SEGMENTS_AT_LEFT}" -gt 0 ]]; then + separator="$(set_rgb_color ${LAST_SEGMENT_COLOR} ${params[1]})${separator_char}${normal}${normal}" fi + LEFT_PROMPT+="${separator}$(set_rgb_color - ${params[1]}) ${params[0]} ${normal}" + LAST_SEGMENT_COLOR=${params[1]} + (( SEGMENTS_AT_LEFT += 1 )) } -function powerline_battery_prompt { - local offset=3 - local BATTERY_STATUS="$(battery_percentage 2> /dev/null)" - if [[ -z "${BATTERY_STATUS}" ]] || [[ "${BATTERY_STATUS}" = "-1" ]] || [[ "${BATTERY_STATUS}" = "no" ]]; then - true +function __powerline_right_segment { + local OLD_IFS="${IFS}"; IFS="|" + local params=( $1 ) + IFS="${OLD_IFS}" + local separator_char="" + local padding=2 + local separator_color="" + + if [[ "${SEGMENTS_AT_RIGHT}" -eq 0 ]]; then + separator_color="$(set_rgb_color ${params[1]} -)" else - local BATTERY_PROMPT="" - if [[ "$((10#${BATTERY_STATUS}))" -le 5 ]]; then - BATTERY_STATUS_THEME_PROMPT_COLOR="${BATTERY_STATUS_THEME_PROMPT_CRITICAL_COLOR}" - elif [[ "$((10#${BATTERY_STATUS}))" -le 25 ]]; then - BATTERY_STATUS_THEME_PROMPT_COLOR="${BATTERY_STATUS_THEME_PROMPT_LOW_COLOR}" - else - BATTERY_STATUS_THEME_PROMPT_COLOR="${BATTERY_STATUS_THEME_PROMPT_GOOD_COLOR}" - fi - [[ "$(ac_adapter_connected)" ]] && BATTERY_STATUS="${BATTERY_AC_CHAR}${BATTERY_STATUS}" - if [[ "${SEGMENT_AT_RIGHT}" -eq 0 ]]; then - BATTERY_PROMPT=$(set_rgb_color ${BATTERY_STATUS_THEME_PROMPT_COLOR} -)${THEME_PROMPT_LEFT_SEPARATOR}${normal} - else - BATTERY_PROMPT=$(set_rgb_color ${BATTERY_STATUS_THEME_PROMPT_COLOR} ${LAST_THEME_COLOR})${THEME_PROMPT_LEFT_SEPARATOR}${normal} - (( offset +=1 )) - fi - BATTERY_PROMPT+="$(set_rgb_color - ${BATTERY_STATUS_THEME_PROMPT_COLOR}) ${BATTERY_STATUS}% ${normal}" - RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${#BATTERY_STATUS} + ${offset} )) - LAST_THEME_COLOR=${BATTERY_STATUS_THEME_PROMPT_COLOR} - RIGHT_PROMPT+="${BATTERY_PROMPT}" - (( SEGMENT_AT_RIGHT += 1 )) + separator_color="$(set_rgb_color ${params[1]} ${LAST_SEGMENT_COLOR})" + (( padding += 1 )) fi + RIGHT_PROMPT+="${separator_color}${separator_char}${normal}$(set_rgb_color - ${params[1]}) ${params[0]} ${normal}$(set_rgb_color - ${COLOR})${normal}" + RIGHT_PROMPT_LENGTH=$(( ${#params[0]} + RIGHT_PROMPT_LENGTH + padding )) + LAST_SEGMENT_COLOR="${params[1]}" + (( SEGMENTS_AT_RIGHT += 1 )) } -function powerline_in_vim_prompt { - local offset=2 - local IN_VIM_PROMPT="" - if [ -n "$VIMRUNTIME" ]; then - if [[ "${SEGMENT_AT_RIGHT}" -eq 0 ]]; then - IN_VIM_PROMPT+="$(set_rgb_color ${IN_VIM_PROMPT_COLOR} -)${THEME_PROMPT_LEFT_SEPARATOR}${normal}" - else - IN_VIM_PROMPT+=$(set_rgb_color ${IN_VIM_PROMPT_COLOR} ${LAST_THEME_COLOR})${THEME_PROMPT_LEFT_SEPARATOR}${normal} - (( offset += 1 )) - fi - IN_VIM_PROMPT+="$(set_rgb_color - ${IN_VIM_PROMPT_COLOR}) ${IN_VIM_PROMPT_TEXT} ${normal}" - RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${#IN_VIM_PROMPT_TEXT} + ${offset})) - LAST_THEME_COLOR=${IN_VIM_PROMPT_COLOR} - RIGHT_PROMPT+="${IN_VIM_PROMPT}" - (( SEGMENT_AT_RIGHT += 1 )) - fi -} - - -function powerline_prompt_command() { - local LAST_STATUS="$?" - local MOVE_CURSOR_RIGHTMOST='\033[500C' +function __powerline_prompt_command { + local last_status="$?" ## always the first + local separator_char="" + local move_cursor_rightmost='\033[500C' LEFT_PROMPT="" RIGHT_PROMPT="" - SEGMENT_AT_LEFT=0 - SEGMENT_AT_RIGHT=0 RIGHT_PROMPT_LENGTH=0 - LAST_THEME_COLOR="" + SEGMENTS_AT_LEFT=0 + SEGMENTS_AT_RIGHT=0 + LAST_SEGMENT_COLOR="" ## left prompt ## - for segment in $THEME_LEFT_SEGMENTS; do - "powerline_${segment}_prompt" + for segment in $POWERLINE_LEFT_PROMPT; do + local info="$(__powerline_${segment}_prompt)" + [[ -n "${info}" ]] && __powerline_left_segment "${info}" done - [[ -n "${LEFT_PROMPT}" ]] && LEFT_PROMPT+="$(set_rgb_color ${LAST_THEME_COLOR} -)${THEME_PROMPT_SEPARATOR}${normal}" + [[ -n "${LEFT_PROMPT}" ]] && LEFT_PROMPT+="$(set_rgb_color ${LAST_SEGMENT_COLOR} -)${separator_char}${normal}" ## right prompt ## - if [[ -n "${THEME_RIGHT_SEGMENTS}" ]]; then - LEFT_PROMPT+="${MOVE_CURSOR_RIGHTMOST}" - for segment in $THEME_RIGHT_SEGMENTS; do - "powerline_${segment}_prompt" + if [[ -n "${POWERLINE_RIGHT_PROMPT}" ]]; then + LEFT_PROMPT+="${move_cursor_rightmost}" + for segment in $POWERLINE_RIGHT_PROMPT; do + local info="$(__powerline_${segment}_prompt)" + [[ -n "${info}" ]] && __powerline_right_segment "${info}" done LEFT_PROMPT+="\033[${RIGHT_PROMPT_LENGTH}D" fi - powerline_last_status_prompt LAST_STATUS + __powerline_last_status_prompt "${last_status}" PS1="${LEFT_PROMPT}${RIGHT_PROMPT}\n${LAST_STATUS_PROMPT}${PROMPT_CHAR} " + + ## cleanup ## + unset LAST_STATUS_PROMPT + unset LEFT_PROMPT + unset RIGHT_PROMPT + unset RIGHT_PROMPT_LENGTH + unset SEGMENTS_AT_LEFT + unset SEGMENTS_AT_RIGHT + unset LAST_SEGMENT_COLOR } -PROMPT_COMMAND=powerline_prompt_command +PROMPT_COMMAND=__powerline_prompt_command From 8bee21e428f702a4a91dfd3112f86bb8b2e1724d Mon Sep 17 00:00:00 2001 From: Eduardo Bellido Bellido Date: Wed, 27 Jan 2016 01:27:11 +0100 Subject: [PATCH 07/10] Update powerline-multiline README.md --- themes/powerline-multiline/README.md | 31 +++++++++++++--------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/themes/powerline-multiline/README.md b/themes/powerline-multiline/README.md index d0f6bfb8..80f07317 100644 --- a/themes/powerline-multiline/README.md +++ b/themes/powerline-multiline/README.md @@ -2,6 +2,8 @@ Colorfull multiline theme, the first line shows information about your shell session (divided into two parts, left and right), the second one is where the shell commands are introduced. +**IMPORTANT:** This theme has a requirement, [a font with the Powerline symbols](https://github.com/powerline/fonts) need tu be used in your terminal emulator, otherwise, the prompt won't be displayed correctly. + ## Information provided * Current path @@ -23,7 +25,7 @@ This theme is pretty configurable, all the configuration is done by setting envi By default, the username and hostname are shown at the right side, but you can change this behavior setting the value of the following variable: - THEME_PROMPT_USER_INFO_MODE + POWERLINE_PROMPT_USER_INFO_MODE for now, the only supported value is `sudo`, that hides the username and hostname, and shows an indicator when the sudo has the credentials cached. Any other value has no effect. @@ -31,33 +33,28 @@ for now, the only supported value is `sudo`, that hides the username and hostnam By default, the current time is shown at the right side, you can change the format with the variable: - THEME_PROMPT_CLOCK_FORMAT="%H:%M:%S" + POWERLINE_PROMPT_CLOCK_FORMAT="%H:%M:%S" the date is printed by the `date` command, so refer to its man page to change the format. ### Segment order -Both prompt sides can be "reordered", all the "segments" (every piece of information) can take any place, the only restriction (for now), is that some segments only can be placed at left, and others only at right. +Both prompt sides can be "reordered", all the "segments" (every piece of information) can take any place, the current available segments are: -Current available left "segments": - -* scm -* virtualenv -* rvm -* cwd - -Current available right "segments": - -* in_vim -* clock * battery +* clock +* cwd +* in_vim +* python_venv +* rvm +* scm * user_info Two variables can be defined to set the order of the prompt segments: - THEME_LEFT_SEGMENTS="scm virtualenv rvm cwd" - THEME_RIGHT_SEGMENTS="in_vim clock battery user_info" + POWERLINE_LEFT_PROMPT="scm python_venv rvm cwd" + POWERLINE_RIGHT_PROMPT="in_vim clock battery user_info" -if you want to remove something else from the prompt, simply remove the "string" that represents the segment from the corresponding variable. +the example values are the defaults, but if you want to remove something else from the prompt, simply remove the "string" that represents the segment from the corresponding variable. From ead5047fb964be4ca237bddf7f73bfde815af9fa Mon Sep 17 00:00:00 2001 From: Eduardo Bellido Bellido Date: Sat, 30 Jan 2016 11:33:00 +0100 Subject: [PATCH 08/10] Reduce unset calls --- .../powerline-multiline/powerline-multiline.theme.bash | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/themes/powerline-multiline/powerline-multiline.theme.bash b/themes/powerline-multiline/powerline-multiline.theme.bash index edd7b82d..6915aaf2 100644 --- a/themes/powerline-multiline/powerline-multiline.theme.bash +++ b/themes/powerline-multiline/powerline-multiline.theme.bash @@ -236,13 +236,9 @@ function __powerline_prompt_command { PS1="${LEFT_PROMPT}${RIGHT_PROMPT}\n${LAST_STATUS_PROMPT}${PROMPT_CHAR} " ## cleanup ## - unset LAST_STATUS_PROMPT - unset LEFT_PROMPT - unset RIGHT_PROMPT - unset RIGHT_PROMPT_LENGTH - unset SEGMENTS_AT_LEFT - unset SEGMENTS_AT_RIGHT - unset LAST_SEGMENT_COLOR + unset LAST_STATUS_PROMPT LAST_SEGMENT_COLOR \ + LEFT_PROMPT RIGHT_PROMPT RIGHT_PROMPT_LENGTH \ + SEGMENTS_AT_LEFT SEGMENTS_AT_RIGHT } PROMPT_COMMAND=__powerline_prompt_command From f6436a878e037f33580acbedd6644c3bb8f7a658 Mon Sep 17 00:00:00 2001 From: Eduardo Bellido Bellido Date: Sat, 30 Jan 2016 12:18:07 +0100 Subject: [PATCH 09/10] Fix some regressions and variables names --- .../powerline-multiline.theme.bash | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/themes/powerline-multiline/powerline-multiline.theme.bash b/themes/powerline-multiline/powerline-multiline.theme.bash index 6915aaf2..210e309c 100644 --- a/themes/powerline-multiline/powerline-multiline.theme.bash +++ b/themes/powerline-multiline/powerline-multiline.theme.bash @@ -62,11 +62,11 @@ function __powerline_user_info_prompt { local color=${USER_INFO_THEME_PROMPT_COLOR} if sudo -n uptime 2>&1 | grep -q "load"; then - COLOR=${USER_INFO_THEME_PROMPT_COLOR_SUDO} + color=${USER_INFO_THEME_PROMPT_COLOR_SUDO} fi case "${POWERLINE_PROMPT_USER_INFO_MODE}" in "sudo") - if [[ "${COLOR}" == "${USER_INFO_THEME_PROMPT_COLOR_SUDO}" ]]; then + if [[ "${color}" == "${USER_INFO_THEME_PROMPT_COLOR_SUDO}" ]]; then user_info="!" fi ;; @@ -78,15 +78,15 @@ function __powerline_user_info_prompt { fi ;; esac - [[ -n "${user_info}" ]] && echo "${user_info}|${COLOR}" + [[ -n "${user_info}" ]] && echo "${user_info}|${color}" } function __powerline_rvm_prompt { - local RVM="" + local rvm="" if command_exists rvm; then - RVM="$(rvm_version_prompt)" - [[ -n "${RVM}" ]] && echo "${RVM}|${RVM_THEME_PROMPT_COLOR}" + rvm="$(rvm_version_prompt)" + [[ -n "${rvm}" ]] && echo "${RVM_CHAR}${rvm}|${RVM_THEME_PROMPT_COLOR}" fi } @@ -95,34 +95,34 @@ function __powerline_python_venv_prompt { if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then python_venv="${CONDA_DEFAULT_ENV}" - PYTHONV_VENV_CHAR=${CONDA_PYTHONVENV_CHAR} + PYTHON_VENV_CHAR=${CONDA_PYTHON_VENV_CHAR} elif [[ -n "${VIRTUAL_ENV}" ]]; then python_venv=$(basename "${VIRTUAL_ENV}") fi - [[ -n "${PYTHON_VENV}" ]] && echo "${python_venv}|${PYTHON_VENV_THEME_PROMPT_COLOR}" + [[ -n "${python_venv}" ]] && echo "${PYTHON_VENV_CHAR}${python_venv}|${PYTHON_VENV_THEME_PROMPT_COLOR}" } function __powerline_scm_prompt { local color="" - local SCM_PROMPT="" + local scm_prompt="" scm_prompt_vars if [[ "${SCM_NONE_CHAR}" != "${SCM_CHAR}" ]]; then if [[ "${SCM_DIRTY}" -eq 3 ]]; then - COLOR=${SCM_THEME_PROMPT_STAGED_COLOR} + color=${SCM_THEME_PROMPT_STAGED_COLOR} elif [[ "${SCM_DIRTY}" -eq 2 ]]; then - COLOR=${SCM_THEME_PROMPT_UNSTAGED_COLOR} + color=${SCM_THEME_PROMPT_UNSTAGED_COLOR} elif [[ "${SCM_DIRTY}" -eq 1 ]]; then - COLOR=${SCM_THEME_PROMPT_DIRTY_COLOR} + color=${SCM_THEME_PROMPT_DIRTY_COLOR} else - COLOR=${SCM_THEME_PROMPT_CLEAN_COLOR} + color=${SCM_THEME_PROMPT_CLEAN_COLOR} fi if [[ "${SCM_GIT_CHAR}" == "${SCM_CHAR}" ]]; then - SCM_PROMPT+="${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}" + scm_prompt+="${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}" fi - echo "${SCM_PROMPT}|${COLOR}" + echo "${scm_prompt}|${color}" fi } From 30c6fd1f59b3d4093babe46d446e9f03c55c70c1 Mon Sep 17 00:00:00 2001 From: Eduardo Bellido Bellido Date: Sat, 30 Jan 2016 12:19:34 +0100 Subject: [PATCH 10/10] Refactor __powerline_last_status_prompt function --- .../powerline-multiline.theme.bash | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/themes/powerline-multiline/powerline-multiline.theme.bash b/themes/powerline-multiline/powerline-multiline.theme.bash index 210e309c..beaf3048 100644 --- a/themes/powerline-multiline/powerline-multiline.theme.bash +++ b/themes/powerline-multiline/powerline-multiline.theme.bash @@ -160,11 +160,7 @@ function __powerline_in_vim_prompt { } 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} -) ${1} ${normal}" - fi + [[ "$1" -ne 0 ]] && echo "$(set_rgb_color ${LAST_STATUS_THEME_PROMPT_COLOR} -) ${1} ${normal}" } function __powerline_left_segment { @@ -231,12 +227,10 @@ function __powerline_prompt_command { LEFT_PROMPT+="\033[${RIGHT_PROMPT_LENGTH}D" fi - __powerline_last_status_prompt "${last_status}" - - PS1="${LEFT_PROMPT}${RIGHT_PROMPT}\n${LAST_STATUS_PROMPT}${PROMPT_CHAR} " + PS1="${LEFT_PROMPT}${RIGHT_PROMPT}\n$(__powerline_last_status_prompt ${last_status})${PROMPT_CHAR} " ## cleanup ## - unset LAST_STATUS_PROMPT LAST_SEGMENT_COLOR \ + unset LAST_SEGMENT_COLOR \ LEFT_PROMPT RIGHT_PROMPT RIGHT_PROMPT_LENGTH \ SEGMENTS_AT_LEFT SEGMENTS_AT_RIGHT }