Merge pull request #406 from edubxb/powerline-multiline
Improved Powerline-multiline themepull/414/head
commit
722ef0cd76
|
|
@ -1,6 +1,18 @@
|
||||||
cite about-plugin
|
cite about-plugin
|
||||||
about-plugin 'display info about your battery charge level'
|
about-plugin 'display info about your battery charge level'
|
||||||
|
|
||||||
|
ac_adapter_connected(){
|
||||||
|
if command_exists acpi;
|
||||||
|
then
|
||||||
|
acpi -a | grep "on-line"
|
||||||
|
if [[ "$?" -eq 0 ]]; then
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
battery_percentage(){
|
battery_percentage(){
|
||||||
about 'displays battery charge as a percentage of full (100%)'
|
about 'displays battery charge as a percentage of full (100%)'
|
||||||
group 'battery'
|
group 'battery'
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
THEME_PROMPT_SEPARATOR=""
|
THEME_PROMPT_SEPARATOR=""
|
||||||
|
THEME_PROMPT_LEFT_SEPARATOR=""
|
||||||
|
|
||||||
SHELL_SSH_CHAR=" "
|
SHELL_SSH_CHAR=" "
|
||||||
SHELL_THEME_PROMPT_COLOR=32
|
SHELL_THEME_PROMPT_COLOR=32
|
||||||
SHELL_SSH_THEME_PROMPT_COLOR=208
|
SHELL_SSH_THEME_PROMPT_COLOR=208
|
||||||
|
|
||||||
VIRTUALENV_CHAR="ⓔ "
|
VIRTUALENV_CHAR="⒫ "
|
||||||
VIRTUALENV_THEME_PROMPT_COLOR=35
|
VIRTUALENV_THEME_PROMPT_COLOR=35
|
||||||
|
|
||||||
SCM_NONE_CHAR=""
|
SCM_NONE_CHAR=""
|
||||||
|
|
@ -16,19 +17,24 @@ PROMPT_CHAR="❯"
|
||||||
SCM_THEME_PROMPT_CLEAN=""
|
SCM_THEME_PROMPT_CLEAN=""
|
||||||
SCM_THEME_PROMPT_DIRTY=""
|
SCM_THEME_PROMPT_DIRTY=""
|
||||||
|
|
||||||
SCM_THEME_PROMPT_COLOR=238
|
SCM_THEME_PROMPT_CLEAN_COLOR=25
|
||||||
SCM_THEME_PROMPT_CLEAN_COLOR=231
|
SCM_THEME_PROMPT_DIRTY_COLOR=88
|
||||||
SCM_THEME_PROMPT_DIRTY_COLOR=196
|
SCM_THEME_PROMPT_STAGED_COLOR=30
|
||||||
SCM_THEME_PROMPT_STAGED_COLOR=220
|
SCM_THEME_PROMPT_UNSTAGED_COLOR=92
|
||||||
SCM_THEME_PROMPT_UNSTAGED_COLOR=166
|
SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_CLEAN_COLOR}
|
||||||
|
|
||||||
CWD_THEME_PROMPT_COLOR=240
|
CWD_THEME_PROMPT_COLOR=240
|
||||||
|
|
||||||
LAST_STATUS_THEME_PROMPT_COLOR=52
|
LAST_STATUS_THEME_PROMPT_COLOR=196
|
||||||
|
|
||||||
PROMPT_LENGTH=0
|
CLOCK_THEME_PROMPT_COLOR=240
|
||||||
|
|
||||||
THEME_PROMPT_CLOCK_FORMAT=${THEME_PROMPT_CLOCK_FORMAT:=" %a %H:%M:%S "}
|
BATTERY_AC_CHAR="⚡"
|
||||||
|
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"}
|
||||||
|
|
||||||
function set_rgb_color {
|
function set_rgb_color {
|
||||||
if [[ "${1}" != "-" ]]; then
|
if [[ "${1}" != "-" ]]; then
|
||||||
|
|
@ -42,30 +48,36 @@ function set_rgb_color {
|
||||||
}
|
}
|
||||||
|
|
||||||
function powerline_shell_prompt {
|
function powerline_shell_prompt {
|
||||||
|
SEGMENT_AT_RIGHT=0
|
||||||
if [[ -n "${SSH_CLIENT}" ]]; then
|
if [[ -n "${SSH_CLIENT}" ]]; then
|
||||||
SHELL_PROMPT="${bold_white}$(set_rgb_color - ${SHELL_SSH_THEME_PROMPT_COLOR}) ${SHELL_SSH_CHAR}\u@\h ${normal}"
|
SHELL_PROMPT="${USER}@${HOSTNAME}"
|
||||||
LAST_THEME_COLOR=${SHELL_SSH_THEME_PROMPT_COLOR}
|
SHELL_THEME_PROMPT_COLOR="${SHELL_SSH_THEME_PROMPT_COLOR}"
|
||||||
PROMPT_LENGTH=$(($PROMPT_LENGTH + ${#USER} + 1 + ${#HOST} + 2))
|
|
||||||
else
|
else
|
||||||
SHELL_PROMPT="${bold_white}$(set_rgb_color - ${SHELL_THEME_PROMPT_COLOR}) \u ${normal}"
|
SHELL_PROMPT="${USER}"
|
||||||
LAST_THEME_COLOR=${SHELL_THEME_PROMPT_COLOR}
|
|
||||||
PROMPT_LENGTH=$(($PROMPT_LENGTH + ${#USER} + 2))
|
|
||||||
fi
|
fi
|
||||||
|
RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${#SHELL_PROMPT} + 2 ))
|
||||||
|
SHELL_PROMPT="$(set_rgb_color - ${SHELL_THEME_PROMPT_COLOR}) ${SHELL_PROMPT} ${normal}"
|
||||||
|
LAST_THEME_COLOR=${SHELL_THEME_PROMPT_COLOR}
|
||||||
|
(( SEGMENT_AT_RIGHT += 1 ))
|
||||||
}
|
}
|
||||||
|
|
||||||
function powerline_virtualenv_prompt {
|
function powerline_virtualenv_prompt {
|
||||||
local environ=""
|
local environ=""
|
||||||
|
|
||||||
if [[ -n "$CONDA_DEFAULT_ENV" ]]; then
|
if [[ -n "$CONDA_DEFAULT_ENV" ]]; then
|
||||||
environ="conda: $CONDA_DEFAULT_ENV"
|
environ="$CONDA_DEFAULT_ENV"
|
||||||
|
VIRTUALENV_CHAR="⒞"
|
||||||
elif [[ -n "$VIRTUAL_ENV" ]]; then
|
elif [[ -n "$VIRTUAL_ENV" ]]; then
|
||||||
environ=$(basename "$VIRTUAL_ENV")
|
environ=$(basename "$VIRTUAL_ENV")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n "$environ" ]]; then
|
if [[ -n "$environ" ]]; then
|
||||||
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}"
|
VIRTUALENV_PROMPT="$(set_rgb_color - ${VIRTUALENV_THEME_PROMPT_COLOR}) ${VIRTUALENV_CHAR}$environ ${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}
|
LAST_THEME_COLOR=${VIRTUALENV_THEME_PROMPT_COLOR}
|
||||||
PROMPT_LENGTH=$(($PROMPT_LENGTH + 2 + 2 + ${#environ} + 1))
|
(( SEGMENT_AT_LEFT += 1 ))
|
||||||
else
|
else
|
||||||
VIRTUALENV_PROMPT=""
|
VIRTUALENV_PROMPT=""
|
||||||
fi
|
fi
|
||||||
|
|
@ -73,55 +85,110 @@ function powerline_virtualenv_prompt {
|
||||||
|
|
||||||
function powerline_scm_prompt {
|
function powerline_scm_prompt {
|
||||||
scm_prompt_vars
|
scm_prompt_vars
|
||||||
|
|
||||||
if [[ "${SCM_NONE_CHAR}" != "${SCM_CHAR}" ]]; then
|
if [[ "${SCM_NONE_CHAR}" != "${SCM_CHAR}" ]]; then
|
||||||
if [[ "${SCM_DIRTY}" -eq 3 ]]; then
|
if [[ "${SCM_DIRTY}" -eq 3 ]]; then
|
||||||
SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_STAGED_COLOR} ${SCM_THEME_PROMPT_COLOR})"
|
SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_STAGED_COLOR}
|
||||||
elif [[ "${SCM_DIRTY}" -eq 2 ]]; then
|
elif [[ "${SCM_DIRTY}" -eq 2 ]]; then
|
||||||
SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_UNSTAGED_COLOR} ${SCM_THEME_PROMPT_COLOR})"
|
SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_UNSTAGED_COLOR}
|
||||||
elif [[ "${SCM_DIRTY}" -eq 1 ]]; then
|
elif [[ "${SCM_DIRTY}" -eq 1 ]]; then
|
||||||
SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_DIRTY_COLOR} ${SCM_THEME_PROMPT_COLOR})"
|
SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_DIRTY_COLOR}
|
||||||
else
|
else
|
||||||
SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_CLEAN_COLOR} ${SCM_THEME_PROMPT_COLOR})"
|
SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_CLEAN_COLOR}
|
||||||
fi
|
fi
|
||||||
if [[ "${SCM_GIT_CHAR}" == "${SCM_CHAR}" ]]; then
|
if [[ "${SCM_GIT_CHAR}" == "${SCM_CHAR}" ]]; then
|
||||||
SCM_PROMPT+=" ${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}"
|
SCM_PROMPT=" ${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}"
|
||||||
fi
|
fi
|
||||||
SCM_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} ${SCM_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}${SCM_PROMPT} ${normal}"
|
SCM_PROMPT="$(set_rgb_color - ${SCM_THEME_PROMPT_COLOR})${SCM_PROMPT} ${normal}"
|
||||||
LAST_THEME_COLOR=${SCM_THEME_PROMPT_COLOR}
|
LAST_THEME_COLOR=${SCM_THEME_PROMPT_COLOR}
|
||||||
PROMPT_LENGTH=$(($PROMPT_LENGTH + 5 + ${#SCM_BRANCH} + ${#SCM_STATE}))
|
(( SEGMENT_AT_LEFT += 1 ))
|
||||||
else
|
else
|
||||||
SCM_PROMPT=""
|
SCM_PROMPT=""
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function powerline_cwd_prompt {
|
function powerline_cwd_prompt {
|
||||||
CWD_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} ${CWD_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}$(set_rgb_color - ${CWD_THEME_PROMPT_COLOR}) \w ${normal}$(set_rgb_color ${CWD_THEME_PROMPT_COLOR} -)${normal}"
|
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}"
|
||||||
|
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}
|
LAST_THEME_COLOR=${CWD_THEME_PROMPT_COLOR}
|
||||||
mypwd="${PWD/#$HOME/~/}"
|
|
||||||
PROMPT_LENGTH=$(($PROMPT_LENGTH + ${#mypwd} + 2))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function powerline_last_status_prompt {
|
function powerline_last_status_prompt {
|
||||||
if [[ "$1" -eq 0 ]]; then
|
if [[ "$1" -eq 0 ]]; then
|
||||||
LAST_STATUS_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} -)${THEME_PROMPT_SEPARATOR}${normal}"
|
LAST_STATUS_PROMPT=""
|
||||||
else
|
else
|
||||||
LAST_STATUS_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} ${LAST_STATUS_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}$(set_rgb_color - ${LAST_STATUS_THEME_PROMPT_COLOR}) ${LAST_STATUS} ${normal}$(set_rgb_color ${LAST_STATUS_THEME_PROMPT_COLOR} -)${THEME_PROMPT_SEPARATOR}${normal}"
|
LAST_STATUS_PROMPT="$(set_rgb_color ${LAST_STATUS_THEME_PROMPT_COLOR} -) ${LAST_STATUS} ${normal}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${#CLOCK} ))
|
||||||
|
LAST_THEME_COLOR=${CLOCK_THEME_PROMPT_COLOR}
|
||||||
|
(( SEGMENT_AT_RIGHT += 1 ))
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function powerline_battery_status_prompt {
|
||||||
|
BATTERY_STATUS="$(battery_percentage 2> /dev/null)"
|
||||||
|
if [[ -z "${BATTERY_STATUS}" ]] || [[ "${BATTERY_STATUS}" = "-1" ]] || [[ "${BATTERY_STATUS}" = "no" ]]; then
|
||||||
|
BATTERY_PROMPT=""
|
||||||
|
else
|
||||||
|
if [[ "${BATTERY_STATUS}" -le 5 ]]; then
|
||||||
|
BATTERY_STATUS_THEME_PROMPT_COLOR="${BATTERY_STATUS_THEME_PROMPT_CRITICAL_COLOR}"
|
||||||
|
elif [[ "${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 ))
|
||||||
|
fi
|
||||||
|
RIGHT_PROMPT_LENGTH=$(( ${RIGHT_PROMPT_LENGTH} + ${#BATTERY_STATUS} + 2 ))
|
||||||
|
LAST_THEME_COLOR=${BATTERY_STATUS_THEME_PROMPT_COLOR}
|
||||||
|
(( SEGMENT_AT_RIGHT += 1 ))
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function powerline_prompt_command() {
|
function powerline_prompt_command() {
|
||||||
local LAST_STATUS="$?"
|
local LAST_STATUS="$?"
|
||||||
PROMPT_LENGTH=0
|
local MOVE_CURSOR_RIGHTMOST='\033[500C'
|
||||||
|
RIGHT_PROMPT_LENGTH=1
|
||||||
|
|
||||||
powerline_shell_prompt
|
## left prompt ##
|
||||||
powerline_virtualenv_prompt
|
|
||||||
powerline_scm_prompt
|
powerline_scm_prompt
|
||||||
|
powerline_virtualenv_prompt
|
||||||
powerline_cwd_prompt
|
powerline_cwd_prompt
|
||||||
powerline_last_status_prompt LAST_STATUS
|
powerline_last_status_prompt LAST_STATUS
|
||||||
|
|
||||||
FIRST_LINE="${SHELL_PROMPT}${VIRTUALENV_PROMPT}${SCM_PROMPT}${CWD_PROMPT}${LAST_STATUS_PROMPT}"
|
LEFT_PROMPT="${SCM_PROMPT}${VIRTUALENV_PROMPT}${CWD_PROMPT}${MOVE_CURSOR_RIGHTMOST}"
|
||||||
PS1="${FIRST_LINE}\n${PROMPT_CHAR} "
|
|
||||||
|
## right prompt ##
|
||||||
|
LAST_THEME_COLOR="-"
|
||||||
|
powerline_shell_prompt
|
||||||
|
powerline_battery_status_prompt
|
||||||
|
powerline_clock_prompt
|
||||||
|
|
||||||
|
[[ "${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+="${CLOCK_PROMPT}${BATTERY_PROMPT}${SHELL_PROMPT}${normal}"
|
||||||
|
|
||||||
|
PS1="${LEFT_PROMPT}${RIGHT_PROMPT}\n${LAST_STATUS_PROMPT}${PROMPT_CHAR} "
|
||||||
}
|
}
|
||||||
|
|
||||||
PROMPT_COMMAND=powerline_prompt_command
|
PROMPT_COMMAND=powerline_prompt_command
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue