From d00c245d4e1dab2831db3da94a207c8bbe6fc404 Mon Sep 17 00:00:00 2001 From: Sabato Luca Guadagno Date: Tue, 6 Jul 2021 10:22:36 +0200 Subject: [PATCH 1/8] consistent formatting across all scripts --- .editorconfig | 5 + scripts/battery.sh | 182 +++++++++++++++---------------- scripts/cpu_info.sh | 62 +++++------ scripts/dracula.sh | 212 ++++++++++++++++++------------------ scripts/gpu_usage.sh | 40 +++---- scripts/network.sh | 62 +++++------ scripts/network_bandwith.sh | 28 ++--- scripts/ram_info.sh | 114 +++++++++---------- scripts/sleep_weather.sh | 40 +++---- scripts/weather.sh | 76 ++++++------- 10 files changed, 413 insertions(+), 408 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..8d81dbe --- /dev/null +++ b/.editorconfig @@ -0,0 +1,5 @@ +[*] +indent_size = 2 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true diff --git a/scripts/battery.sh b/scripts/battery.sh index c0a789c..24012fa 100755 --- a/scripts/battery.sh +++ b/scripts/battery.sh @@ -3,121 +3,121 @@ export LC_ALL=en_US.UTF-8 linux_acpi() { - arg=$1 - BAT=$(ls -d /sys/class/power_supply/BAT* | head -1) - if [ ! -x "$(which acpi 2> /dev/null)" ];then - case "$arg" in - status) - cat $BAT/status - ;; + arg=$1 + BAT=$(ls -d /sys/class/power_supply/BAT* | head -1) + if [ ! -x "$(which acpi 2> /dev/null)" ];then + case "$arg" in + status) + cat $BAT/status + ;; - percent) - cat $BAT/capacity - ;; + percent) + cat $BAT/capacity + ;; - *) - ;; - esac - else - case "$arg" in - status) - acpi | cut -d: -f2- | cut -d, -f1 | tr -d ' ' - ;; - percent) - acpi | cut -d: -f2- | cut -d, -f2 | tr -d '% ' - ;; - *) - ;; - esac - fi + *) + ;; + esac + else + case "$arg" in + status) + acpi | cut -d: -f2- | cut -d, -f1 | tr -d ' ' + ;; + percent) + acpi | cut -d: -f2- | cut -d, -f2 | tr -d '% ' + ;; + *) + ;; + esac + fi } battery_percent() { - # Check OS - case $(uname -s) in - Linux) - percent=$(linux_acpi percent) - [ -n "$percent" ] && echo " $percent" - ;; + # Check OS + case $(uname -s) in + Linux) + percent=$(linux_acpi percent) + [ -n "$percent" ] && echo " $percent" + ;; - Darwin) - echo $(pmset -g batt | grep -Eo '[0-9]?[0-9]?[0-9]%') - ;; + Darwin) + echo $(pmset -g batt | grep -Eo '[0-9]?[0-9]?[0-9]%') + ;; - FreeBSD) - echo $(apm | sed '8,11d' | grep life | awk '{print $4}') - ;; + FreeBSD) + echo $(apm | sed '8,11d' | grep life | awk '{print $4}') + ;; - CYGWIN*|MINGW32*|MSYS*|MINGW*) - # leaving empty - TODO - windows compatability - ;; + CYGWIN*|MINGW32*|MSYS*|MINGW*) + # leaving empty - TODO - windows compatability + ;; - *) - ;; - esac + *) + ;; + esac } battery_status() { - # Check OS - case $(uname -s) in - Linux) - status=$(linux_acpi status) - ;; + # Check OS + case $(uname -s) in + Linux) + status=$(linux_acpi status) + ;; - Darwin) - status=$(pmset -g batt | sed -n 2p | cut -d ';' -f 2 | tr -d " ") - ;; + Darwin) + status=$(pmset -g batt | sed -n 2p | cut -d ';' -f 2 | tr -d " ") + ;; - FreeBSD) - status=$(apm | sed '8,11d' | grep Status | awk '{printf $3}') - ;; + FreeBSD) + status=$(apm | sed '8,11d' | grep Status | awk '{printf $3}') + ;; - CYGWIN*|MINGW32*|MSYS*|MINGW*) - # leaving empty - TODO - windows compatability - ;; + CYGWIN*|MINGW32*|MSYS*|MINGW*) + # leaving empty - TODO - windows compatability + ;; - *) - ;; - esac + *) + ;; + esac - case $status in - discharging|Discharging) - echo '' - ;; - high) - echo '' - ;; - charging) - echo 'AC' - ;; - *) - echo 'AC' - ;; - esac - ### Old if statements didn't work on BSD, they're probably not POSIX compliant, not sure - # if [ $status = 'discharging' ] || [ $status = 'Discharging' ]; then - # echo '' - # # elif [ $status = 'charging' ]; then # This is needed for FreeBSD AC checking support - # # echo 'AC' - # else - # echo 'AC' - # fi + case $status in + discharging|Discharging) + echo '' + ;; + high) + echo '' + ;; + charging) + echo 'AC' + ;; + *) + echo 'AC' + ;; + esac + ### Old if statements didn't work on BSD, they're probably not POSIX compliant, not sure + # if [ $status = 'discharging' ] || [ $status = 'Discharging' ]; then + # echo '' + # # elif [ $status = 'charging' ]; then # This is needed for FreeBSD AC checking support + # # echo 'AC' + # else + # echo 'AC' + # fi } main() { - bat_stat=$(battery_status) - bat_perc=$(battery_percent) + bat_stat=$(battery_status) + bat_perc=$(battery_percent) - if [ -z "$bat_stat" ]; then # Test if status is empty or not - echo "♥ $bat_perc" - elif [ -z "$bat_perc" ]; then # In case it is a desktop with no battery percent, only AC power - echo "♥ $bat_stat" - else - echo "♥ $bat_stat $bat_perc" - fi + if [ -z "$bat_stat" ]; then # Test if status is empty or not + echo "♥ $bat_perc" + elif [ -z "$bat_perc" ]; then # In case it is a desktop with no battery percent, only AC power + echo "♥ $bat_stat" + else + echo "♥ $bat_stat $bat_perc" + fi } #run main driver program diff --git a/scripts/cpu_info.sh b/scripts/cpu_info.sh index 6a5cec1..675b234 100755 --- a/scripts/cpu_info.sh +++ b/scripts/cpu_info.sh @@ -14,47 +14,47 @@ get_tmux_option() { fi } -# normalize the percentage string to always have a length of 5 +# normalize the percentage string to always have a length of 5 normalize_percent_len() { - # the max length that the percent can reach, which happens for a two digit number with a decimal house: "99.9%" - max_len=5 - percent_len=${#1} - let diff_len=$max_len-$percent_len - # if the diff_len is even, left will have 1 more space than right - let left_spaces=($diff_len+1)/2 - let right_spaces=($diff_len)/2 - printf "%${left_spaces}s%s%${right_spaces}s\n" "" $1 "" + # the max length that the percent can reach, which happens for a two digit number with a decimal house: "99.9%" + max_len=5 + percent_len=${#1} + let diff_len=$max_len-$percent_len + # if the diff_len is even, left will have 1 more space than right + let left_spaces=($diff_len+1)/2 + let right_spaces=($diff_len)/2 + printf "%${left_spaces}s%s%${right_spaces}s\n" "" $1 "" } get_percent() { - case $(uname -s) in - Linux) - percent=$(LC_NUMERIC=en_US.UTF-8 top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1"%"}') - normalize_percent_len $percent - ;; - - Darwin) - cpuvalue=$(ps -A -o %cpu | awk -F. '{s+=$1} END {print s}') - cpucores=$(sysctl -n hw.logicalcpu) - cpuusage=$(( cpuvalue / cpucores )) - percent="$cpuusage%" - normalize_percent_len $percent - ;; + case $(uname -s) in + Linux) + percent=$(LC_NUMERIC=en_US.UTF-8 top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1"%"}') + normalize_percent_len $percent + ;; - CYGWIN*|MINGW32*|MSYS*|MINGW*) - # TODO - windows compatability - ;; - esac + Darwin) + cpuvalue=$(ps -A -o %cpu | awk -F. '{s+=$1} END {print s}') + cpucores=$(sysctl -n hw.logicalcpu) + cpuusage=$(( cpuvalue / cpucores )) + percent="$cpuusage%" + normalize_percent_len $percent + ;; + + CYGWIN*|MINGW32*|MSYS*|MINGW*) + # TODO - windows compatability + ;; + esac } main() { - # storing the refresh rate in the variable RATE, default is 5 - RATE=$(get_tmux_option "@dracula-refresh-rate" 5) - cpu_percent=$(get_percent) - echo "CPU $cpu_percent" - sleep $RATE + # storing the refresh rate in the variable RATE, default is 5 + RATE=$(get_tmux_option "@dracula-refresh-rate" 5) + cpu_percent=$(get_percent) + echo "CPU $cpu_percent" + sleep $RATE } # run main driver diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 91033c0..7729800 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -59,27 +59,27 @@ main() # Handle left icon configuration case $show_left_icon in - smiley) - left_icon="☺";; - session) - left_icon="#S";; - window) - left_icon="#W";; - *) - left_icon=$show_left_icon;; + smiley) + left_icon="☺";; + session) + left_icon="#S";; + window) + left_icon="#W";; + *) + left_icon=$show_left_icon;; esac # Handle left icon padding padding="" if [ "$show_left_icon_padding" -gt "0" ]; then - padding="$(printf '%*s' $show_left_icon_padding)" + padding="$(printf '%*s' $show_left_icon_padding)" fi left_icon="$left_icon$padding" # Handle powerline option if $show_powerline; then - right_sep="$show_right_sep" - left_sep="$show_left_sep" + right_sep="$show_right_sep" + left_sep="$show_left_sep" fi # start weather script in background @@ -89,10 +89,10 @@ main() # Set timezone unless hidden by configuration case $show_timezone in - false) - timezone="";; - true) - timezone="#(date +%Z)";; + false) + timezone="";; + true) + timezone="#(date +%Z)";; esac case $show_flags in @@ -109,14 +109,14 @@ main() # set the prefix + t time format if $show_military; then - tmux set-option -g clock-mode-style 24 + tmux set-option -g clock-mode-style 24 else - tmux set-option -g clock-mode-style 12 + tmux set-option -g clock-mode-style 12 fi # set length tmux set-option -g status-left-length 100 - tmux set-option -g status-right-length 100 + tmux set-option -g status-right-length 100 # pane border styling if $show_border_contrast; then @@ -135,113 +135,113 @@ main() # wait unit $datafile exists just to avoid errors # this should almost never need to wait unless something unexpected occurs while $show_weather && [ ! -f $datafile ]; do - sleep 0.01 + sleep 0.01 done # Powerline Configuration if $show_powerline; then - tmux set-option -g status-left "#[bg=${green},fg=${dark_gray}]#{?client_prefix,#[bg=${yellow}],} ${left_icon} #[fg=${green},bg=${gray}]#{?client_prefix,#[fg=${yellow}],}${left_sep}" - tmux set-option -g status-right "" - powerbg=${gray} + tmux set-option -g status-left "#[bg=${green},fg=${dark_gray}]#{?client_prefix,#[bg=${yellow}],} ${left_icon} #[fg=${green},bg=${gray}]#{?client_prefix,#[fg=${yellow}],}${left_sep}" + tmux set-option -g status-right "" + powerbg=${gray} - if $show_battery; then # battery - tmux set-option -g status-right "#[fg=${pink},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${pink}] #($current_dir/battery.sh)" - powerbg=${pink} + if $show_battery; then # battery + tmux set-option -g status-right "#[fg=${pink},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${pink}] #($current_dir/battery.sh)" + powerbg=${pink} + fi + + if $show_ram_usage; then + tmux set-option -ga status-right "#[fg=${cyan},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${cyan}] #($current_dir/ram_info.sh)" + powerbg=${cyan} + fi + + if $show_cpu_usage; then + tmux set-option -ga status-right "#[fg=${orange},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${orange}] #($current_dir/cpu_info.sh)" + powerbg=${orange} + fi + + if $show_gpu_usage; then + tmux set-option -ga status-right "#[fg=${pink},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${pink}] #($current_dir/gpu_usage.sh)" + powerbg=${pink} + fi + + if $show_network; then # network + tmux set-option -ga status-right "#[fg=${cyan},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${cyan}] #($current_dir/network.sh)" + powerbg=${cyan} + fi + + if [[ "$show_network_bandwith" != "" ]]; then # network bandwith + tmux set-option -g status-right-length 250 + tmux set-option -ga status-right "#[fg=${green},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${green}] #($current_dir/network_bandwith.sh)" + powerbg=${green} + fi + + if $show_weather; then # weather + tmux set-option -ga status-right "#[fg=${orange},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${orange}] #(cat $datafile)" + powerbg=${orange} + fi + + if $show_time; then + if $show_day_month && $show_military ; then # military time and dd/mm + tmux set-option -ga status-right "#[fg=${dark_purple},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${white},bg=${dark_purple}] %a %d/%m %R ${timezone} " + elif $show_military; then # only military time + tmux set-option -ga status-right "#[fg=${dark_purple},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${white},bg=${dark_purple}] %a %m/%d %R ${timezone} " + elif $show_day_month; then # only dd/mm + tmux set-option -ga status-right "#[fg=${dark_purple},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${white},bg=${dark_purple}] %a %d/%m %I:%M %p ${timezone} " + else + tmux set-option -ga status-right "#[fg=${dark_purple},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${white},bg=${dark_purple}] %a %m/%d %I:%M %p ${timezone} " fi + fi - if $show_ram_usage; then - tmux set-option -ga status-right "#[fg=${cyan},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${cyan}] #($current_dir/ram_info.sh)" - powerbg=${cyan} - fi - - if $show_cpu_usage; then - tmux set-option -ga status-right "#[fg=${orange},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${orange}] #($current_dir/cpu_info.sh)" - powerbg=${orange} - fi - - if $show_gpu_usage; then - tmux set-option -ga status-right "#[fg=${pink},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${pink}] #($current_dir/gpu_usage.sh)" - powerbg=${pink} - fi - - if $show_network; then # network - tmux set-option -ga status-right "#[fg=${cyan},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${cyan}] #($current_dir/network.sh)" - powerbg=${cyan} - fi - - if [[ "$show_network_bandwith" != "" ]]; then # network bandwith - tmux set-option -g status-right-length 250 - tmux set-option -ga status-right "#[fg=${green},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${green}] #($current_dir/network_bandwith.sh)" - powerbg=${green} - fi - - if $show_weather; then # weather - tmux set-option -ga status-right "#[fg=${orange},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${orange}] #(cat $datafile)" - powerbg=${orange} - fi - - if $show_time; then - if $show_day_month && $show_military ; then # military time and dd/mm - tmux set-option -ga status-right "#[fg=${dark_purple},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${white},bg=${dark_purple}] %a %d/%m %R ${timezone} " - elif $show_military; then # only military time - tmux set-option -ga status-right "#[fg=${dark_purple},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${white},bg=${dark_purple}] %a %m/%d %R ${timezone} " - elif $show_day_month; then # only dd/mm - tmux set-option -ga status-right "#[fg=${dark_purple},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${white},bg=${dark_purple}] %a %d/%m %I:%M %p ${timezone} " - else - tmux set-option -ga status-right "#[fg=${dark_purple},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${white},bg=${dark_purple}] %a %m/%d %I:%M %p ${timezone} " - fi - fi - - tmux set-window-option -g window-status-current-format "#[fg=${gray},bg=${dark_purple}]${left_sep}#[fg=${white},bg=${dark_purple}] #I #W${current_flags} #[fg=${dark_purple},bg=${gray}]${left_sep}" + tmux set-window-option -g window-status-current-format "#[fg=${gray},bg=${dark_purple}]${left_sep}#[fg=${white},bg=${dark_purple}] #I #W${current_flags} #[fg=${dark_purple},bg=${gray}]${left_sep}" # Non Powerline Configuration - else - tmux set-option -g status-left "#[bg=${green},fg=${dark_gray}]#{?client_prefix,#[bg=${yellow}],} ${left_icon}" +else + tmux set-option -g status-left "#[bg=${green},fg=${dark_gray}]#{?client_prefix,#[bg=${yellow}],} ${left_icon}" - tmux set-option -g status-right "" + tmux set-option -g status-right "" - if $show_battery; then # battery - tmux set-option -g status-right "#[fg=${dark_gray},bg=${pink}] #($current_dir/battery.sh) " - fi - if $show_ram_usage; then - tmux set-option -ga status-right "#[fg=${dark_gray},bg=${cyan}] #($current_dir/ram_info.sh) " - fi + if $show_battery; then # battery + tmux set-option -g status-right "#[fg=${dark_gray},bg=${pink}] #($current_dir/battery.sh) " + fi + if $show_ram_usage; then + tmux set-option -ga status-right "#[fg=${dark_gray},bg=${cyan}] #($current_dir/ram_info.sh) " + fi - if $show_cpu_usage; then - tmux set-option -ga status-right "#[fg=${dark_gray},bg=${orange}] #($current_dir/cpu_info.sh) " - fi + if $show_cpu_usage; then + tmux set-option -ga status-right "#[fg=${dark_gray},bg=${orange}] #($current_dir/cpu_info.sh) " + fi - if $show_gpu_usage; then - tmux set-option -ga status-right "#[fg=${dark_gray},bg=${pink}] #($current_dir/gpu_usage.sh) " - fi + if $show_gpu_usage; then + tmux set-option -ga status-right "#[fg=${dark_gray},bg=${pink}] #($current_dir/gpu_usage.sh) " + fi - if $show_network; then # network - tmux set-option -ga status-right "#[fg=${dark_gray},bg=${cyan}] #($current_dir/network.sh) " - fi + if $show_network; then # network + tmux set-option -ga status-right "#[fg=${dark_gray},bg=${cyan}] #($current_dir/network.sh) " + fi - if [[ "$show_network_bandwith" != "" ]]; then # network bandwith - tmux set-option -g status-right-length 250 - tmux set-option -ga status-right "#[fg=${dark_gray},bg=${green}] #($current_dir/network_bandwith.sh) " - fi + if [[ "$show_network_bandwith" != "" ]]; then # network bandwith + tmux set-option -g status-right-length 250 + tmux set-option -ga status-right "#[fg=${dark_gray},bg=${green}] #($current_dir/network_bandwith.sh) " + fi - if $show_weather; then # weather - tmux set-option -ga status-right "#[fg=${dark_gray},bg=${orange}] #(cat $datafile) " - fi + if $show_weather; then # weather + tmux set-option -ga status-right "#[fg=${dark_gray},bg=${orange}] #(cat $datafile) " + fi - if $show_time; then - if $show_day_month && $show_military ; then # military time and dd/mm - tmux set-option -ga status-right "#[fg=${white},bg=${dark_purple}] %a %d/%m %R ${timezone} " - elif $show_military; then # only military time - tmux set-option -ga status-right "#[fg=${white},bg=${dark_purple}] %a %m/%d %R ${timezone} " - elif $show_day_month; then # only dd/mm - tmux set-option -ga status-right "#[fg=${white},bg=${dark_purple}] %a %d/%m %I:%M %p ${timezone} " - else - tmux set-option -ga status-right "#[fg=${white},bg=${dark_purple}] %a %m/%d %I:%M %p ${timezone} " - fi - fi + if $show_time; then + if $show_day_month && $show_military ; then # military time and dd/mm + tmux set-option -ga status-right "#[fg=${white},bg=${dark_purple}] %a %d/%m %R ${timezone} " + elif $show_military; then # only military time + tmux set-option -ga status-right "#[fg=${white},bg=${dark_purple}] %a %m/%d %R ${timezone} " + elif $show_day_month; then # only dd/mm + tmux set-option -ga status-right "#[fg=${white},bg=${dark_purple}] %a %d/%m %I:%M %p ${timezone} " + else + tmux set-option -ga status-right "#[fg=${white},bg=${dark_purple}] %a %m/%d %I:%M %p ${timezone} " + fi + fi - tmux set-window-option -g window-status-current-format "#[fg=${white},bg=${dark_purple}] #I #W${current_flags} " + tmux set-window-option -g window-status-current-format "#[fg=${white},bg=${dark_purple}] #I #W${current_flags} " fi diff --git a/scripts/gpu_usage.sh b/scripts/gpu_usage.sh index d9685c8..fe69814 100755 --- a/scripts/gpu_usage.sh +++ b/scripts/gpu_usage.sh @@ -16,38 +16,38 @@ get_tmux_option() { get_platform() { - case $(uname -s) in - Linux) - gpu=$(lspci -v | grep VGA | head -n 1 | awk '{print $5}') - echo $gpu - ;; + case $(uname -s) in + Linux) + gpu=$(lspci -v | grep VGA | head -n 1 | awk '{print $5}') + echo $gpu + ;; - Darwin) - # TODO - Darwin/Mac compatability - ;; + Darwin) + # TODO - Darwin/Mac compatability + ;; - CYGWIN*|MINGW32*|MSYS*|MINGW*) - # TODO - windows compatability - ;; - esac + CYGWIN*|MINGW32*|MSYS*|MINGW*) + # TODO - windows compatability + ;; + esac } get_gpu() { - gpu=$(get_platform) - if [[ "$gpu" == NVIDIA ]]; then + gpu=$(get_platform) + if [[ "$gpu" == NVIDIA ]]; then usage=$(nvidia-smi | grep '%' | awk '{ sum += $13 } END { printf("%d%%\n", sum / NR) }') else usage='unknown' - fi + fi echo $usage } main() { - # storing the refresh rate in the variable RATE, default is 5 - RATE=$(get_tmux_option "@dracula-refresh-rate" 5) - gpu_usage=$(get_gpu) - echo "GPU $gpu_usage" - sleep $RATE + # storing the refresh rate in the variable RATE, default is 5 + RATE=$(get_tmux_option "@dracula-refresh-rate" 5) + gpu_usage=$(get_gpu) + echo "GPU $gpu_usage" + sleep $RATE } # run the main driver main diff --git a/scripts/network.sh b/scripts/network.sh index bd7f84e..d2aa88b 100755 --- a/scripts/network.sh +++ b/scripts/network.sh @@ -6,46 +6,46 @@ HOSTS="google.com github.com example.com" get_ssid() { - # Check OS - case $(uname -s) in - Linux) - SSID=$(iw dev | sed -nr 's/^\t\tssid (.*)/\1/p') - if [ -n "$SSID" ]; then - printf '%s' "$SSID" - else - echo 'Ethernet' - fi - ;; + # Check OS + case $(uname -s) in + Linux) + SSID=$(iw dev | sed -nr 's/^\t\tssid (.*)/\1/p') + if [ -n "$SSID" ]; then + printf '%s' "$SSID" + else + echo 'Ethernet' + fi + ;; - Darwin) - if /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | grep -E ' SSID' | cut -d ':' -f 2 | sed 's/ ^*//g' &> /dev/null; then - echo "$(/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | grep -E ' SSID' | cut -d ':' -f 2)" | sed 's/ ^*//g' - else - echo 'Ethernet' - fi - ;; + Darwin) + if /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | grep -E ' SSID' | cut -d ':' -f 2 | sed 's/ ^*//g' &> /dev/null; then + echo "$(/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | grep -E ' SSID' | cut -d ':' -f 2)" | sed 's/ ^*//g' + else + echo 'Ethernet' + fi + ;; - CYGWIN*|MINGW32*|MSYS*|MINGW*) - # leaving empty - TODO - windows compatability - ;; + CYGWIN*|MINGW32*|MSYS*|MINGW*) + # leaving empty - TODO - windows compatability + ;; - *) - ;; - esac + *) + ;; + esac } main() { - network="Offline" - for host in $HOSTS; do - if ping -q -c 1 -W 1 $host &>/dev/null; then - network="$(get_ssid)" - break - fi - done + network="Offline" + for host in $HOSTS; do + if ping -q -c 1 -W 1 $host &>/dev/null; then + network="$(get_ssid)" + break + fi + done - echo "$network" + echo "$network" } #run main driver function diff --git a/scripts/network_bandwith.sh b/scripts/network_bandwith.sh index 213ef26..675f39b 100755 --- a/scripts/network_bandwith.sh +++ b/scripts/network_bandwith.sh @@ -6,22 +6,22 @@ network_name=$(tmux show-option -gqv "@dracula-network-bandwith") main() { while true - do - initial_download=$(cat /sys/class/net/$network_name/statistics/rx_bytes) - initial_upload=$(cat /sys/class/net/$network_name/statistics/tx_bytes) - - sleep $INTERVAL - - final_download=$(cat /sys/class/net/$network_name/statistics/rx_bytes) - final_upload=$(cat /sys/class/net/$network_name/statistics/tx_bytes) + do + initial_download=$(cat /sys/class/net/$network_name/statistics/rx_bytes) + initial_upload=$(cat /sys/class/net/$network_name/statistics/tx_bytes) - total_download_bps=$(expr $final_download - $initial_download) - total_upload_bps=$(expr $final_upload - $initial_upload) + sleep $INTERVAL - total_download_kbps=$(echo "scale=2; $total_download_bps / 1024" | bc) - total_upload_kbps=$(echo "scale=2; $total_upload_bps / 1024" | bc) + final_download=$(cat /sys/class/net/$network_name/statistics/rx_bytes) + final_upload=$(cat /sys/class/net/$network_name/statistics/tx_bytes) - echo "↓ $total_download_kbps kB/s • ↑ $total_upload_kbps kB/s" - done + total_download_bps=$(expr $final_download - $initial_download) + total_upload_bps=$(expr $final_upload - $initial_upload) + + total_download_kbps=$(echo "scale=2; $total_download_bps / 1024" | bc) + total_upload_kbps=$(echo "scale=2; $total_upload_bps / 1024" | bc) + + echo "↓ $total_download_kbps kB/s • ↑ $total_upload_kbps kB/s" + done } main diff --git a/scripts/ram_info.sh b/scripts/ram_info.sh index f0f7bff..5489912 100755 --- a/scripts/ram_info.sh +++ b/scripts/ram_info.sh @@ -16,70 +16,70 @@ get_tmux_option() { get_percent() { - case $(uname -s) in - Linux) - # percent=$(free -m | awk 'NR==2{printf "%.1f%%\n", $3*100/$2}') - total_mem_gb=$(free -g | awk '/^Mem/ {print $2}') - used_mem=$(free -g | awk '/^Mem/ {print $3}') - total_mem=$(free -h | awk '/^Mem/ {print $2}') - if (( $total_mem_gb == 0)); then - memory_usage=$(free -m | awk '/^Mem/ {print $3}') - total_mem_mb=$(free -m | awk '/^Mem/ {print $2}') - echo $memory_usage\M\B/$total_mem_mb\M\B - elif (( $used_mem == 0 )); then - memory_usage=$(free -m | awk '/^Mem/ {print $3}') - echo $memory_usage\M\B/$total_mem\G\B - else - memory_usage=$(free -g | awk '/^Mem/ {print $3}') - echo $memory_usage\G\B/$total_mem\G\B - fi - ;; + case $(uname -s) in + Linux) + # percent=$(free -m | awk 'NR==2{printf "%.1f%%\n", $3*100/$2}') + total_mem_gb=$(free -g | awk '/^Mem/ {print $2}') + used_mem=$(free -g | awk '/^Mem/ {print $3}') + total_mem=$(free -h | awk '/^Mem/ {print $2}') + if (( $total_mem_gb == 0)); then + memory_usage=$(free -m | awk '/^Mem/ {print $3}') + total_mem_mb=$(free -m | awk '/^Mem/ {print $2}') + echo $memory_usage\M\B/$total_mem_mb\M\B + elif (( $used_mem == 0 )); then + memory_usage=$(free -m | awk '/^Mem/ {print $3}') + echo $memory_usage\M\B/$total_mem\G\B + else + memory_usage=$(free -g | awk '/^Mem/ {print $3}') + echo $memory_usage\G\B/$total_mem\G\B + fi + ;; - Darwin) - # percent=$(ps -A -o %mem | awk '{mem += $1} END {print mem}') - # Get used memory blocks with vm_stat, multiply by 4096 to get size in bytes, then convert to MiB - used_mem=$(vm_stat | grep ' active\|wired ' | sed 's/[^0-9]//g' | paste -sd ' ' - | awk '{printf "%d\n", ($1+$2) * 4096 / 1048576}') - total_mem=$(system_profiler SPHardwareDataType | grep "Memory:" | awk '{print $2 $3}') - if (( $used_mem < 1024 )); then - echo $used_mem\M\B/$total_mem - else - memory=$(($used_mem/1024)) - echo $memory\G\B/$total_mem - fi - ;; - - FreeBSD) - # Looked at the code from neofetch - hw_pagesize="$(sysctl -n hw.pagesize)" - mem_inactive="$(($(sysctl -n vm.stats.vm.v_inactive_count) * hw_pagesize))" - mem_unused="$(($(sysctl -n vm.stats.vm.v_free_count) * hw_pagesize))" - mem_cache="$(($(sysctl -n vm.stats.vm.v_cache_count) * hw_pagesize))" + Darwin) + # percent=$(ps -A -o %mem | awk '{mem += $1} END {print mem}') + # Get used memory blocks with vm_stat, multiply by 4096 to get size in bytes, then convert to MiB + used_mem=$(vm_stat | grep ' active\|wired ' | sed 's/[^0-9]//g' | paste -sd ' ' - | awk '{printf "%d\n", ($1+$2) * 4096 / 1048576}') + total_mem=$(system_profiler SPHardwareDataType | grep "Memory:" | awk '{print $2 $3}') + if (( $used_mem < 1024 )); then + echo $used_mem\M\B/$total_mem + else + memory=$(($used_mem/1024)) + echo $memory\G\B/$total_mem + fi + ;; - free_mem=$(((mem_inactive + mem_unused + mem_cache) / 1024 / 1024)) - total_mem=$(($(sysctl -n hw.physmem) / 1024 / 1024)) - used_mem=$((total_mem - free_mem)) - echo $used_mem - if (( $used_mem < 1024 )); then - echo $used_mem\M\B/$total_mem - else - memory=$(($used_mem/1024)) - echo $memory\G\B/$total_mem - fi - ;; + FreeBSD) + # Looked at the code from neofetch + hw_pagesize="$(sysctl -n hw.pagesize)" + mem_inactive="$(($(sysctl -n vm.stats.vm.v_inactive_count) * hw_pagesize))" + mem_unused="$(($(sysctl -n vm.stats.vm.v_free_count) * hw_pagesize))" + mem_cache="$(($(sysctl -n vm.stats.vm.v_cache_count) * hw_pagesize))" - CYGWIN*|MINGW32*|MSYS*|MINGW*) - # TODO - windows compatability - ;; - esac + free_mem=$(((mem_inactive + mem_unused + mem_cache) / 1024 / 1024)) + total_mem=$(($(sysctl -n hw.physmem) / 1024 / 1024)) + used_mem=$((total_mem - free_mem)) + echo $used_mem + if (( $used_mem < 1024 )); then + echo $used_mem\M\B/$total_mem + else + memory=$(($used_mem/1024)) + echo $memory\G\B/$total_mem + fi + ;; + + CYGWIN*|MINGW32*|MSYS*|MINGW*) + # TODO - windows compatability + ;; + esac } main() { - # storing the refresh rate in the variable RATE, default is 5 - RATE=$(get_tmux_option "@dracula-refresh-rate" 5) - ram_percent=$(get_percent) - echo "RAM $ram_percent" - sleep $RATE + # storing the refresh rate in the variable RATE, default is 5 + RATE=$(get_tmux_option "@dracula-refresh-rate" 5) + ram_percent=$(get_percent) + echo "RAM $ram_percent" + sleep $RATE } #run main driver diff --git a/scripts/sleep_weather.sh b/scripts/sleep_weather.sh index 621ff8d..276c25c 100755 --- a/scripts/sleep_weather.sh +++ b/scripts/sleep_weather.sh @@ -12,35 +12,35 @@ DATAFILE=/tmp/.dracula-tmux-data ensure_single_process() { - # check for another running instance of this script and terminate it if found - [ -f $LOCKFILE ] && ps -p "$(cat $LOCKFILE)" -o cmd= | grep -F " ${BASH_SOURCE[0]}" && kill "$(cat $LOCKFILE)" - echo $$ > $LOCKFILE + # check for another running instance of this script and terminate it if found + [ -f $LOCKFILE ] && ps -p "$(cat $LOCKFILE)" -o cmd= | grep -F " ${BASH_SOURCE[0]}" && kill "$(cat $LOCKFILE)" + echo $$ > $LOCKFILE } main() { - ensure_single_process + ensure_single_process - current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - if [ ! -f $DATAFILE ]; then - printf "Loading..." > $DATAFILE - fi + if [ ! -f $DATAFILE ]; then + printf "Loading..." > $DATAFILE + fi - $current_dir/weather.sh > $DATAFILE + $current_dir/weather.sh > $DATAFILE - while tmux has-session &> /dev/null - do - $current_dir/weather.sh $fahrenheit $location > $DATAFILE - if tmux has-session &> /dev/null - then - sleep 1200 - else - break - fi - done + while tmux has-session &> /dev/null + do + $current_dir/weather.sh $fahrenheit $location > $DATAFILE + if tmux has-session &> /dev/null + then + sleep 1200 + else + break + fi + done - rm $LOCKFILE + rm $LOCKFILE } #run main driver function diff --git a/scripts/weather.sh b/scripts/weather.sh index e01b0fe..2254a69 100755 --- a/scripts/weather.sh +++ b/scripts/weather.sh @@ -7,64 +7,64 @@ location=$2 display_location() { - if $location; then - city=$(curl -s https://ipinfo.io/city 2> /dev/null) - region=$(curl -s https://ipinfo.io/region 2> /dev/null) - echo " $city, $region" - else - echo '' - fi + if $location; then + city=$(curl -s https://ipinfo.io/city 2> /dev/null) + region=$(curl -s https://ipinfo.io/region 2> /dev/null) + echo " $city, $region" + else + echo '' + fi } fetch_weather_information() { - display_weather=$1 - # it gets the weather condition textual name (%C), and the temperature (%t) - curl -sL wttr.in\?format="%C+%t$display_weather" + display_weather=$1 + # it gets the weather condition textual name (%C), and the temperature (%t) + curl -sL wttr.in\?format="%C+%t$display_weather" } #get weather display display_weather() { - if $fahrenheit; then - display_weather='&u' # for USA system - else - display_weather='&m' # for metric system - fi - weather_information=$(fetch_weather_information $display_weather) + if $fahrenheit; then + display_weather='&u' # for USA system + else + display_weather='&m' # for metric system + fi + weather_information=$(fetch_weather_information $display_weather) - weather_condition=$(echo $weather_information | rev | cut -d ' ' -f2- | rev) # Sunny, Snow, etc - temperature=$(echo $weather_information | rev | cut -d ' ' -f 1 | rev) # +31°C, -3°F, etc - unicode=$(forecast_unicode $weather_condition) + weather_condition=$(echo $weather_information | rev | cut -d ' ' -f2- | rev) # Sunny, Snow, etc + temperature=$(echo $weather_information | rev | cut -d ' ' -f 1 | rev) # +31°C, -3°F, etc + unicode=$(forecast_unicode $weather_condition) - echo "$unicode${temperature/+/}" # remove the plus sign to the temperature + echo "$unicode${temperature/+/}" # remove the plus sign to the temperature } forecast_unicode() { - weather_condition=$(echo $weather_condition | awk '{print tolower($0)}') + weather_condition=$(echo $weather_condition | awk '{print tolower($0)}') - if [[ $weather_condition =~ 'snow' ]]; then - echo '❄ ' - elif [[ (($weather_condition =~ 'rain') || ($weather_condition =~ 'shower')) ]]; then - echo '☂ ' - elif [[ (($weather_condition =~ 'overcast') || ($weather_condition =~ 'cloud')) ]]; then - echo '☁ ' - elif [[ $weather_condition = 'NA' ]]; then - echo '' - else - echo '☀ ' - fi + if [[ $weather_condition =~ 'snow' ]]; then + echo '❄ ' + elif [[ (($weather_condition =~ 'rain') || ($weather_condition =~ 'shower')) ]]; then + echo '☂ ' + elif [[ (($weather_condition =~ 'overcast') || ($weather_condition =~ 'cloud')) ]]; then + echo '☁ ' + elif [[ $weather_condition = 'NA' ]]; then + echo '' + else + echo '☀ ' + fi } main() { - # process should be cancelled when session is killed - if ping -q -c 1 -W 1 ipinfo.io &>/dev/null; then - echo "$(display_weather)$(display_location)" - else - echo "Location Unavailable" - fi + # process should be cancelled when session is killed + if ping -q -c 1 -W 1 ipinfo.io &>/dev/null; then + echo "$(display_weather)$(display_location)" + else + echo "Location Unavailable" + fi } #run main driver program From 151cd3e45fd6660fe3d373b7ecd66c71fdafd2c7 Mon Sep 17 00:00:00 2001 From: Sabato Luca Guadagno Date: Tue, 6 Jul 2021 10:29:37 +0200 Subject: [PATCH 2/8] resolve #106, Bug: GiGB in RAM usage (Ubuntu) --- scripts/ram_info.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/ram_info.sh b/scripts/ram_info.sh index 5489912..f7ed9b6 100755 --- a/scripts/ram_info.sh +++ b/scripts/ram_info.sh @@ -28,10 +28,10 @@ get_percent() echo $memory_usage\M\B/$total_mem_mb\M\B elif (( $used_mem == 0 )); then memory_usage=$(free -m | awk '/^Mem/ {print $3}') - echo $memory_usage\M\B/$total_mem\G\B + echo $memory_usage\M\B/$total_mem_gb\G\B else memory_usage=$(free -g | awk '/^Mem/ {print $3}') - echo $memory_usage\G\B/$total_mem\G\B + echo $memory_usage\G\B/$total_mem_gb\G\B fi ;; From 87df275c6e669cd861f4e566f0d089b8f88393a8 Mon Sep 17 00:00:00 2001 From: Sabato Luca Guadagno Date: Tue, 6 Jul 2021 11:21:21 +0200 Subject: [PATCH 3/8] get_tmux_option(), normalize_percent_len() in scripts/utils.sh source scripts/utils.sh in dracula.sh, cpu_info.sh, gpu_usage.sh, ram_info.sh normalize_percent_len for ram_info custom labels for cpu-usage, gpu-usage, ram-usage --- scripts/cpu_info.sh | 29 +++++------------------------ scripts/dracula.sh | 12 ++---------- scripts/gpu_usage.sh | 21 ++++++++------------- scripts/ram_info.sh | 3 ++- scripts/utils.sh | 25 +++++++++++++++++++++++++ 5 files changed, 42 insertions(+), 48 deletions(-) create mode 100644 scripts/utils.sh diff --git a/scripts/cpu_info.sh b/scripts/cpu_info.sh index 675b234..b66ee8c 100755 --- a/scripts/cpu_info.sh +++ b/scripts/cpu_info.sh @@ -2,29 +2,8 @@ # setting the locale, some users have issues with different locales, this forces the correct one export LC_ALL=en_US.UTF-8 -# function for getting the refresh rate -get_tmux_option() { - local option=$1 - local default_value=$2 - local option_value=$(tmux show-option -gqv "$option") - if [ -z $option_value ]; then - echo $default_value - else - echo $option_value - fi -} - -# normalize the percentage string to always have a length of 5 -normalize_percent_len() { - # the max length that the percent can reach, which happens for a two digit number with a decimal house: "99.9%" - max_len=5 - percent_len=${#1} - let diff_len=$max_len-$percent_len - # if the diff_len is even, left will have 1 more space than right - let left_spaces=($diff_len+1)/2 - let right_spaces=($diff_len)/2 - printf "%${left_spaces}s%s%${right_spaces}s\n" "" $1 "" -} +current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +source $current_dir/utils.sh get_percent() { @@ -52,8 +31,10 @@ main() { # storing the refresh rate in the variable RATE, default is 5 RATE=$(get_tmux_option "@dracula-refresh-rate" 5) + cpu_label=$(get_tmux_option "@dracula-cpu-usage-label" "CPU") cpu_percent=$(get_percent) - echo "CPU $cpu_percent" + echo "$cpu_label $cpu_percent" + # echo "$current_dir" sleep $RATE } diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 7729800..8156c1c 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -2,16 +2,8 @@ # setting the locale, some users have issues with different locales, this forces the correct one export LC_ALL=en_US.UTF-8 -get_tmux_option() { - local option=$1 - local default_value=$2 - local option_value=$(tmux show-option -gqv "$option") - if [ -z $option_value ]; then - echo $default_value - else - echo $option_value - fi -} +current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +source $current_dir/utils.sh main() { diff --git a/scripts/gpu_usage.sh b/scripts/gpu_usage.sh index fe69814..9ffc647 100755 --- a/scripts/gpu_usage.sh +++ b/scripts/gpu_usage.sh @@ -2,17 +2,8 @@ # setting the locale, some users have issues with different locales, this forces the correct one export LC_ALL=en_US.UTF-8 -# function for getting the refresh rate -get_tmux_option() { - local option=$1 - local default_value=$2 - local option_value=$(tmux show-option -gqv "$option") - if [ -z $option_value ]; then - echo $default_value - else - echo $option_value - fi -} +current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +source $current_dir/utils.sh get_platform() { @@ -31,6 +22,7 @@ get_platform() ;; esac } + get_gpu() { gpu=$(get_platform) @@ -39,15 +31,18 @@ get_gpu() else usage='unknown' fi - echo $usage + normalize_percent_len $usage } + main() { # storing the refresh rate in the variable RATE, default is 5 RATE=$(get_tmux_option "@dracula-refresh-rate" 5) + gpu_label=$(get_tmux_option "@dracula-gpu-usage-label" "GPU") gpu_usage=$(get_gpu) - echo "GPU $gpu_usage" + echo "$gpu_label $gpu_usage" sleep $RATE } + # run the main driver main diff --git a/scripts/ram_info.sh b/scripts/ram_info.sh index f7ed9b6..625ad61 100755 --- a/scripts/ram_info.sh +++ b/scripts/ram_info.sh @@ -77,8 +77,9 @@ main() { # storing the refresh rate in the variable RATE, default is 5 RATE=$(get_tmux_option "@dracula-refresh-rate" 5) + ram_label=$(get_tmux_option "@dracula-ram-usage-label" "RAM") ram_percent=$(get_percent) - echo "RAM $ram_percent" + echo "$ram_label $ram_percent" sleep $RATE } diff --git a/scripts/utils.sh b/scripts/utils.sh new file mode 100644 index 0000000..33a47d0 --- /dev/null +++ b/scripts/utils.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +get_tmux_option() { + local option=$1 + local default_value=$2 + local option_value=$(tmux show-option -gqv "$option") + if [ -z $option_value ]; then + echo $default_value + else + echo $option_value + fi +} + +# normalize the percentage string to always have a length of 5 +normalize_percent_len() { + # the max length that the percent can reach, which happens for a two digit number with a decimal house: "99.9%" + max_len=5 + percent_len=${#1} + let diff_len=$max_len-$percent_len + # if the diff_len is even, left will have 1 more space than right + let left_spaces=($diff_len+1)/2 + let right_spaces=($diff_len)/2 + printf "%${left_spaces}s%s%${right_spaces}s\n" "" $1 "" +} + From 4abfcf279949b6c301d3c853a204fe01dbe8c587 Mon Sep 17 00:00:00 2001 From: Sabato Luca Guadagno Date: Tue, 6 Jul 2021 13:28:34 +0200 Subject: [PATCH 4/8] resolve #42, Enhancement: Make status bar modules / color more configurable --- INSTALL.md | 143 +++++++++++++++++++++++++++++++++++++-------- scripts/dracula.sh | 134 +++++++++++++++--------------------------- 2 files changed, 168 insertions(+), 109 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 57a768d..d093252 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -4,7 +4,7 @@ If you are a tpm user, you can install the theme and keep up to date by adding the following to your .tmux.conf file: - set -g @plugin 'dracula/tmux' + set -g @plugin 'dracula/tmux' Add any configuration options below this line in your tmux config. @@ -44,25 +44,122 @@ programs.tmux = { #### Configuration -Customize the status bar by adding any of these lines to your .tmux.conf as desired: -* Disable battery functionality: `set -g @dracula-show-battery false` -* Disable network functionality: `set -g @dracula-show-network false` -* Enable network bandwith functionality: `set -g @dracula-network-bandwith $network_name` - - You could get the `$network_name` through the command: `sudo lshw -class network -short | grep wl | awk '{print $2}'` -* Disable weather functionality: `set -g @dracula-show-weather false` -* Disable time functionality: `set -g @dracula-show-time false` -* Disable location information: `set -g @dracula-show-location false` -* Switch from default fahrenheit to celsius: `set -g @dracula-show-fahrenheit false` -* Enable powerline symbols: `set -g @dracula-show-powerline true` -* Switch powerline symbols `set -g @dracula-show-left-sep ` for left and `set -g @dracula-show-right-sep ` for right symbol (can set any symbol you like as seperator) -* Enable window flags: `set -g @dracula-show-flags true` -* Adjust the refresh rate for the bar `set -g @dracula-refresh-rate 5` the default is 5, it can accept any number -* Enable military time: `set -g @dracula-military-time true` -* Disable timezone: `set -g @dracula-show-timezone false` -* Switch the left smiley icon `set -g @dracula-show-left-icon session` it can accept `session`, `smiley`, `window`, or any character. -* Add padding to the left smiley icon `set -g @dracula-left-icon-padding` default is 1, it can accept any number and 0 disables padding. -* Enable high contrast pane border: `set -g @dracula-border-contrast true` -* Enable cpu usage: `set -g @dracula-cpu-usage true` -* Enable ram usage: `set -g @dracula-ram-usage true` -* Enable gpu usage: `set -g @dracula-gpu-usage true` -* Swap date to day/month `set -g @dracula-day-month true` +To enable plugins set up the `@dracula-plugins` option in you `.tmux.conf` file, separate plugin by space. +The order that you define the plugins will be the order on the status bar left to right. + +```bash +# available plugins: battery, cpu-usage, gpu-usage, ram-usage, network, network-bandwith, weather, time +set -g @dracula-plugins "cpu-usage gpu-usage ram-usage" +``` + +For each plugin is possible to customize background and foreground colors + +```bash +# available colors: white, gray, dark_gray, light_purple, dark_purple, cyan, green, orange, red, pink, yellow +# set -g @dracula-[plugin-name]-colors "[background] [foreground]" +set -g @dracula-cpu-usage-colors "pink dark_gray" +``` + +#### Status bar options + +Enable powerline symbols + +```bash +set -g @dracula-show-powerline true +``` + +Switch powerline symbols + +```bash +# for left +set -g @dracula-show-left-sep  + +# for right symbol (can set any symbol you like as seperator) +set -g @dracula-show-right-sep  +``` + +Enable window flags + +```bash +set -g @dracula-show-flags true +``` + +Adjust the refresh rate for the status bar + +```bash +# the default is 5, it can accept any number +set -g @dracula-refresh-rate 5 +``` + +Switch the left smiley icon + +```bash +# it can accept `session`, `smiley`, `window`, or any character. +set -g @dracula-show-left-icon session +``` + +Add padding to the left smiley icon + +```bash +# default is 1, it can accept any number and 0 disables padding. +set -g @dracula-left-icon-padding 1 +``` + +Enable high contrast pane border + +```bash +set -g @dracula-border-contrast true +``` + +#### cpu-usage options + +Customize label + +```bash +set -g @dracula-cpu-usage-label "CPU" +``` + +#### gpu-usage options + +Customize label + +```bash +set -g @dracula-gpu-usage-label "GPU" +``` + +#### ram-usage options + +Customize label + +```bash +set -g @dracula-ram-usage-label "RAM" +``` + +#### time options + +Disable timezone + +```bash +set -g @dracula-show-timezone false +``` + +Swap date to day/month + +```bash +set -g @dracula-day-month true +``` + +Enable military time + +```bash +set -g @dracula-military-time true +``` + +#### weather options + +Switch from default fahrenheit to celsius + +```bash +set -g @dracula-show-fahrenheit false +``` + diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 8156c1c..7c9f70e 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -9,13 +9,7 @@ main() { datafile=/tmp/.dracula-tmux-data - # set current directory variable - current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - # set configuration option variables - show_battery=$(get_tmux_option "@dracula-show-battery" true) - show_network=$(get_tmux_option "@dracula-show-network" true) - show_weather=$(get_tmux_option "@dracula-show-weather" true) show_fahrenheit=$(get_tmux_option "@dracula-show-fahrenheit" true) show_location=$(get_tmux_option "@dracula-show-location" true) show_powerline=$(get_tmux_option "@dracula-show-powerline" false) @@ -27,13 +21,8 @@ main() show_left_sep=$(get_tmux_option "@dracula-show-left-sep" ) show_right_sep=$(get_tmux_option "@dracula-show-right-sep" ) show_border_contrast=$(get_tmux_option "@dracula-border-contrast" false) - show_cpu_usage=$(get_tmux_option "@dracula-cpu-usage" false) - show_ram_usage=$(get_tmux_option "@dracula-ram-usage" false) - show_gpu_usage=$(get_tmux_option "@dracula-gpu-usage" false) show_day_month=$(get_tmux_option "@dracula-day-month" false) - show_time=$(get_tmux_option "@dracula-show-time" true) show_refresh=$(get_tmux_option "@dracula-refresh-rate" 5) - show_network_bandwith=$(get_tmux_option "@dracula-network-bandwith" "") # Dracula Color Pallette white='#f8f8f2' @@ -130,111 +119,83 @@ main() sleep 0.01 done - # Powerline Configuration + # Status left if $show_powerline; then - tmux set-option -g status-left "#[bg=${green},fg=${dark_gray}]#{?client_prefix,#[bg=${yellow}],} ${left_icon} #[fg=${green},bg=${gray}]#{?client_prefix,#[fg=${yellow}],}${left_sep}" - tmux set-option -g status-right "" powerbg=${gray} + else + tmux set-option -g status-left "#[bg=${green},fg=${dark_gray}]#{?client_prefix,#[bg=${yellow}],} ${left_icon}" + fi - if $show_battery; then # battery - tmux set-option -g status-right "#[fg=${pink},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${pink}] #($current_dir/battery.sh)" - powerbg=${pink} + # Status right + tmux set-option -g status-right "" + IFS=' ' read -r -a plugins <<< $(get_tmux_option "@dracula-plugins" "battery network weather") + + for plugin in "${plugins[@]}"; do + if [ $plugin = "battery" ]; then + IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-battery-colors" "pink dark_gray") + script="#($current_dir/battery.sh)" fi - if $show_ram_usage; then - tmux set-option -ga status-right "#[fg=${cyan},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${cyan}] #($current_dir/ram_info.sh)" - powerbg=${cyan} + if [ $plugin = "gpu-usage" ]; then + IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-gpu-usage-colors" "pink dark_gray") + script="#($current_dir/gpu_usage.sh)" fi - if $show_cpu_usage; then - tmux set-option -ga status-right "#[fg=${orange},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${orange}] #($current_dir/cpu_info.sh)" - powerbg=${orange} + if [ $plugin = "cpu-usage" ]; then + IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-cpu-usage-colors" "orange dark_gray") + script="#($current_dir/cpu_info.sh)" fi - if $show_gpu_usage; then - tmux set-option -ga status-right "#[fg=${pink},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${pink}] #($current_dir/gpu_usage.sh)" - powerbg=${pink} + if [ $plugin = "ram-usage" ]; then + IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-ram-usage-colors" "cyan dark_gray") + script="#($current_dir/ram_info.sh)" fi - if $show_network; then # network - tmux set-option -ga status-right "#[fg=${cyan},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${cyan}] #($current_dir/network.sh)" - powerbg=${cyan} + if [ $plugin = "network" ]; then + IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-network-colors" "cyan dark_gray") + script="#($current_dir/network.sh)" fi - if [[ "$show_network_bandwith" != "" ]]; then # network bandwith + if [ $plugin = "network-bandwith" ]; then + IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-network-bandwith-colors" "cyan dark_gray") tmux set-option -g status-right-length 250 - tmux set-option -ga status-right "#[fg=${green},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${green}] #($current_dir/network_bandwith.sh)" - powerbg=${green} + script="#($current_dir/network_bandwith.sh)" fi - if $show_weather; then # weather - tmux set-option -ga status-right "#[fg=${orange},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${orange}] #(cat $datafile)" - powerbg=${orange} + if [ $plugin = "weather" ]; then + IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-weather-colors" "orange dark_gray") + script="#(cat $datafile)" fi - if $show_time; then + if [ $plugin = "time" ]; then + IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-weather-colors" "dark_purple white") if $show_day_month && $show_military ; then # military time and dd/mm - tmux set-option -ga status-right "#[fg=${dark_purple},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${white},bg=${dark_purple}] %a %d/%m %R ${timezone} " + script="%a %d/%m %R ${timezone} " elif $show_military; then # only military time - tmux set-option -ga status-right "#[fg=${dark_purple},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${white},bg=${dark_purple}] %a %m/%d %R ${timezone} " + script="%a %m/%d %R ${timezone} " elif $show_day_month; then # only dd/mm - tmux set-option -ga status-right "#[fg=${dark_purple},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${white},bg=${dark_purple}] %a %d/%m %I:%M %p ${timezone} " + script="%a %d/%m %I:%M %p ${timezone} " else - tmux set-option -ga status-right "#[fg=${dark_purple},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${white},bg=${dark_purple}] %a %m/%d %I:%M %p ${timezone} " + script="%a %m/%d %I:%M %p ${timezone} " fi fi - tmux set-window-option -g window-status-current-format "#[fg=${gray},bg=${dark_purple}]${left_sep}#[fg=${white},bg=${dark_purple}] #I #W${current_flags} #[fg=${dark_purple},bg=${gray}]${left_sep}" - - # Non Powerline Configuration -else - tmux set-option -g status-left "#[bg=${green},fg=${dark_gray}]#{?client_prefix,#[bg=${yellow}],} ${left_icon}" - - tmux set-option -g status-right "" - - if $show_battery; then # battery - tmux set-option -g status-right "#[fg=${dark_gray},bg=${pink}] #($current_dir/battery.sh) " - fi - if $show_ram_usage; then - tmux set-option -ga status-right "#[fg=${dark_gray},bg=${cyan}] #($current_dir/ram_info.sh) " - fi - - if $show_cpu_usage; then - tmux set-option -ga status-right "#[fg=${dark_gray},bg=${orange}] #($current_dir/cpu_info.sh) " - fi - - if $show_gpu_usage; then - tmux set-option -ga status-right "#[fg=${dark_gray},bg=${pink}] #($current_dir/gpu_usage.sh) " - fi - - if $show_network; then # network - tmux set-option -ga status-right "#[fg=${dark_gray},bg=${cyan}] #($current_dir/network.sh) " - fi - - if [[ "$show_network_bandwith" != "" ]]; then # network bandwith - tmux set-option -g status-right-length 250 - tmux set-option -ga status-right "#[fg=${dark_gray},bg=${green}] #($current_dir/network_bandwith.sh) " - fi - - if $show_weather; then # weather - tmux set-option -ga status-right "#[fg=${dark_gray},bg=${orange}] #(cat $datafile) " - fi - - if $show_time; then - if $show_day_month && $show_military ; then # military time and dd/mm - tmux set-option -ga status-right "#[fg=${white},bg=${dark_purple}] %a %d/%m %R ${timezone} " - elif $show_military; then # only military time - tmux set-option -ga status-right "#[fg=${white},bg=${dark_purple}] %a %m/%d %R ${timezone} " - elif $show_day_month; then # only dd/mm - tmux set-option -ga status-right "#[fg=${white},bg=${dark_purple}] %a %d/%m %I:%M %p ${timezone} " + if $show_powerline; then + tmux set-option -ga status-right "#[fg=${!colors[0]},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${!colors[1]},bg=${!colors[0]}] $script" + powerbg=${!colors[0]} else - tmux set-option -ga status-right "#[fg=${white},bg=${dark_purple}] %a %m/%d %I:%M %p ${timezone} " + tmux set-option -ga status-right "#[fg=${!colors[1]},bg=${!colors[0]}] $script" fi - fi + done - tmux set-window-option -g window-status-current-format "#[fg=${white},bg=${dark_purple}] #I #W${current_flags} " + tmux set-option -ga status-right " " + # Window option + if $show_powerline; then + tmux set-window-option -g window-status-current-format "#[fg=${gray},bg=${dark_purple}]${left_sep}#[fg=${white},bg=${dark_purple}] #I #W${current_flags} #[fg=${dark_purple},bg=${gray}]${left_sep}" + else + tmux set-window-option -g window-status-current-format "#[fg=${white},bg=${dark_purple}] #I #W${current_flags} " fi tmux set-window-option -g window-status-format "#[fg=${white}]#[bg=${gray}] #I #W${flags}" @@ -244,3 +205,4 @@ else # run main function main + From 90c2748a39dad40ccf6878e2c56ab75f08cbd4c2 Mon Sep 17 00:00:00 2001 From: Sabato Luca Guadagno Date: Tue, 6 Jul 2021 13:44:31 +0200 Subject: [PATCH 5/8] remove commented code --- scripts/cpu_info.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/cpu_info.sh b/scripts/cpu_info.sh index b66ee8c..04d3037 100755 --- a/scripts/cpu_info.sh +++ b/scripts/cpu_info.sh @@ -34,7 +34,6 @@ main() cpu_label=$(get_tmux_option "@dracula-cpu-usage-label" "CPU") cpu_percent=$(get_percent) echo "$cpu_label $cpu_percent" - # echo "$current_dir" sleep $RATE } From 58619bd3c64ad8bc58542dd69a9d20cff0207d2b Mon Sep 17 00:00:00 2001 From: Sabato Luca Guadagno Date: Mon, 19 Jul 2021 08:19:41 +0200 Subject: [PATCH 6/8] fix too many arguments in utils.sh --- scripts/utils.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/utils.sh b/scripts/utils.sh index 33a47d0..a296192 100644 --- a/scripts/utils.sh +++ b/scripts/utils.sh @@ -4,7 +4,7 @@ get_tmux_option() { local option=$1 local default_value=$2 local option_value=$(tmux show-option -gqv "$option") - if [ -z $option_value ]; then + if [ -z "$option_value" ]; then echo $default_value else echo $option_value From 9fcf4515b86e7649c0befb6a495aa43bf8f2c22a Mon Sep 17 00:00:00 2001 From: Sabato Luca Guadagno Date: Thu, 22 Jul 2021 12:17:11 +0200 Subject: [PATCH 7/8] wait for $datafile if weather plugin is active --- scripts/dracula.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 7c9f70e..e830d65 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -113,12 +113,6 @@ main() # status bar tmux set-option -g status-style "bg=${gray},fg=${white}" - # wait unit $datafile exists just to avoid errors - # this should almost never need to wait unless something unexpected occurs - while $show_weather && [ ! -f $datafile ]; do - sleep 0.01 - done - # Status left if $show_powerline; then tmux set-option -g status-left "#[bg=${green},fg=${dark_gray}]#{?client_prefix,#[bg=${yellow}],} ${left_icon} #[fg=${green},bg=${gray}]#{?client_prefix,#[fg=${yellow}],}${left_sep}" @@ -164,6 +158,12 @@ main() fi if [ $plugin = "weather" ]; then + # wait unit $datafile exists just to avoid errors + # this should almost never need to wait unless something unexpected occurs + while [ ! -f $datafile ]; do + sleep 0.01 + done + IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-weather-colors" "orange dark_gray") script="#(cat $datafile)" fi From 832d06405b51a0747e542f6206cd792cced9948d Mon Sep 17 00:00:00 2001 From: Sabato Luca Guadagno Date: Thu, 22 Jul 2021 12:23:57 +0200 Subject: [PATCH 8/8] start weather script only when weather is present in plugins --- scripts/dracula.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/dracula.sh b/scripts/dracula.sh index e830d65..cb0f7a0 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -23,6 +23,7 @@ main() show_border_contrast=$(get_tmux_option "@dracula-border-contrast" false) show_day_month=$(get_tmux_option "@dracula-day-month" false) show_refresh=$(get_tmux_option "@dracula-refresh-rate" 5) + IFS=' ' read -r -a plugins <<< $(get_tmux_option "@dracula-plugins" "battery network weather") # Dracula Color Pallette white='#f8f8f2' @@ -64,7 +65,7 @@ main() fi # start weather script in background - if $show_weather; then + if [[ "${plugins[@]}" =~ "weather" ]]; then $current_dir/sleep_weather.sh $show_fahrenheit $show_location & fi @@ -123,7 +124,6 @@ main() # Status right tmux set-option -g status-right "" - IFS=' ' read -r -a plugins <<< $(get_tmux_option "@dracula-plugins" "battery network weather") for plugin in "${plugins[@]}"; do if [ $plugin = "battery" ]; then