From 7a51ea23eeea3590db6db18a3730d64427c2774d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Felipe=20S=C3=A1nchez?= Date: Thu, 25 May 2017 00:21:30 -0500 Subject: [PATCH 1/7] Improvements in Atomic theme Operating system detection was added to show the percentage of the battery in the promt --- themes/atomic/atomic.theme.bash | 65 ++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/themes/atomic/atomic.theme.bash b/themes/atomic/atomic.theme.bash index 467e8c4c..ef90f06e 100644 --- a/themes/atomic/atomic.theme.bash +++ b/themes/atomic/atomic.theme.bash @@ -166,7 +166,48 @@ ___atomic_prompt_clock() { printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}" } -___atomic_prompt_battery() { +case "$OSTYPE" in + cygwin*) ___atomic_prompt_battery() { + [ "${THEME_SHOW_BATTERY}" != "true" ] && return + batp=$(echo porcent=$(WMIC PATH Win32_Battery Get EstimatedChargeRemaining /Format:List) | grep -o '[0-9]*') + bats=$(echo porcent=$(WMIC Path Win32_Battery Get BatteryStatus /Format:List) | grep -o '[0-9]*') + + if [ "$batp" -gt 50 ]; then + color=$bold_green + elif [ "$batp" -lt 50 ] && [ "$batp" -gt 25 ]; then + color=$bold_yellow + elif [ "$batp" -lt 25 ]; then + color=$IRed + fi + + box="[|]" + [ "$bats" -eq 1 ] && info="-" + [ "$bats" -eq 2 ] && info="+" + info+=$batp + [ "$info" == "+100" ] && info="AC" + printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}" + } ;; + msys*) ___atomic_prompt_battery() { + [ "${THEME_SHOW_BATTERY}" != "true" ] && return + batp=$(echo porcent=$(WMIC PATH Win32_Battery Get EstimatedChargeRemaining /Format:List) | grep -o '[0-9]*') + bats=$(echo porcent=$(WMIC Path Win32_Battery Get BatteryStatus /Format:List) | grep -o '[0-9]*') + + if [ "$batp" -gt 50 ]; then + color=$bold_green + elif [ "$batp" -lt 50 ] && [ "$batp" -gt 25 ]; then + color=$bold_yellow + elif [ "$batp" -lt 25 ]; then + color=$IRed + fi + + box="[|]" + [ "$bats" -eq 1 ] && info="-" + [ "$bats" -eq 2 ] && info="+" + info+=$batp + [ "$info" == "+100" ] && info="AC" + printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}" + } ;; + darwin*) ___atomic_prompt_battery() { [ ! -e "$BASH_IT"/plugins/enabled/battery.plugin.bash ] || [ "${THEME_SHOW_BATTERY}" != "true" ] && return batp=$(battery_percentage) @@ -183,7 +224,27 @@ ___atomic_prompt_battery() { info+=$batp [ "$info" == "+100" ] && info="AC" printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}" -} + } ;; + linux*) ___atomic_prompt_battery() { + [ ! -e "$BASH_IT"/plugins/enabled/battery.plugin.bash ] || + [ "${THEME_SHOW_BATTERY}" != "true" ] && return + batp=$(battery_percentage) + if [ "$batp" -gt 50 ]; then + color=$bold_green + elif [ "$batp" -lt 50 ] && [ "$batp" -gt 25 ]; then + color=$bold_yellow + elif [ "$batp" -lt 25 ]; then + color=$IRed + fi + box="[|]" + ac_adapter_disconnected && info="-" + ac_adapter_connected && info="+" + info+=$batp + [ "$info" == "+100" ] && info="AC" + printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}" + } ;; + *) echo "bt:" ;; +esac ___atomic_prompt_exitcode() { [ "${THEME_SHOW_EXITCODE}" != "true" ] && return From 176cf00f6c32f0a2c84ade5951f12fe5638bbce5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Felipe=20S=C3=A1nchez?= Date: Thu, 25 May 2017 23:27:12 -0500 Subject: [PATCH 2/7] Update battery.plugin.bash - Add WIndows Bash checker. - Clean and organize the code. --- plugins/available/battery.plugin.bash | 78 ++++++++++++++++----------- 1 file changed, 47 insertions(+), 31 deletions(-) diff --git a/plugins/available/battery.plugin.bash b/plugins/available/battery.plugin.bash index db5a94f5..e4cee35d 100644 --- a/plugins/available/battery.plugin.bash +++ b/plugins/available/battery.plugin.bash @@ -10,6 +10,10 @@ ac_adapter_connected(){ then ioreg -n AppleSmartBattery -r | grep -q '"ExternalConnected" = Yes' return $? + elif command_exists WMIC; + then + WMIC Path Win32_Battery Get BatteryStatus /Format:List | grep -q 'BatteryStatus=2' + return $? fi } @@ -22,13 +26,17 @@ ac_adapter_disconnected(){ then ioreg -n AppleSmartBattery -r | grep -q '"ExternalConnected" = No' return $? + elif command_exists WMIC; + then + WMIC Path Win32_Battery Get BatteryStatus /Format:List | grep -q 'BatteryStatus=1' + return $? fi } battery_percentage(){ about 'displays battery charge as a percentage of full (100%)' group 'battery' - + if command_exists acpi; then local ACPI_OUTPUT=$(acpi -b) @@ -38,37 +46,45 @@ battery_percentage(){ case $PERC_OUTPUT in *%) echo "0${PERC_OUTPUT}" | head -c 2 - ;; + ;; *) echo ${PERC_OUTPUT} - ;; + ;; esac - ;; - + ;; + *" Charging"* | *" Discharging"*) local PERC_OUTPUT=$(echo $ACPI_OUTPUT | awk -F, '/,/{gsub(/ /, "", $0); gsub(/%/,"", $0); print $2}' ) echo ${PERC_OUTPUT} - ;; + ;; *" Full"*) echo '100' - ;; + ;; *) echo '-1' - ;; + ;; esac elif command_exists ioreg; then - # http://hints.macworld.com/article.php?story=20100130123935998 - #local IOREG_OUTPUT_10_6=$(ioreg -l | grep -i capacity | tr '\n' ' | ' | awk '{printf("%.2f%%", $10/$5 * 100)}') - #local IOREG_OUTPUT_10_5=$(ioreg -l | grep -i capacity | grep -v Legacy| tr '\n' ' | ' | awk '{printf("%.2f%%", $14/$7 * 100)}') local IOREG_OUTPUT=$(ioreg -n AppleSmartBattery -r | awk '$1~/Capacity/{c[$1]=$3} END{OFMT="%05.2f%%"; max=c["\"MaxCapacity\""]; print (max>0? 100*c["\"CurrentCapacity\""]/max: "?")}') case $IOREG_OUTPUT in 100*) echo '100' - ;; + ;; *) echo $IOREG_OUTPUT | head -c 2 - ;; + ;; + esac + elif command_exists WMIC; + then + local WINPC=$(echo porcent=$(WMIC PATH Win32_Battery Get EstimatedChargeRemaining /Format:List) | grep -o '[0-9]*') + case $WINPC in + 100*) + echo '100' + ;; + *) + echo $WINPC + ;; esac else echo "no" @@ -78,7 +94,7 @@ battery_percentage(){ battery_charge(){ about 'graphical display of your battery charge' group 'battery' - + # Full char local F_C='▸' # Depleted char @@ -89,55 +105,55 @@ battery_charge(){ local DANGER_COLOR="${red}" local BATTERY_OUTPUT="${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${D_C}" local BATTERY_PERC=$(battery_percentage) - + case $BATTERY_PERC in no) echo "" - ;; + ;; 9*) echo "${FULL_COLOR}${F_C}${F_C}${F_C}${F_C}${F_C}${normal}" - ;; + ;; 8*) echo "${FULL_COLOR}${F_C}${F_C}${F_C}${F_C}${HALF_COLOR}${F_C}${normal}" - ;; + ;; 7*) echo "${FULL_COLOR}${F_C}${F_C}${F_C}${F_C}${DEPLETED_COLOR}${D_C}${normal}" - ;; + ;; 6*) echo "${FULL_COLOR}${F_C}${F_C}${F_C}${HALF_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${normal}" - ;; + ;; 5*) echo "${FULL_COLOR}${F_C}${F_C}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${normal}" - ;; + ;; 4*) echo "${FULL_COLOR}${F_C}${F_C}${HALF_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${normal}" - ;; + ;; 3*) echo "${FULL_COLOR}${F_C}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${normal}" - ;; + ;; 2*) echo "${FULL_COLOR}${F_C}${HALF_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${normal}" - ;; + ;; 1*) echo "${FULL_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${normal}" - ;; + ;; 05) echo "${DANGER_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${normal}" - ;; + ;; 04) echo "${DANGER_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${normal}" - ;; + ;; 03) echo "${DANGER_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${normal}" - ;; + ;; 02) echo "${DANGER_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${normal}" - ;; + ;; 0*) echo "${HALF_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${normal}" - ;; + ;; *) echo "${DANGER_COLOR}UNPLG${normal}" - ;; + ;; esac } From 6e1477a8aa057f8e6a5be9143eb07eac11987e32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Felipe=20S=C3=A1nchez?= Date: Thu, 25 May 2017 23:43:18 -0500 Subject: [PATCH 3/7] Update atomic.theme.bash - Reverted Battery Segment to the original. - Now the segment is the same for all operating systems. - Battery Plugin control segment battery in theme. - I have cleaned and organized the code :smiley: --- themes/atomic/atomic.theme.bash | 404 ++++++++++++++------------------ 1 file changed, 170 insertions(+), 234 deletions(-) diff --git a/themes/atomic/atomic.theme.bash b/themes/atomic/atomic.theme.bash index ef90f06e..68515edd 100644 --- a/themes/atomic/atomic.theme.bash +++ b/themes/atomic/atomic.theme.bash @@ -9,12 +9,9 @@ IRed="\e[1;49;31m" IGreen="\e[1;49;32m" IYellow="\e[1;49;33m" -ICyan="\e[1;49;36m" IWhite="\e[1;49;37m" -White="\e[0;49;37m" BIWhite="\e[1;49;37m" BICyan="\e[1;49;36m" -ResetColor="\e[0;49;37m" ############# ## Symbols ## @@ -31,79 +28,79 @@ Face="\342\230\273" ############# ____atomic_top_left_parse() { - ifs_old="${IFS}" - IFS="|" - args=( $1 ) - IFS="${ifs_old}" - if [ -n "${args[3]}" ]; then - _TOP_LEFT+="${args[2]}${args[3]}" - fi - _TOP_LEFT+="${args[0]}${args[1]}" - if [ -n "${args[4]}" ]; then - _TOP_LEFT+="${args[2]}${args[4]}" - fi - _TOP_LEFT+="" + ifs_old="${IFS}" + IFS="|" + args=( $1 ) + IFS="${ifs_old}" + if [ -n "${args[3]}" ]; then + _TOP_LEFT+="${args[2]}${args[3]}" + fi + _TOP_LEFT+="${args[0]}${args[1]}" + if [ -n "${args[4]}" ]; then + _TOP_LEFT+="${args[2]}${args[4]}" + fi + _TOP_LEFT+="" } ____atomic_top_right_parse() { - ifs_old="${IFS}" - IFS="|" - args=( $1 ) - IFS="${ifs_old}" - _TOP_RIGHT+=" " - if [ -n "${args[3]}" ]; then - _TOP_RIGHT+="${args[2]}${args[3]}" - fi - _TOP_RIGHT+="${args[0]}${args[1]}" - if [ -n "${args[4]}" ]; then - _TOP_RIGHT+="${args[2]}${args[4]}" - fi - __TOP_RIGHT_LEN=$(( __TOP_RIGHT_LEN + ${#args[1]} + ${#args[3]} + ${#args[4]} + 1 )) - (( __SEG_AT_RIGHT += 1 )) + ifs_old="${IFS}" + IFS="|" + args=( $1 ) + IFS="${ifs_old}" + _TOP_RIGHT+=" " + if [ -n "${args[3]}" ]; then + _TOP_RIGHT+="${args[2]}${args[3]}" + fi + _TOP_RIGHT+="${args[0]}${args[1]}" + if [ -n "${args[4]}" ]; then + _TOP_RIGHT+="${args[2]}${args[4]}" + fi + __TOP_RIGHT_LEN=$(( __TOP_RIGHT_LEN + ${#args[1]} + ${#args[3]} + ${#args[4]} + 1 )) + (( __SEG_AT_RIGHT += 1 )) } ____atomic_bottom_parse() { - ifs_old="${IFS}" - IFS="|" - args=( $1 ) - IFS="${ifs_old}" - _BOTTOM+="${args[0]}${args[1]}" - [ ${#args[1]} -gt 0 ] && _BOTTOM+=" " + ifs_old="${IFS}" + IFS="|" + args=( $1 ) + IFS="${ifs_old}" + _BOTTOM+="${args[0]}${args[1]}" + [ ${#args[1]} -gt 0 ] && _BOTTOM+=" " } ____atomic_top() { - _TOP_LEFT="" - _TOP_RIGHT="" - __TOP_RIGHT_LEN=0 - __SEG_AT_RIGHT=0 - - for seg in ${___ATOMIC_TOP_LEFT}; do - info="$(___atomic_prompt_"${seg}")" - [ -n "${info}" ] && ____atomic_top_left_parse "${info}" - done - - ___cursor_right="\e[500C" - _TOP_LEFT+="${___cursor_right}" - - for seg in ${___ATOMIC_TOP_RIGHT}; do - info="$(___atomic_prompt_"${seg}")" - [ -n "${info}" ] && ____atomic_top_right_parse "${info}" - done - - [ $__TOP_RIGHT_LEN -gt 0 ] && __TOP_RIGHT_LEN=$(( __TOP_RIGHT_LEN - 0 )) - ___cursor_adjust="\e[${__TOP_RIGHT_LEN}D" - _TOP_LEFT+="${___cursor_adjust}" - - printf "%s%s" "${_TOP_LEFT}" "${_TOP_RIGHT}" + _TOP_LEFT="" + _TOP_RIGHT="" + __TOP_RIGHT_LEN=0 + __SEG_AT_RIGHT=0 + + for seg in ${___ATOMIC_TOP_LEFT}; do + info="$(___atomic_prompt_"${seg}")" + [ -n "${info}" ] && ____atomic_top_left_parse "${info}" + done + + ___cursor_right="\e[500C" + _TOP_LEFT+="${___cursor_right}" + + for seg in ${___ATOMIC_TOP_RIGHT}; do + info="$(___atomic_prompt_"${seg}")" + [ -n "${info}" ] && ____atomic_top_right_parse "${info}" + done + + [ $__TOP_RIGHT_LEN -gt 0 ] && __TOP_RIGHT_LEN=$(( __TOP_RIGHT_LEN - 0 )) + ___cursor_adjust="\e[${__TOP_RIGHT_LEN}D" + _TOP_LEFT+="${___cursor_adjust}" + + printf "%s%s" "${_TOP_LEFT}" "${_TOP_RIGHT}" } ____atomic_bottom() { - _BOTTOM="" - for seg in $___ATOMIC_BOTTOM; do - info="$(___atomic_prompt_"${seg}")" - [ -n "${info}" ] && ____atomic_bottom_parse "${info}" - done - printf "\n%s" "${_BOTTOM}" + _BOTTOM="" + for seg in $___ATOMIC_BOTTOM; do + info="$(___atomic_prompt_"${seg}")" + [ -n "${info}" ] && ____atomic_bottom_parse "${info}" + done + printf "\n%s" "${_BOTTOM}" } ############## @@ -111,156 +108,95 @@ ____atomic_bottom() { ############## ___atomic_prompt_user_info() { - color=$white - box="${normal}${LineA}\$([[ \$? != 0 ]] && echo \"${BIWhite}[${IRed}${SX}${BIWhite}]${normal}${Line}\")${Line}${BIWhite}[|${BIWhite}]${normal}${Line}" - info="${IYellow}\u${IRed}@${IGreen}\h" - - printf "%s|%s|%s|%s" "${color}" "${info}" "${white}" "${box}" + color=$white + box="${normal}${LineA}\$([[ \$? != 0 ]] && echo \"${BIWhite}[${IRed}${SX}${BIWhite}]${normal}${Line}\")${Line}${BIWhite}[|${BIWhite}]${normal}${Line}" + info="${IYellow}\u${IRed}@${IGreen}\h" + + printf "%s|%s|%s|%s" "${color}" "${info}" "${white}" "${box}" } ___atomic_prompt_dir() { - color=${IRed} - box="[|]${normal}${Line}" - info="\w" - printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}" + color=${IRed} + box="[|]${normal}${Line}" + info="\w" + printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}" } ___atomic_prompt_scm() { - [ "${THEME_SHOW_SCM}" != "true" ] && return - color=$bold_green - box="[${IWhite}$(scm_char)] " - info="$(scm_prompt_info)" - printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}" + [ "${THEME_SHOW_SCM}" != "true" ] && return + color=$bold_green + box="[${IWhite}$(scm_char)] " + info="$(scm_prompt_info)" + printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}" } ___atomic_prompt_python() { - [ "${THEME_SHOW_PYTHON}" != "true" ] && return - color=$bold_yellow - box="[|]" - info="$(python_version_prompt)" - printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_blue}" "${box}" + [ "${THEME_SHOW_PYTHON}" != "true" ] && return + color=$bold_yellow + box="[|]" + info="$(python_version_prompt)" + printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_blue}" "${box}" } ___atomic_prompt_ruby() { - [ "${THEME_SHOW_RUBY}" != "true" ] && return - color=$bold_white - box="[|]" - info="rb-$(ruby_version_prompt)" - printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_red}" "${box}" + [ "${THEME_SHOW_RUBY}" != "true" ] && return + color=$bold_white + box="[|]" + info="rb-$(ruby_version_prompt)" + printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_red}" "${box}" } ___atomic_prompt_todo() { - [ "${THEME_SHOW_TODO}" != "true" ] || - [ -z "$(which todo.sh)" ] && return - color=$bold_white - box="[|]" - info="t:$(todo.sh ls | egrep "TODO: [0-9]+ of ([0-9]+)" | awk '{ print $4 }' )" - printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_green}" "${box}" + [ "${THEME_SHOW_TODO}" != "true" ] || + [ -z "$(which todo.sh)" ] && return + color=$bold_white + box="[|]" + info="t:$(todo.sh ls | egrep "TODO: [0-9]+ of ([0-9]+)" | awk '{ print $4 }' )" + printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_green}" "${box}" } ___atomic_prompt_clock() { - [ "${THEME_SHOW_CLOCK}" != "true" ] && return - color=$THEME_CLOCK_COLOR - box="[|]" - info="$(date +"${THEME_CLOCK_FORMAT}")" - printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}" + [ "${THEME_SHOW_CLOCK}" != "true" ] && return + color=$THEME_CLOCK_COLOR + box="[|]" + info="$(date +"${THEME_CLOCK_FORMAT}")" + printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}" } -case "$OSTYPE" in - cygwin*) ___atomic_prompt_battery() { - [ "${THEME_SHOW_BATTERY}" != "true" ] && return - batp=$(echo porcent=$(WMIC PATH Win32_Battery Get EstimatedChargeRemaining /Format:List) | grep -o '[0-9]*') - bats=$(echo porcent=$(WMIC Path Win32_Battery Get BatteryStatus /Format:List) | grep -o '[0-9]*') - - if [ "$batp" -gt 50 ]; then - color=$bold_green - elif [ "$batp" -lt 50 ] && [ "$batp" -gt 25 ]; then - color=$bold_yellow - elif [ "$batp" -lt 25 ]; then - color=$IRed - fi - - box="[|]" - [ "$bats" -eq 1 ] && info="-" - [ "$bats" -eq 2 ] && info="+" - info+=$batp - [ "$info" == "+100" ] && info="AC" - printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}" - } ;; - msys*) ___atomic_prompt_battery() { - [ "${THEME_SHOW_BATTERY}" != "true" ] && return - batp=$(echo porcent=$(WMIC PATH Win32_Battery Get EstimatedChargeRemaining /Format:List) | grep -o '[0-9]*') - bats=$(echo porcent=$(WMIC Path Win32_Battery Get BatteryStatus /Format:List) | grep -o '[0-9]*') - - if [ "$batp" -gt 50 ]; then - color=$bold_green - elif [ "$batp" -lt 50 ] && [ "$batp" -gt 25 ]; then - color=$bold_yellow - elif [ "$batp" -lt 25 ]; then - color=$IRed - fi - - box="[|]" - [ "$bats" -eq 1 ] && info="-" - [ "$bats" -eq 2 ] && info="+" - info+=$batp - [ "$info" == "+100" ] && info="AC" - printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}" - } ;; - darwin*) ___atomic_prompt_battery() { - [ ! -e "$BASH_IT"/plugins/enabled/battery.plugin.bash ] || - [ "${THEME_SHOW_BATTERY}" != "true" ] && return - batp=$(battery_percentage) - if [ "$batp" -gt 50 ]; then - color=$bold_green - elif [ "$batp" -lt 50 ] && [ "$batp" -gt 25 ]; then - color=$bold_yellow - elif [ "$batp" -lt 25 ]; then - color=$IRed - fi - box="[|]" - ac_adapter_disconnected && info="-" - ac_adapter_connected && info="+" - info+=$batp - [ "$info" == "+100" ] && info="AC" - printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}" - } ;; - linux*) ___atomic_prompt_battery() { - [ ! -e "$BASH_IT"/plugins/enabled/battery.plugin.bash ] || - [ "${THEME_SHOW_BATTERY}" != "true" ] && return - batp=$(battery_percentage) - if [ "$batp" -gt 50 ]; then - color=$bold_green - elif [ "$batp" -lt 50 ] && [ "$batp" -gt 25 ]; then - color=$bold_yellow - elif [ "$batp" -lt 25 ]; then - color=$IRed - fi - box="[|]" - ac_adapter_disconnected && info="-" - ac_adapter_connected && info="+" - info+=$batp - [ "$info" == "+100" ] && info="AC" - printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}" - } ;; - *) echo "bt:" ;; -esac +___atomic_prompt_battery() { + [ ! -e "$BASH_IT"/plugins/enabled/battery.plugin.bash ] || + [ "${THEME_SHOW_BATTERY}" != "true" ] && return + batp=$(battery_percentage) + if [ "$batp" -gt 50 ]; then + color=$bold_green + elif [ "$batp" -lt 50 ] && [ "$batp" -gt 25 ]; then + color=$bold_yellow + elif [ "$batp" -lt 25 ]; then + color=$IRed + fi + box="[|]" + ac_adapter_disconnected && info="-" + ac_adapter_connected && info="+" + info+=$batp + [ "$info" == "+100" ] && info="AC" + printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}" +} ___atomic_prompt_exitcode() { - [ "${THEME_SHOW_EXITCODE}" != "true" ] && return - color=$bold_purple - [ "$exitcode" -ne 0 ] && printf "%s|%s" "${color}" "${exitcode}" + [ "${THEME_SHOW_EXITCODE}" != "true" ] && return + color=$bold_purple + [ "$exitcode" -ne 0 ] && printf "%s|%s" "${color}" "${exitcode}" } ___atomic_prompt_char() { - color=$white - prompt_char="${__ATOMIC_PROMPT_CHAR_PS1}" - if [ "${THEME_SHOW_SUDO}" == "true" ]; then - if [ $(sudo -n id -u 2>&1 | grep 0) ]; then - prompt_char="${__ATOMIC_PROMPT_CHAR_PS1_SUDO}" - fi - fi - printf "%s|%s" "${color}" "${prompt_char}" + color=$white + prompt_char="${__ATOMIC_PROMPT_CHAR_PS1}" + if [ "${THEME_SHOW_SUDO}" == "true" ]; then + if [ $(sudo -n id -u 2>&1 | grep 0) ]; then + prompt_char="${__ATOMIC_PROMPT_CHAR_PS1_SUDO}" + fi + fi + printf "%s|%s" "${color}" "${prompt_char}" } ######### @@ -269,53 +205,53 @@ ___atomic_prompt_char() { __atomic_show() { typeset _seg=${1:-} - shift - export THEME_SHOW_${_seg}=true + shift + export THEME_SHOW_${_seg}=true } __atomic_hide() { - typeset _seg=${1:-} - shift - export THEME_SHOW_${_seg}=false + typeset _seg=${1:-} + shift + export THEME_SHOW_${_seg}=false } _atomic_completion() { - local cur _action actions segments - COMPREPLY=() - cur="${COMP_WORDS[COMP_CWORD]}" - _action="${COMP_WORDS[1]}" - actions="show hide" - segments="battery clock exitcode python ruby scm sudo todo" - case "${_action}" in - show) - COMPREPLY=( $(compgen -W "${segments}" -- "${cur}") ) - return 0 - ;; - hide) - COMPREPLY=( $(compgen -W "${segments}" -- "${cur}") ) - return 0 - ;; - esac - - COMPREPLY=( $(compgen -W "${actions}" -- "${cur}") ) - return 0 + local cur _action actions segments + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + _action="${COMP_WORDS[1]}" + actions="show hide" + segments="battery clock exitcode python ruby scm sudo todo" + case "${_action}" in + show) + COMPREPLY=( $(compgen -W "${segments}" -- "${cur}") ) + return 0 + ;; + hide) + COMPREPLY=( $(compgen -W "${segments}" -- "${cur}") ) + return 0 + ;; + esac + + COMPREPLY=( $(compgen -W "${actions}" -- "${cur}") ) + return 0 } atomic() { - typeset action=${1:-} - shift - typeset segs=${*:-} - typeset func - case $action in - show) - func=__atomic_show;; - hide) - func=__atomic_hide;; - esac - for seg in ${segs}; do - seg=$(printf "%s" "${seg}" | tr '[:lower:]' '[:upper:]') - $func "${seg}" - done + typeset action=${1:-} + shift + typeset segs=${*:-} + typeset func + case $action in + show) + func=__atomic_show;; + hide) + func=__atomic_hide;; + esac + for seg in ${segs}; do + seg=$(printf "%s" "${seg}" | tr '[:lower:]' '[:upper:]') + $func "${seg}" + done } complete -F _atomic_completion atomic @@ -364,19 +300,19 @@ ___ATOMIC_BOTTOM=${___ATOMIC_BOTTOM:-"char"} ############ __atomic_ps1() { - printf "%s%s%s" "$(____atomic_top)" "$(____atomic_bottom)" "${normal}" + printf "%s%s%s" "$(____atomic_top)" "$(____atomic_bottom)" "${normal}" } __atomic_ps2() { - color=$bold_white - printf "%s%s%s" "${color}" "${__ATOMIC_PROMPT_CHAR_PS2} " "${normal}" + color=$bold_white + printf "%s%s%s" "${color}" "${__ATOMIC_PROMPT_CHAR_PS2} " "${normal}" } _atomic_prompt() { - exitcode="$?" - - PS1="$(__atomic_ps1)" - PS2="$(__atomic_ps2)" + exitcode="$?" + + PS1="$(__atomic_ps1)" + PS2="$(__atomic_ps2)" } safe_append_prompt_command _atomic_prompt From 8e98790c1d07cd2d808235f353d087d25b6dde3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Felipe=20S=C3=A1nchez?= Date: Fri, 26 May 2017 13:35:11 -0500 Subject: [PATCH 4/7] Update atomic.theme.bash - Changed the dependence of the battery plug-in. - Now checking if the function of the battery plugin exists, otherwise it will not load. --- themes/atomic/atomic.theme.bash | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/themes/atomic/atomic.theme.bash b/themes/atomic/atomic.theme.bash index 68515edd..e42db6e2 100644 --- a/themes/atomic/atomic.theme.bash +++ b/themes/atomic/atomic.theme.bash @@ -27,6 +27,8 @@ Face="\342\230\273" ## Parsers ## ############# +isFunction() { [[ "$(declare -Ff "$1")" ]]; } + ____atomic_top_left_parse() { ifs_old="${IFS}" IFS="|" @@ -164,8 +166,8 @@ ___atomic_prompt_clock() { } ___atomic_prompt_battery() { - [ ! -e "$BASH_IT"/plugins/enabled/battery.plugin.bash ] || - [ "${THEME_SHOW_BATTERY}" != "true" ] && return + chk=$(isFunction battery_percentage && echo yes || echo no) + [ "$chk" != "yes" ] || [ "${THEME_SHOW_BATTERY}" != "true" ] && return batp=$(battery_percentage) if [ "$batp" -gt 50 ]; then color=$bold_green From 692c3516d55361b8cf340bf3e8f329584c444a2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Felipe=20S=C3=A1nchez?= Date: Fri, 26 May 2017 13:38:22 -0500 Subject: [PATCH 5/7] Update atomic.theme.bash Minor Updates --- themes/atomic/atomic.theme.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/themes/atomic/atomic.theme.bash b/themes/atomic/atomic.theme.bash index e42db6e2..9b8ea14c 100644 --- a/themes/atomic/atomic.theme.bash +++ b/themes/atomic/atomic.theme.bash @@ -169,11 +169,11 @@ ___atomic_prompt_battery() { chk=$(isFunction battery_percentage && echo yes || echo no) [ "$chk" != "yes" ] || [ "${THEME_SHOW_BATTERY}" != "true" ] && return batp=$(battery_percentage) - if [ "$batp" -gt 50 ]; then + if [ "$batp" -eq 50 ] && [ "$batp" -gt 50 ]; then color=$bold_green elif [ "$batp" -lt 50 ] && [ "$batp" -gt 25 ]; then color=$bold_yellow - elif [ "$batp" -lt 25 ]; then + elif [ "$batp" -eq 25 ] && [ "$batp" -lt 25 ]; then color=$IRed fi box="[|]" From f936b1e4857fdc4d37ece6d6065c28951da3ff02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Felipe=20S=C3=A1nchez?= Date: Fri, 26 May 2017 13:41:08 -0500 Subject: [PATCH 6/7] Update atomic.theme.bash Minor Updates u_u --- themes/atomic/atomic.theme.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/themes/atomic/atomic.theme.bash b/themes/atomic/atomic.theme.bash index 9b8ea14c..6a7819f5 100644 --- a/themes/atomic/atomic.theme.bash +++ b/themes/atomic/atomic.theme.bash @@ -169,11 +169,11 @@ ___atomic_prompt_battery() { chk=$(isFunction battery_percentage && echo yes || echo no) [ "$chk" != "yes" ] || [ "${THEME_SHOW_BATTERY}" != "true" ] && return batp=$(battery_percentage) - if [ "$batp" -eq 50 ] && [ "$batp" -gt 50 ]; then + if [ "$batp" -eq 50 ] || [ "$batp" -gt 50 ]; then color=$bold_green elif [ "$batp" -lt 50 ] && [ "$batp" -gt 25 ]; then color=$bold_yellow - elif [ "$batp" -eq 25 ] && [ "$batp" -lt 25 ]; then + elif [ "$batp" -eq 25 ] || [ "$batp" -lt 25 ]; then color=$IRed fi box="[|]" From 7d318def4803db86f6db41a254d4501a8cec88bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Felipe=20S=C3=A1nchez?= Date: Sun, 28 May 2017 13:39:48 -0500 Subject: [PATCH 7/7] Update atomic.theme.bash Theme improved to 100% --- themes/atomic/atomic.theme.bash | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/themes/atomic/atomic.theme.bash b/themes/atomic/atomic.theme.bash index 6a7819f5..8ac18dfd 100644 --- a/themes/atomic/atomic.theme.bash +++ b/themes/atomic/atomic.theme.bash @@ -27,8 +27,6 @@ Face="\342\230\273" ## Parsers ## ############# -isFunction() { [[ "$(declare -Ff "$1")" ]]; } - ____atomic_top_left_parse() { ifs_old="${IFS}" IFS="|" @@ -166,7 +164,7 @@ ___atomic_prompt_clock() { } ___atomic_prompt_battery() { - chk=$(isFunction battery_percentage && echo yes || echo no) + chk=$(command_exists battery_percentage && echo yes || echo no) [ "$chk" != "yes" ] || [ "${THEME_SHOW_BATTERY}" != "true" ] && return batp=$(battery_percentage) if [ "$batp" -eq 50 ] || [ "$batp" -gt 50 ]; then