From 7a9420ec9b4eddc344a2679ad735d09ed6e9a605 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 4 Mar 2022 12:37:15 -0800 Subject: [PATCH] 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. --- .../battery.plugin.bash => lib/battery.bash | 0 .../battery.plugin.bats => lib/battery.bats} | 0 themes/base.theme.bash | 14 ++++---------- themes/demula/demula.theme.bash | 12 ++---------- themes/rana/rana.theme.bash | 12 ++---------- 5 files changed, 8 insertions(+), 30 deletions(-) rename plugins/available/battery.plugin.bash => lib/battery.bash (100%) rename test/{plugins/battery.plugin.bats => lib/battery.bats} (100%) diff --git a/plugins/available/battery.plugin.bash b/lib/battery.bash similarity index 100% rename from plugins/available/battery.plugin.bash rename to lib/battery.bash diff --git a/test/plugins/battery.plugin.bats b/test/lib/battery.bats similarity index 100% rename from test/plugins/battery.plugin.bats rename to test/lib/battery.bats diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 92a56e5e..d64263d8 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -555,21 +555,15 @@ function prompt_char() { } function battery_char() { - # The battery_char function depends on the presence of the battery_percentage function. - if [[ "${THEME_BATTERY_PERCENTAGE_CHECK}" == true ]] && _command_exists battery_percentage; then - echo -ne "${bold_red?}$(battery_percentage)%" + local battery_percentage + battery_percentage="$(battery_percentage)" + if [[ "${THEME_BATTERY_PERCENTAGE_CHECK}" == true ]]; then + echo -e "${bold_red?}${battery_percentage}%" else false fi } -if ! _command_exists battery_charge; then - # if user has installed battery plugin, skip this... - function battery_charge() { - : # no op - } -fi - function aws_profile() { if [[ -n "${AWS_DEFAULT_PROFILE:-}" ]]; then echo -ne "${AWS_DEFAULT_PROFILE}" diff --git a/themes/demula/demula.theme.bash b/themes/demula/demula.theme.bash index 7d8d6cc8..17e068cd 100644 --- a/themes/demula/demula.theme.bash +++ b/themes/demula/demula.theme.bash @@ -82,14 +82,6 @@ ${D_BRANCH_COLOR}%b %r ${D_CHANGES_COLOR}%m%u ${D_DEFAULT_COLOR}" 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() { local LAST_COMMAND_FAILED=$(mitsuhikos_lastcommandfailed) @@ -101,7 +93,7 @@ prompt() { if [[ "$OSTYPE" = 'linux'* ]] then 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}\ at ${D_MACHINE_COLOR}\h ${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}\ $(demula_vcprompt)\ $(is_vim_shell)\ -$(safe_battery_charge) +$(battery_charge) ${D_INTERMEDIATE_COLOR}$ ${D_DEFAULT_COLOR}" fi diff --git a/themes/rana/rana.theme.bash b/themes/rana/rana.theme.bash index 3da74d6d..e9703c41 100644 --- a/themes/rana/rana.theme.bash +++ b/themes/rana/rana.theme.bash @@ -115,14 +115,6 @@ ${D_BRANCH_COLOR}%b %r ${D_CHANGES_COLOR}%m%u ${D_DEFAULT_COLOR}" 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() { local s=''; local branchName=''; @@ -185,7 +177,7 @@ prompt() { then 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}\ at ${D_MACHINE_COLOR}\h ${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}\ $(demula_vcprompt)\ $(is_vim_shell)\ -$(safe_battery_charge) +$(battery_charge) ${D_INTERMEDIATE_COLOR}$ ${D_DEFAULT_COLOR}" fi