Skip to content

Commit

Permalink
lib/battery: rename plugin/battery
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gaelicWizard committed Feb 9, 2022
1 parent c66be51 commit ecc54ac
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 30 deletions.
File renamed without changes.
File renamed without changes.
14 changes: 4 additions & 10 deletions themes/base.theme.bash
Original file line number Diff line number Diff line change
Expand Up @@ -565,21 +565,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 -e "${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 -e "${AWS_DEFAULT_PROFILE}"
Expand Down
12 changes: 2 additions & 10 deletions themes/demula/demula.theme.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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}\
Expand All @@ -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

Expand Down
12 changes: 2 additions & 10 deletions themes/rana/rana.theme.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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='';
Expand Down Expand Up @@ -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}\
Expand All @@ -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

Expand Down

0 comments on commit ecc54ac

Please sign in to comment.