lib/battery: rename `plugin/battery`

This plugin *only* provides utility functions, so it has zero cost to just being enabled. This allows us to eliminate assumptions from `lib/theme` and several themes.
pull/1950/head
John D Pell 2022-03-04 12:37:15 -08:00
parent 4cb7453e90
commit 7a9420ec9b
5 changed files with 8 additions and 30 deletions

View File

@ -555,21 +555,15 @@ function prompt_char() {
} }
function battery_char() { function battery_char() {
# The battery_char function depends on the presence of the battery_percentage function. local battery_percentage
if [[ "${THEME_BATTERY_PERCENTAGE_CHECK}" == true ]] && _command_exists battery_percentage; then battery_percentage="$(battery_percentage)"
echo -ne "${bold_red?}$(battery_percentage)%" if [[ "${THEME_BATTERY_PERCENTAGE_CHECK}" == true ]]; then
echo -e "${bold_red?}${battery_percentage}%"
else else
false false
fi fi
} }
if ! _command_exists battery_charge; then
# if user has installed battery plugin, skip this...
function battery_charge() {
: # no op
}
fi
function aws_profile() { function aws_profile() {
if [[ -n "${AWS_DEFAULT_PROFILE:-}" ]]; then if [[ -n "${AWS_DEFAULT_PROFILE:-}" ]]; then
echo -ne "${AWS_DEFAULT_PROFILE}" echo -ne "${AWS_DEFAULT_PROFILE}"

View File

@ -82,14 +82,6 @@ ${D_BRANCH_COLOR}%b %r ${D_CHANGES_COLOR}%m%u ${D_DEFAULT_COLOR}"
fi fi
} }
# checks if the plugin is installed before calling battery_charge
safe_battery_charge() {
if _command_exists battery_charge ;
then
battery_charge
fi
}
# -------------------------------------------------------------- PROMPT OUTPUT # -------------------------------------------------------------- PROMPT OUTPUT
prompt() { prompt() {
local LAST_COMMAND_FAILED=$(mitsuhikos_lastcommandfailed) local LAST_COMMAND_FAILED=$(mitsuhikos_lastcommandfailed)
@ -101,7 +93,7 @@ prompt() {
if [[ "$OSTYPE" = 'linux'* ]] if [[ "$OSTYPE" = 'linux'* ]]
then then
PS1="${TITLEBAR}${SAVE_CURSOR}${MOVE_CURSOR_RIGHTMOST}${MOVE_CURSOR_5_LEFT} PS1="${TITLEBAR}${SAVE_CURSOR}${MOVE_CURSOR_RIGHTMOST}${MOVE_CURSOR_5_LEFT}
$(safe_battery_charge)${RESTORE_CURSOR}\ $(battery_charge)${RESTORE_CURSOR}\
${D_USER_COLOR}\u ${D_INTERMEDIATE_COLOR}\ ${D_USER_COLOR}\u ${D_INTERMEDIATE_COLOR}\
at ${D_MACHINE_COLOR}\h ${D_INTERMEDIATE_COLOR}\ at ${D_MACHINE_COLOR}\h ${D_INTERMEDIATE_COLOR}\
in ${D_DIR_COLOR}\w ${D_INTERMEDIATE_COLOR}\ in ${D_DIR_COLOR}\w ${D_INTERMEDIATE_COLOR}\
@ -117,7 +109,7 @@ in ${D_DIR_COLOR}\w ${D_INTERMEDIATE_COLOR}\
${LAST_COMMAND_FAILED}\ ${LAST_COMMAND_FAILED}\
$(demula_vcprompt)\ $(demula_vcprompt)\
$(is_vim_shell)\ $(is_vim_shell)\
$(safe_battery_charge) $(battery_charge)
${D_INTERMEDIATE_COLOR}$ ${D_DEFAULT_COLOR}" ${D_INTERMEDIATE_COLOR}$ ${D_DEFAULT_COLOR}"
fi fi

View File

@ -115,14 +115,6 @@ ${D_BRANCH_COLOR}%b %r ${D_CHANGES_COLOR}%m%u ${D_DEFAULT_COLOR}"
fi fi
} }
# checks if the plugin is installed before calling battery_charge
safe_battery_charge() {
if _command_exists battery_charge ;
then
battery_charge
fi
}
prompt_git() { prompt_git() {
local s=''; local s='';
local branchName=''; local branchName='';
@ -185,7 +177,7 @@ prompt() {
then then
PS1="${TITLEBAR} PS1="${TITLEBAR}
${SAVE_CURSOR}${MOVE_CURSOR_RIGHTMOST}${MOVE_CURSOR_5_LEFT}\ ${SAVE_CURSOR}${MOVE_CURSOR_RIGHTMOST}${MOVE_CURSOR_5_LEFT}\
$(safe_battery_charge)${RESTORE_CURSOR}\ $(battery_charge)${RESTORE_CURSOR}\
${D_USER_COLOR}\u ${D_INTERMEDIATE_COLOR}\ ${D_USER_COLOR}\u ${D_INTERMEDIATE_COLOR}\
at ${D_MACHINE_COLOR}\h ${D_INTERMEDIATE_COLOR}\ at ${D_MACHINE_COLOR}\h ${D_INTERMEDIATE_COLOR}\
in ${D_DIR_COLOR}\w ${D_INTERMEDIATE_COLOR}\ in ${D_DIR_COLOR}\w ${D_INTERMEDIATE_COLOR}\
@ -203,7 +195,7 @@ $(prompt_git "$D_INTERMEDIATE_COLOR on $D_GIT_COLOR")\
${LAST_COMMAND_FAILED}\ ${LAST_COMMAND_FAILED}\
$(demula_vcprompt)\ $(demula_vcprompt)\
$(is_vim_shell)\ $(is_vim_shell)\
$(safe_battery_charge) $(battery_charge)
${D_INTERMEDIATE_COLOR}$ ${D_DEFAULT_COLOR}" ${D_INTERMEDIATE_COLOR}$ ${D_DEFAULT_COLOR}"
fi fi