style(themes/powerline-*): adjust styles

This commit is contained in:
Koichi Murase 2024-09-10 11:05:42 +09:00
parent 2428b27143
commit 275b606aa9
4 changed files with 58 additions and 66 deletions

View File

@ -9,41 +9,41 @@ source "$OSH/themes/powerline/powerline.base.sh"
function __powerline_user_info_prompt {
local user_info=""
local color=${USER_INFO_THEME_PROMPT_COLOR}
local secondary_color="${USER_INFO_THEME_PROMPT_SECONDARY_COLOR}"
local color=$USER_INFO_THEME_PROMPT_COLOR
local secondary_color=$USER_INFO_THEME_PROMPT_SECONDARY_COLOR
if [[ "${THEME_CHECK_SUDO}" = true ]]; then
if [[ $THEME_CHECK_SUDO == true ]]; then
# check whether sudo is active for no-password executions
if sudo -n cat <<< c3bcc5c 2>&1 | grep -q c3bcc5c; then
color=${USER_INFO_THEME_PROMPT_COLOR_SUDO}
fi
fi
case "${POWERLINE_PROMPT_USER_INFO_MODE}" in
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
;;
*)
if [[ -n "${SSH_CLIENT}" ]]; then
user_info="${USER_INFO_SSH_CHAR}${USER}@${HOSTNAME}"
if [[ $SSH_CLIENT ]]; then
user_info=$USER_INFO_SSH_CHAR$USER@$HOSTNAME
else
user_info="${USER}"
user_info=$USER
fi
;;
esac
if [[ -n "${user_info}" ]]; then
if [[ $user_info ]]; then
local clock=$(date +"${OMB_THEME_POWERLINE_ICON_CLOCK-%X %D}")
_omb_util_print "$OMB_THEME_POWERLINE_ICON_USER ${user_info}${clock:+ $clock}|${color}|${secondary_color}"
_omb_util_print "$OMB_THEME_POWERLINE_ICON_USER $user_info${clock:+ $clock}|$color|$secondary_color"
fi
}
function __powerline_cwd_prompt {
_omb_util_print "$(pwd | sed "s|^${HOME}|$OMB_THEME_POWERLINE_ICON_HOME|")|${CWD_THEME_PROMPT_COLOR}"
_omb_util_print "$(pwd | sed "s|^$HOME|$OMB_THEME_POWERLINE_ICON_HOME|")|$CWD_THEME_PROMPT_COLOR"
}
function __powerline_last_status_prompt {
if [[ "$1" -ne 0 ]]; then
if (($1 != 0)); then
_omb_util_print "$OMB_THEME_POWERLINE_ICON_EXIT_FAILURE${1}|${LAST_STATUS_THEME_PROMPT_COLOR}"
else
_omb_util_print "$OMB_THEME_POWERLINE_ICON_EXIT_SUCCESS|${LAST_STATUS_THEME_PROMPT_COLOR_SUCCESS}"

View File

@ -3,63 +3,58 @@
source "$OSH/themes/powerline/powerline.base.sh"
function __powerline_last_status_prompt {
[[ "$1" -ne 0 ]] && _omb_util_print "$(set_color ${LAST_STATUS_THEME_PROMPT_COLOR} -) ${1} ${_omb_prompt_normal}"
(($1 != 0)) && _omb_util_print "$(set_color $LAST_STATUS_THEME_PROMPT_COLOR -) $1 $_omb_prompt_normal"
}
function __powerline_right_segment {
local OLD_IFS="${IFS}"; IFS="|"
local OLD_IFS=$IFS; IFS='|'
local params=( $1 )
IFS="${OLD_IFS}"
local separator_char="${POWERLINE_RIGHT_SEPARATOR}"
IFS=$OLD_IFS
local separator_char=$POWERLINE_RIGHT_SEPARATOR
local padding=2
local separator_color=""
local text_color=${params[2]:-"-"}
local text_color=${params[2]:-'-'}
if [[ "${SEGMENTS_AT_RIGHT}" -eq 0 ]]; then
separator_color="$(set_color ${params[1]} -)"
if ((SEGMENTS_AT_RIGHT == 0)); then
separator_color=$(set_color ${params[1]} -)
else
separator_color="$(set_color ${params[1]} ${LAST_SEGMENT_COLOR})"
(( padding += 1 ))
separator_color=$(set_color ${params[1]} $LAST_SEGMENT_COLOR)
((padding += 1))
fi
RIGHT_PROMPT+="${separator_color}${separator_char}${_omb_prompt_normal}$(set_color ${text_color} ${params[1]}) ${params[0]} ${_omb_prompt_normal}$(set_color - ${COLOR})${_omb_prompt_normal}"
RIGHT_PROMPT_LENGTH=$(( ${#params[0]} + RIGHT_PROMPT_LENGTH + padding ))
LAST_SEGMENT_COLOR="${params[1]}"
(( SEGMENTS_AT_RIGHT += 1 ))
RIGHT_PROMPT+="$separator_color$separator_char$_omb_prompt_normal$(set_color $text_color ${params[1]}) ${params[0]} $_omb_prompt_normal$(set_color - $COLOR)$_omb_prompt_normal"
RIGHT_PROMPT_LENGTH=$((${#params[0]} + RIGHT_PROMPT_LENGTH + padding))
LAST_SEGMENT_COLOR=${params[1]}
((SEGMENTS_AT_RIGHT += 1))
}
function __powerline_prompt_command {
local last_status="$?" ## always the first
local separator_char="${POWERLINE_LEFT_SEPARATOR}"
local last_status=$? ## always the first
local separator_char=$POWERLINE_LEFT_SEPARATOR
local move_cursor_rightmost='\033[500C'
LEFT_PROMPT=""
RIGHT_PROMPT=""
RIGHT_PROMPT_LENGTH=0
SEGMENTS_AT_LEFT=0
SEGMENTS_AT_RIGHT=0
LAST_SEGMENT_COLOR=""
local LEFT_PROMPT=""
local RIGHT_PROMPT=""
local RIGHT_PROMPT_LENGTH=0
local SEGMENTS_AT_LEFT=0
local SEGMENTS_AT_RIGHT=0
local LAST_SEGMENT_COLOR=""
## left prompt ##
for segment in $POWERLINE_LEFT_PROMPT; do
local info="$(__powerline_${segment}_prompt)"
[[ -n "${info}" ]] && __powerline_left_segment "${info}"
local info=$(__powerline_"$segment"_prompt)
[[ $info ]] && __powerline_left_segment "$info"
done
[[ -n "${LEFT_PROMPT}" ]] && LEFT_PROMPT+="$(set_color ${LAST_SEGMENT_COLOR} -)${separator_char}${_omb_prompt_normal}"
[[ $LEFT_PROMPT ]] && LEFT_PROMPT+=$(set_color ${LAST_SEGMENT_COLOR} -)${separator_char}${_omb_prompt_normal}
## right prompt ##
if [[ -n "${POWERLINE_RIGHT_PROMPT}" ]]; then
LEFT_PROMPT+="${move_cursor_rightmost}"
if [[ $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}"
local info=$(__powerline_"$segment"_prompt)
[[ $info ]] && __powerline_right_segment "$info"
done
LEFT_PROMPT+="\033[${RIGHT_PROMPT_LENGTH}D"
fi
PS1="${LEFT_PROMPT}${RIGHT_PROMPT}\n$(__powerline_last_status_prompt ${last_status})${PROMPT_CHAR} "
## cleanup ##
unset LAST_SEGMENT_COLOR \
LEFT_PROMPT RIGHT_PROMPT RIGHT_PROMPT_LENGTH \
SEGMENTS_AT_LEFT SEGMENTS_AT_RIGHT
PS1="$LEFT_PROMPT$RIGHT_PROMPT\n$(__powerline_last_status_prompt $last_status)$PROMPT_CHAR "
}

View File

@ -3,16 +3,16 @@
source "$OSH/themes/powerline/powerline.base.sh"
function __powerline_left_segment {
local OLD_IFS="${IFS}"; IFS="|"
local OLD_IFS=$IFS; IFS='|'
local params=( $1 )
IFS="${OLD_IFS}"
IFS=$OLD_IFS
local separator_char=""
local separator=""
local background_color=${params[2]:-"-"}
local background_color=${params[2]:-'-'}
if [[ "${SEGMENTS_AT_LEFT}" -gt 0 ]]; then
separator="${separator_char}"
if ((SEGMENTS_AT_LEFT > 0)); then
separator=$separator_char
fi
LEFT_PROMPT+="${separator}$(set_color ${params[1]} ${background_color}) ${params[0]} ${_omb_prompt_normal}"
(( SEGMENTS_AT_LEFT += 1 ))
((SEGMENTS_AT_LEFT += 1))
}

View File

@ -3,30 +3,27 @@
source "$OSH/themes/powerline/powerline.base.sh"
function __powerline_left_segment {
local OLD_IFS="${IFS}"; IFS="|"
local OLD_IFS=$IFS; IFS='|'
local params=( $1 )
IFS="${OLD_IFS}"
local text_color=${params[2]:-"-"}
IFS=$OLD_IFS
local text_color=${params[2]:-'-'}
LEFT_PROMPT+="${separator}$(set_color ${text_color} ${params[1]}) ${params[0]} ${_omb_prompt_normal}"
LEFT_PROMPT+="$separator$(set_color $text_color ${params[1]}) ${params[0]} $_omb_prompt_normal"
LAST_SEGMENT_COLOR=${params[1]}
}
function __powerline_prompt_command {
local last_status="$?" ## always the first
local last_status=$? ## always the first
LEFT_PROMPT=""
local LEFT_PROMPT=""
## left prompt ##
for segment in $POWERLINE_PROMPT; do
local info="$(__powerline_${segment}_prompt)"
[[ -n "${info}" ]] && __powerline_left_segment "${info}"
local info=$(__powerline_"$segment"_prompt)
[[ $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} -) ${_omb_prompt_normal}"
((last_status != 0)) && __powerline_left_segment $(__powerline_last_status_prompt $last_status)
[[ $LEFT_PROMPT ]] && LEFT_PROMPT+="$(set_color $LAST_SEGMENT_COLOR -) $_omb_prompt_normal"
PS1="${LEFT_PROMPT} "
## cleanup ##
unset LEFT_PROMPT
PS1="$LEFT_PROMPT "
}