diff --git a/.gitignore b/.gitignore index 769be90..4e8c377 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ # JUnit reports **/report.xml +venv/** \ No newline at end of file diff --git a/src/battery-widget.sh b/src/battery-widget.sh index a1f641b..ca1aa9e 100755 --- a/src/battery-widget.sh +++ b/src/battery-widget.sh @@ -4,24 +4,23 @@ ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.." . "${ROOT_DIR}/lib/coreutils-compat.sh" -# check if not enabled +# Check if the battery widget is enabled SHOW_BATTERY_WIDGET=$(tmux show-option -gv @tokyo-night-tmux_show_battery_widget 2>/dev/null) if [ "${SHOW_BATTERY_WIDGET}" != "1" ]; then exit 0 fi -# get value from tmux config -BATTERY_NAME=$(tmux show-option -gv @tokyo-night-tmux_battery_name 2>/dev/null) # default 'BAT1' -BATTERY_LOW=$(tmux show-option -gv @tokyo-night-tmux_battery_low_threshold 2>/dev/null) # default 21 +# Get values from tmux config or set defaults +BATTERY_NAME=$(tmux show-option -gv @tokyo-night-tmux_battery_name 2>/dev/null) +BATTERY_LOW=$(tmux show-option -gv @tokyo-night-tmux_battery_low_threshold 2>/dev/null) RESET="#[fg=brightwhite,bg=#15161e,nobold,noitalics,nounderscore,nodim]" DISCHARGING_ICONS=("󰁺" "󰁻" "󰁼" "󰁽" "󰁾" "󰁿" "󰂀" "󰂁" "󰂂" "󰁹") CHARGING_ICONS=("󰢜" "󰂆" "󰂇" "󰂈" "󰢝" "󰂉" "󰢞" "󰂊" "󰂋" "󰂅") NOT_CHARGING_ICON="󰚥" NO_BATTERY_ICON="󱉝" +DEFAULT_BATTERY_LOW=21 -default_show_battery_percentage=1 -default_battery_low="21" if [[ "$(uname)" == "Darwin" ]]; then default_battery_name="InternalBattery-0" else @@ -29,45 +28,98 @@ else fi BATTERY_NAME="${BATTERY_NAME:-$default_battery_name}" -BATTERY_LOW="${BATTERY_LOW:-$default_battery_low}" +BATTERY_LOW="${BATTERY_LOW:-$DEFAULT_BATTERY_LOW}" -# get battery stats -if [[ "$(uname)" == "Darwin" ]]; then - pmstat=$(pmset -g batt | grep $BATTERY_NAME) - BATTERY_STATUS=$(echo $pmstat | awk '{print $4}' | sed 's/[^a-z]*//g') - BATTERY_PERCENTAGE=$(echo $pmstat | awk '{print $3}' | sed 's/[^0-9]*//g') -else - BATTERY_STATUS=$(&1 | grep -q "EstimatedChargeRemaining" + ;; + *) + return 1 + ;; + esac +} + +# Exit if no battery is found +if ! battery_exists; then + echo "#[fg=green,bg=default]░ ${NOT_CHARGING_ICON}${RESET}#[bg=default]" + exit 0 fi -# set color and icon based on battery status -case "${BATTERY_STATUS}" in -"Charging" | "charging") - ICONS="${CHARGING_ICONS[$((BATTERY_PERCENTAGE / 10 - 1))]}" +# Get battery stats for different OS +get_battery_stats() { + local battery_name=$1 + local battery_status="" + local battery_percentage="" + + case "$(uname)" in + "Darwin") + pmstat=$(pmset -g batt | grep "$battery_name") + battery_status=$(echo "$pmstat" | awk '{print $4}' | sed 's/[^a-zA-Z]*//g') + battery_percentage=$(echo "$pmstat" | awk '{print $3}' | sed 's/[^0-9]*//g') + ;; + "Linux") + if [[ -f "/sys/class/power_supply/${battery_name}/status" && -f "/sys/class/power_supply/${battery_name}/capacity" ]]; then + battery_status=$(<"/sys/class/power_supply/${battery_name}/status") + battery_percentage=$(<"/sys/class/power_supply/${battery_name}/capacity") + else + battery_status="Unknown" + battery_percentage="0" + fi + ;; + "CYGWIN" | "MINGW" | "MSYS" | "Windows_NT") + battery_percentage=$(WMIC PATH Win32_Battery Get EstimatedChargeRemaining | grep -Eo '[0-9]+') + [[ -n $battery_percentage ]] && battery_status="Discharging" || battery_status="Unknown" + ;; + *) + battery_status="UnsupportedOS" + battery_percentage=0 + ;; + esac + + echo "$battery_status $battery_percentage" +} + +# Fetch the battery status and percentage +read -r BATTERY_STATUS BATTERY_PERCENTAGE < <(get_battery_stats "$BATTERY_NAME") + +# Ensure percentage is a number +if ! [[ $BATTERY_PERCENTAGE =~ ^[0-9]+$ ]]; then + BATTERY_PERCENTAGE=0 +fi + +# Determine icon and color based on battery status and percentage +case "$BATTERY_STATUS" in +"Charging" | "Charged" | "charging" | "Charged") + ICON="${CHARGING_ICONS[$((BATTERY_PERCENTAGE / 10))]}" ;; "Discharging" | "discharging") - ICONS="${DISCHARGING_ICONS[$((BATTERY_PERCENTAGE / 10 - 1))]}" - ;; -"Not charging" | "AC") - ICONS="${NOT_CHARGING_ICON}" + ICON="${DISCHARGING_ICONS[$((BATTERY_PERCENTAGE / 10))]}" ;; -"Full" | "charged") - ICONS="${NOT_CHARGING_ICON}" +"Full" | "charged" | "full" | "AC") + ICON="$NOT_CHARGING_ICON" ;; *) - ICONS="${NO_BATTERY_ICON}" - BATTERY_PERCENTAGE="0" + ICON="$NO_BATTERY_ICON" ;; esac -# set color on battery capacity -if [[ ${BATTERY_PERCENTAGE} -lt ${BATTERY_LOW} ]]; then - _color="#[fg=red,bg=default,bold]" -elif [[ ${BATTERY_PERCENTAGE} -ge 100 ]]; then - _color="#[fg=green,bg=default]" +# Set color based on battery percentage +if [[ $BATTERY_PERCENTAGE -lt $BATTERY_LOW ]]; then + color="#[fg=red,bg=default,bold]" +elif [[ $BATTERY_PERCENTAGE -ge 100 ]]; then + color="#[fg=green,bg=default]" else - _color="#[fg=yellow,bg=default]" + color="#[fg=yellow,bg=default]" fi -echo "${_color}░ ${ICONS}${RESET}#[bg=default] ${BATTERY_PERCENTAGE}% " +# Print the battery status with some extra spaces for padding +echo "${color}░ ${ICON}${RESET} #[bg=default] ${BATTERY_PERCENTAGE}% " diff --git a/src/custom-number.sh b/src/custom-number.sh index 0408d3a..aadf376 100755 --- a/src/custom-number.sh +++ b/src/custom-number.sh @@ -4,6 +4,7 @@ ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.." . "${ROOT_DIR}/lib/coreutils-compat.sh" +format_hide="" format_none="0123456789" format_digital="🯰🯱🯲🯳🯴🯵🯶🯷🯸🯹" format_fsquare="󰎡󰎤󰎧󰎪󰎭󰎱󰎳󰎶󰎹󰎼" @@ -18,6 +19,11 @@ FORMAT=${2:-none} # Preserve leading whitespace for bash format="$(eval echo \"\$format_${FORMAT}\")" + +if [ "$FORMAT" = "hide" ]; then + exit 0 +fi + if [ -z "$format" ]; then echo "Invalid format: $FORMAT" exit 1 @@ -25,11 +31,10 @@ fi # If format is roman numerals (-r), only handle IDs of 1 digit if [ "$FORMAT" = "roman" ] && [ ${#ID} -gt 1 ]; then - echo -n $ID - continue + echo -n "$ID " else for ((i = 0; i < ${#ID}; i++)); do DIGIT=${ID:i:1} - echo -n "${format:DIGIT:1}" + echo -n "${format:DIGIT:1} " done fi diff --git a/src/datetime-widget.sh b/src/datetime-widget.sh index 0fd725f..6cf19dc 100755 --- a/src/datetime-widget.sh +++ b/src/datetime-widget.sh @@ -22,24 +22,35 @@ time_string="" if [[ $date_format == "YMD" ]]; then # Year Month Day date format - date_string="%Y-%m-%d" + date_string=" %Y-%m-%d" elif [[ $date_format == "MDY" ]]; then # Month Day Year date format - date_string="%m-%d-%Y" + date_string=" %m-%d-%Y" elif [[ $date_format == "DMY" ]]; then # Day Month Year date format - date_string="%d-%m-%Y" + date_string=" %d-%m-%Y" +elif [[ $date_format == "hide" ]]; then + # Day Month Year date format + date_string="" else # Default to YMD date format if not specified - date_string="%Y-%m-%d" + date_string=" %Y-%m-%d" fi if [[ $time_format == "12H" ]]; then # 12-hour format with AM/PM - time_string="%I:%M %p" + time_string="%I:%M %p " +elif [[ $time_format == "hide" ]]; then + # 24-hour format + time_string="" else # Default to 24-hour format if not specified - time_string="%H:%M" + time_string="%H:%M " +fi + +separator="" +if [[ $date_string && $time_string ]]; then + separator="❬ " fi -echo "$RESET#[fg=${THEME[foreground]},bg=${THEME[bblack]}] $date_string #[]❬ $time_string " +echo "$RESET#[fg=${THEME[foreground]},bg=${THEME[bblack]}]$date_string $separator$time_string" diff --git a/tokyo-night.tmux b/tokyo-night.tmux index 7d06fe9..6a55454 100755 --- a/tokyo-night.tmux +++ b/tokyo-night.tmux @@ -58,9 +58,9 @@ tmux set -g status-left "#[fg=${THEME[bblack]},bg=${THEME[blue]},bold] #{?client #+--- Windows ---+ # Focus -tmux set -g window-status-current-format "$RESET#[fg=${THEME[green]},bg=${THEME[bblack]}] #{?#{==:#{pane_current_command},ssh},󰣀,} #[fg=${THEME[foreground]},bold,nodim]$window_number #W#[nobold]#{?window_zoomed_flag, $zoom_number, $custom_pane} #{?window_last_flag,,} " +tmux set -g window-status-current-format "$RESET#[fg=${THEME[green]},bg=${THEME[bblack]}] #{?#{==:#{pane_current_command},ssh},󰣀 , }#[fg=${THEME[foreground]},bold,nodim]$window_number#W#[nobold]#{?window_zoomed_flag, $zoom_number, $custom_pane}#{?window_last_flag, , }" # Unfocused -tmux set -g window-status-format "$RESET#[fg=${THEME[foreground]}] #{?#{==:#{pane_current_command},ssh},󰣀,}${RESET} $window_number #W#[nobold,dim]#{?window_zoomed_flag, $zoom_number, $custom_pane} #[fg=${THEME[yellow]}]#{?window_last_flag,󰁯 , } " +tmux set -g window-status-format "$RESET#[fg=${THEME[foreground]}] #{?#{==:#{pane_current_command},ssh},󰣀 , }${RESET}$window_number#W#[nobold,dim]#{?window_zoomed_flag, $zoom_number, $custom_pane}#[fg=${THEME[yellow]}]#{?window_last_flag,󰁯 , }" #+--- Bars RIGHT ---+ tmux set -g status-right "$battery_status$current_path$cmus_status$netspeed$git_status$wb_git_status$date_and_time"