Added cpu percentage, works on powerline and normal, will add memory

later :)
This commit is contained in:
Ethan Edwards 2020-06-01 02:10:10 -04:00
parent 83cb547db9
commit b10c4dcf18
3 changed files with 68 additions and 0 deletions

View file

@ -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` * 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. * 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 high contrast pane border: `set -g @dracula-border-contrast true`
* Enable cpu percentage: `set -g @dracula-cpu-percent true`

53
scripts/cpu_info.sh Executable file
View file

@ -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

View file

@ -27,6 +27,7 @@ main()
show_left_sep=$(get_tmux_option "@dracula-show-left-sep") show_left_sep=$(get_tmux_option "@dracula-show-left-sep")
show_right_sep=$(get_tmux_option "@dracula-show-right-sep") show_right_sep=$(get_tmux_option "@dracula-show-right-sep")
show_border_contrast=$(get_tmux_option "@dracula-border-contrast" false) show_border_contrast=$(get_tmux_option "@dracula-border-contrast" false)
show_cpu_percentage=$(get_tmux_option "@dracula-cpu-percent" false)
# Dracula Color Pallette # Dracula Color Pallette
white='#f8f8f2' white='#f8f8f2'
@ -64,6 +65,10 @@ main()
if $show_weather; then if $show_weather; then
$current_dir/sleep_weather.sh $show_fahrenheit & $current_dir/sleep_weather.sh $show_fahrenheit &
fi fi
if $show_cpu_percentage; then
$current_dir/cpu_info.sh &
fi
# sets refresh interval to every 5 seconds # sets refresh interval to every 5 seconds
@ -98,6 +103,11 @@ main()
tmux set-option -g status-right "" tmux set-option -g status-right ""
powerbg=${gray} 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 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)" 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} powerbg=${pink}
@ -131,6 +141,10 @@ main()
tmux set-option -g status-right "#[fg=${dark_gray},bg=${pink}] #($current_dir/battery.sh) " tmux set-option -g status-right "#[fg=${dark_gray},bg=${pink}] #($current_dir/battery.sh) "
fi 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 if $show_network; then # network
tmux set-option -ga status-right "#[fg=${dark_gray},bg=${cyan}] #($current_dir/network.sh) " tmux set-option -ga status-right "#[fg=${dark_gray},bg=${cyan}] #($current_dir/network.sh) "
fi fi