Skip to content

Commit 07d11b9

Browse files
committed
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.
1 parent 3623777 commit 07d11b9

File tree

5 files changed

+8
-30
lines changed

5 files changed

+8
-30
lines changed
File renamed without changes.
File renamed without changes.

themes/base.theme.bash

+4-10
Original file line numberDiff line numberDiff line change
@@ -565,21 +565,15 @@ function prompt_char() {
565565
}
566566

567567
function battery_char() {
568-
# The battery_char function depends on the presence of the battery_percentage function.
569-
if [[ "${THEME_BATTERY_PERCENTAGE_CHECK}" == true ]] && _command_exists battery_percentage; then
570-
echo -e "${bold_red?}$(battery_percentage)%"
568+
local battery_percentage
569+
battery_percentage="$(battery_percentage)"
570+
if [[ "${THEME_BATTERY_PERCENTAGE_CHECK}" == true ]]; then
571+
echo -e "${bold_red?}${battery_percentage}%"
571572
else
572573
false
573574
fi
574575
}
575576

576-
if ! _command_exists battery_charge; then
577-
# if user has installed battery plugin, skip this...
578-
function battery_charge() {
579-
: # no op
580-
}
581-
fi
582-
583577
function aws_profile() {
584578
if [[ -n "${AWS_DEFAULT_PROFILE:-}" ]]; then
585579
echo -e "${AWS_DEFAULT_PROFILE}"

themes/demula/demula.theme.bash

+2-10
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,6 @@ ${D_BRANCH_COLOR}%b %r ${D_CHANGES_COLOR}%m%u ${D_DEFAULT_COLOR}"
8282
fi
8383
}
8484

85-
# checks if the plugin is installed before calling battery_charge
86-
safe_battery_charge() {
87-
if _command_exists battery_charge ;
88-
then
89-
battery_charge
90-
fi
91-
}
92-
9385
# -------------------------------------------------------------- PROMPT OUTPUT
9486
prompt() {
9587
local LAST_COMMAND_FAILED=$(mitsuhikos_lastcommandfailed)
@@ -101,7 +93,7 @@ prompt() {
10193
if [[ "$OSTYPE" = 'linux'* ]]
10294
then
10395
PS1="${TITLEBAR}${SAVE_CURSOR}${MOVE_CURSOR_RIGHTMOST}${MOVE_CURSOR_5_LEFT}
104-
$(safe_battery_charge)${RESTORE_CURSOR}\
96+
$(battery_charge)${RESTORE_CURSOR}\
10597
${D_USER_COLOR}\u ${D_INTERMEDIATE_COLOR}\
10698
at ${D_MACHINE_COLOR}\h ${D_INTERMEDIATE_COLOR}\
10799
in ${D_DIR_COLOR}\w ${D_INTERMEDIATE_COLOR}\
@@ -117,7 +109,7 @@ in ${D_DIR_COLOR}\w ${D_INTERMEDIATE_COLOR}\
117109
${LAST_COMMAND_FAILED}\
118110
$(demula_vcprompt)\
119111
$(is_vim_shell)\
120-
$(safe_battery_charge)
112+
$(battery_charge)
121113
${D_INTERMEDIATE_COLOR}$ ${D_DEFAULT_COLOR}"
122114
fi
123115

themes/rana/rana.theme.bash

+2-10
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,6 @@ ${D_BRANCH_COLOR}%b %r ${D_CHANGES_COLOR}%m%u ${D_DEFAULT_COLOR}"
115115
fi
116116
}
117117

118-
# checks if the plugin is installed before calling battery_charge
119-
safe_battery_charge() {
120-
if _command_exists battery_charge ;
121-
then
122-
battery_charge
123-
fi
124-
}
125-
126118
prompt_git() {
127119
local s='';
128120
local branchName='';
@@ -185,7 +177,7 @@ prompt() {
185177
then
186178
PS1="${TITLEBAR}
187179
${SAVE_CURSOR}${MOVE_CURSOR_RIGHTMOST}${MOVE_CURSOR_5_LEFT}\
188-
$(safe_battery_charge)${RESTORE_CURSOR}\
180+
$(battery_charge)${RESTORE_CURSOR}\
189181
${D_USER_COLOR}\u ${D_INTERMEDIATE_COLOR}\
190182
at ${D_MACHINE_COLOR}\h ${D_INTERMEDIATE_COLOR}\
191183
in ${D_DIR_COLOR}\w ${D_INTERMEDIATE_COLOR}\
@@ -203,7 +195,7 @@ $(prompt_git "$D_INTERMEDIATE_COLOR on $D_GIT_COLOR")\
203195
${LAST_COMMAND_FAILED}\
204196
$(demula_vcprompt)\
205197
$(is_vim_shell)\
206-
$(safe_battery_charge)
198+
$(battery_charge)
207199
${D_INTERMEDIATE_COLOR}$ ${D_DEFAULT_COLOR}"
208200
fi
209201

0 commit comments

Comments
 (0)