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..c5180cd --- /dev/null +++ b/scripts/cpu_info.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +get_percent() +{ + case $(uname -s) in + Linux) + percent=$(top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1"%"}') + echo $percent + ;; + + Darwin) + percent=$(ps -A -o %cpu | awk '{s+=$1} END {print s "%"}') + echo $percent + ;; + + CYGWIN*|MINGW32*|MSYS*|MINGW*) + # TODO - windows compatability + ;; + esac +} + +main() +{ + cpu_percent=$(get_percent) + echo "CPU $cpu_percent" + sleep 10 +} + +# run main driver +main diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 5cd2155..e3b3bbe 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,8 +65,7 @@ main() if $show_weather; then $current_dir/sleep_weather.sh $show_fahrenheit & fi - - + # sets refresh interval to every 5 seconds tmux set-option -g status-interval 5 @@ -103,6 +103,11 @@ main() 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} @@ -131,6 +136,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