From b10c4dcf18360e4e77f53494d0404cdb8a0d20ae Mon Sep 17 00:00:00 2001 From: Ethan Edwards Date: Mon, 1 Jun 2020 02:10:10 -0400 Subject: [PATCH 1/7] Added cpu percentage, works on powerline and normal, will add memory later :) --- INSTALL.md | 1 + scripts/cpu_info.sh | 53 +++++++++++++++++++++++++++++++++++++++++++++ scripts/dracula.sh | 14 ++++++++++++ 3 files changed, 68 insertions(+) create mode 100755 scripts/cpu_info.sh diff --git a/INSTALL.md b/INSTALL.md index aa4fdd3..3dd0106 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -24,3 +24,4 @@ Customize the status bar by adding any of these lines to your .tmux.conf as desi * Enable military time: `set -g @dracula-military-time true` * Switch the left smiley icon `set -g @dracula-show-left-icon session` it can accept `session`, `smiley`, `window`, or any character. * Enable high contrast pane border: `set -g @dracula-border-contrast true` +* Enable cpu percentage: `set -g @dracula-cpu-percent true` diff --git a/scripts/cpu_info.sh b/scripts/cpu_info.sh new file mode 100755 index 0000000..861f754 --- /dev/null +++ b/scripts/cpu_info.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash + +get_percent() +{ + arg=$1 + case "$arg" in + Linux) + percent=$(top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1"%"}') + echo $percent + ;; + + Mac) + # TODO - Mac compatability + ;; + + Windows) + # TODO - windows compatability + ;; + esac +} +check_os() +{ + # Check os + case $(uname -s) in + Linux) + get_percent Linux + ;; + + Darwin) + # Dont have a mac currently, TODO - Mac compatability + get_percent Mac + ;; + + CYGWIN*|MINGW32*|MSYS*|MINGW*) + get_percent Windows + # leaving empty - TODO - windows compatability + ;; + + *) + ;; + esac +} + + + +main() +{ + cpu_percent=$(check_os) + echo "CPU $cpu_percent" + sleep 5 +} +#run main driver +main diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 5cd2155..27a5d2a 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -27,6 +27,7 @@ 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_percentage=$(get_tmux_option "@dracula-cpu-percent" false) # Dracula Color Pallette white='#f8f8f2' @@ -64,6 +65,10 @@ main() if $show_weather; then $current_dir/sleep_weather.sh $show_fahrenheit & fi + + if $show_cpu_percentage; then + $current_dir/cpu_info.sh & + fi # sets refresh interval to every 5 seconds @@ -98,6 +103,11 @@ main() tmux set-option -g status-right "" powerbg=${gray} + if $show_cpu_percentage; then + tmux set-option -ga status-right "#[fg=${pink},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${pink}] #($current_dir/cpu_info.sh)" + powerbg=${pink} + 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} @@ -131,6 +141,10 @@ main() tmux set-option -g status-right "#[fg=${dark_gray},bg=${pink}] #($current_dir/battery.sh) " fi + if $show_cpu_percentage; then + tmux set-option -ga status-right "#[fg=${dark_gray},bg=${orange}]#($current_dir/cpu_info.sh) " + fi + if $show_network; then # network tmux set-option -ga status-right "#[fg=${dark_gray},bg=${cyan}] #($current_dir/network.sh) " fi From 3e4add69187aad485e43e87b28187f910161d3ce Mon Sep 17 00:00:00 2001 From: Ethan Edwards Date: Mon, 1 Jun 2020 10:39:17 -0400 Subject: [PATCH 2/7] Added Mac (? testing) support, added comments --- scripts/cpu_info.sh | 4 ++-- scripts/dracula.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/cpu_info.sh b/scripts/cpu_info.sh index 861f754..74aaa46 100755 --- a/scripts/cpu_info.sh +++ b/scripts/cpu_info.sh @@ -10,7 +10,7 @@ get_percent() ;; Mac) - # TODO - Mac compatability + percent=$(ps -A -o %cpu | awk '{s+=$1} END {print s "%"}') ;; Windows) @@ -27,7 +27,7 @@ check_os() ;; Darwin) - # Dont have a mac currently, TODO - Mac compatability + # Dont have a mac currently, TODO - Mac compatability - May have a solution, testing get_percent Mac ;; diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 27a5d2a..aebdbcf 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -66,11 +66,11 @@ main() $current_dir/sleep_weather.sh $show_fahrenheit & fi + # start cpu script in the background if $show_cpu_percentage; then $current_dir/cpu_info.sh & fi - # sets refresh interval to every 5 seconds tmux set-option -g status-interval 5 From a17746e0d131759d103fba28c8eba5294d6bf2a5 Mon Sep 17 00:00:00 2001 From: Ethan Edwards Date: Mon, 1 Jun 2020 11:53:16 -0400 Subject: [PATCH 3/7] Fixed a bug --- scripts/cpu_info.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/cpu_info.sh b/scripts/cpu_info.sh index 74aaa46..37560ab 100755 --- a/scripts/cpu_info.sh +++ b/scripts/cpu_info.sh @@ -11,6 +11,7 @@ get_percent() Mac) percent=$(ps -A -o %cpu | awk '{s+=$1} END {print s "%"}') + echo $percent ;; Windows) From 1451ccaff76ae4da537f167deace9c86918f2adc Mon Sep 17 00:00:00 2001 From: Ethan Edwards Date: Mon, 1 Jun 2020 19:27:15 -0400 Subject: [PATCH 4/7] Fixed it for powerline, removed 'testing' on Mac --- scripts/cpu_info.sh | 3 +-- scripts/dracula.sh | 10 +++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/scripts/cpu_info.sh b/scripts/cpu_info.sh index 37560ab..8879fb3 100755 --- a/scripts/cpu_info.sh +++ b/scripts/cpu_info.sh @@ -28,7 +28,6 @@ check_os() ;; Darwin) - # Dont have a mac currently, TODO - Mac compatability - May have a solution, testing get_percent Mac ;; @@ -48,7 +47,7 @@ main() { cpu_percent=$(check_os) echo "CPU $cpu_percent" - sleep 5 + sleep 10 } #run main driver main diff --git a/scripts/dracula.sh b/scripts/dracula.sh index aebdbcf..1e567e8 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -103,16 +103,16 @@ main() tmux set-option -g status-right "" powerbg=${gray} - if $show_cpu_percentage; then - tmux set-option -ga status-right "#[fg=${pink},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${pink}] #($current_dir/cpu_info.sh)" - powerbg=${pink} - 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} fi + if $show_cpu_percentage; 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_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} From 3ec7e1a038e2326843aec6885f9f1f0234a567df Mon Sep 17 00:00:00 2001 From: Ethan Edwards Date: Tue, 2 Jun 2020 22:55:14 -0400 Subject: [PATCH 5/7] For some reason branch wasnt up to date? Fixed --- scripts/cpu_info.sh | 28 ++-------------------------- scripts/dracula.sh | 5 ----- 2 files changed, 2 insertions(+), 31 deletions(-) diff --git a/scripts/cpu_info.sh b/scripts/cpu_info.sh index 8879fb3..cee644f 100755 --- a/scripts/cpu_info.sh +++ b/scripts/cpu_info.sh @@ -2,8 +2,7 @@ get_percent() { - arg=$1 - case "$arg" in + case $(uname -s) in Linux) percent=$(top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1"%"}') echo $percent @@ -19,33 +18,10 @@ get_percent() ;; esac } -check_os() -{ - # Check os - case $(uname -s) in - Linux) - get_percent Linux - ;; - - Darwin) - get_percent Mac - ;; - - CYGWIN*|MINGW32*|MSYS*|MINGW*) - get_percent Windows - # leaving empty - TODO - windows compatability - ;; - - *) - ;; - esac -} - - main() { - cpu_percent=$(check_os) + cpu_percent=$(get_percent) echo "CPU $cpu_percent" sleep 10 } diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 1e567e8..fbf27f8 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -66,11 +66,6 @@ main() $current_dir/sleep_weather.sh $show_fahrenheit & fi - # start cpu script in the background - if $show_cpu_percentage; then - $current_dir/cpu_info.sh & - fi - # sets refresh interval to every 5 seconds tmux set-option -g status-interval 5 From 87ef58abfca7bcfa3e4e794339a7a326eadc9522 Mon Sep 17 00:00:00 2001 From: Ethan Edwards Date: Wed, 3 Jun 2020 22:58:26 -0400 Subject: [PATCH 6/7] Fixed the uname -s output case statement issue --- scripts/cpu_info.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/cpu_info.sh b/scripts/cpu_info.sh index cee644f..c5180cd 100755 --- a/scripts/cpu_info.sh +++ b/scripts/cpu_info.sh @@ -8,12 +8,12 @@ get_percent() echo $percent ;; - Mac) + Darwin) percent=$(ps -A -o %cpu | awk '{s+=$1} END {print s "%"}') echo $percent ;; - Windows) + CYGWIN*|MINGW32*|MSYS*|MINGW*) # TODO - windows compatability ;; esac @@ -25,5 +25,6 @@ main() echo "CPU $cpu_percent" sleep 10 } -#run main driver + +# run main driver main From 614d0123520411e29728e7b7a44d66793eced401 Mon Sep 17 00:00:00 2001 From: Dane Williams Date: Wed, 3 Jun 2020 20:33:41 -0700 Subject: [PATCH 7/7] fix space for non powerline --- scripts/dracula.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/dracula.sh b/scripts/dracula.sh index fbf27f8..e3b3bbe 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -137,7 +137,7 @@ main() fi if $show_cpu_percentage; then - tmux set-option -ga status-right "#[fg=${dark_gray},bg=${orange}]#($current_dir/cpu_info.sh) " + tmux set-option -ga status-right "#[fg=${dark_gray},bg=${orange}] #($current_dir/cpu_info.sh) " fi if $show_network; then # network