Skip to content

Commit

Permalink
Merge pull request #424 from zoj613/cpu_usage
Browse files Browse the repository at this point in the history
cpu_usage: Support custom colors for cpu_usage blocklet
  • Loading branch information
denisse-dev authored Oct 12, 2021
2 parents 0139a44 + 8d49405 commit 01557be
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions cpu_usage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ LABEL=CPU
#T_WARN=50
#T_CRIT=80
#DECIMALS=2
#COLOR_NORMAL=#EBDBB2
#COLOR_WARN=#FFFC00
#COLOR_CRIT=#FF0000
```
10 changes: 7 additions & 3 deletions cpu_usage/cpu_usage
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ my $t_crit = $ENV{T_CRIT} // 80;
my $cpu_usage = -1;
my $decimals = $ENV{DECIMALS} // 2;
my $label = $ENV{LABEL} // "";
my $color_normal = $ENV{COLOR_NORMAL} // "#EBDBB2";
my $color_warn = $ENV{COLOR_WARN} // "#FFFC00";
my $color_crit = $ENV{COLOR_CRIT} // "#FF0000";

sub help {
print "Usage: cpu_usage [-w <warning>] [-c <critical>] [-d <decimals>]\n";
Expand Down Expand Up @@ -53,10 +56,11 @@ printf "%.${decimals}f%%\n", $cpu_usage;

# Print color, if needed
if ($cpu_usage >= $t_crit) {
print "#FF0000\n";
exit 33;
print "${color_crit}\n";
} elsif ($cpu_usage >= $t_warn) {
print "#FFFC00\n";
print "${color_warn}\n";
} else {
print "${color_normal}\n";
}

exit 0;
3 changes: 3 additions & 0 deletions cpu_usage/i3blocks.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ LABEL=CPU
#T_WARN=50
#T_CRIT=80
#DECIMALS=2
#COLOR_NORMAL=#EBDBB2
#COLOR_WARN=#FFFC00
#COLOR_CRIT=#FF0000

0 comments on commit 01557be

Please sign in to comment.