17 |
|
|
18 |
my $debug = shift @ARGV; |
my $debug = shift @ARGV; |
19 |
my $awesome = 0; |
my $awesome = 0; |
20 |
|
my $dzen = 1; |
21 |
|
|
22 |
$|=1; |
$|=1; |
23 |
|
|
68 |
} |
} |
69 |
}); |
}); |
70 |
|
|
71 |
|
my $unit_colors = { |
72 |
|
'b' => '#ff0000', |
73 |
|
'k' => '#ffff00', |
74 |
|
'M' => '#00ff00', |
75 |
|
'G' => '#0000ff', |
76 |
|
}; |
77 |
|
|
78 |
sub unit { |
sub unit { |
79 |
my $v = shift; |
my ($v,$align) = @_; |
80 |
|
$align ||= ''; |
81 |
|
|
82 |
warn "unit( $v )\n" if ($debug); |
warn "unit( $v )\n" if ($debug); |
83 |
|
|
89 |
$v /= 1024; |
$v /= 1024; |
90 |
} |
} |
91 |
|
|
92 |
|
my $unit = $units[$o]; |
93 |
|
|
94 |
|
my $out = ''; |
95 |
|
$out .= '^fg(' . $unit_colors->{$unit} . ')'; |
96 |
|
|
97 |
if ( $v >= 1 ) { |
if ( $v >= 1 ) { |
98 |
return sprintf("%d%s", $v, $units[$o]); |
$out .= sprintf("%${align}5d",$v); |
99 |
} elsif ( $v == 0 ) { |
} elsif ( $v == 0 ) { |
100 |
return ''; |
$out = ' ' x 5; |
101 |
} else { |
} else { |
102 |
return sprintf("%.1f%s", $v, $units[$o]); |
$out .= sprintf("%${align}5.1f", $v); |
103 |
} |
} |
104 |
|
|
105 |
|
$unit = '^fg(#444444)' . $unit if $dzen; |
106 |
|
$out =~ s/\s(\s*)$/$unit$1/ unless $out =~ m/\s{5}/; |
107 |
|
$out .= '^fg(#ffffff)' if $dzen; |
108 |
|
|
109 |
|
return $out; |
110 |
} |
} |
111 |
|
|
112 |
my ( $lrx, $ltx ) = ( 0, 0 ); |
my ( $lrx, $ltx ) = ( 0, 0 ); |
126 |
my $full = read_file( $sysfs_path ); |
my $full = read_file( $sysfs_path ); |
127 |
$sysfs_path =~ s/_full/_now/; |
$sysfs_path =~ s/_full/_now/; |
128 |
my $now = read_file( $sysfs_path ); |
my $now = read_file( $sysfs_path ); |
129 |
$bat = sprintf("%2d%% | ", $now * 100 / $full ); |
$bat = sprintf("%2d%%", $now * 100 / $full ); |
130 |
|
|
131 |
} elsif ( $proc_acpi_battery ) { |
} elsif ( $proc_acpi_battery ) { |
132 |
|
|
146 |
my $mm = int( ( $time - $hh ) * 60 ); |
my $mm = int( ( $time - $hh ) * 60 ); |
147 |
my $ss = ( $time * 3600 ) % 60; |
my $ss = ( $time * 3600 ) % 60; |
148 |
|
|
149 |
$bat = sprintf("%s %2d%% %02d:%02d:%02d %3.1fW!| ", |
$bat = sprintf("%s %2d%% %02d:%02d:%02d %3.1fW!", |
150 |
substr($state->{'charging state'},0,1), |
substr($state->{'charging state'},0,1), |
151 |
$pcnt * 100, $hh, $mm, $ss, |
$pcnt * 100, $hh, $mm, $ss, |
152 |
$state->{'present rate'} / 1000 |
$state->{'present rate'} / 1000 |
153 |
); |
); |
154 |
} |
} |
155 |
} |
} |
|
} else { |
|
|
$bat =~ s/!(\|\s)$/ $1/; |
|
156 |
} |
} |
157 |
$i++; |
$i++; |
158 |
|
|
205 |
my $d_write = ( $d_w - $ld_w ) / $dt; |
my $d_write = ( $d_w - $ld_w ) / $dt; |
206 |
( $ld_r, $ld_w ) = ( $d_r, $d_w ); |
( $ld_r, $ld_w ) = ( $d_r, $d_w ); |
207 |
|
|
208 |
my $out = sprintf("%s |%5s D %-5s|%5s > %-5s| %s%s | %s", |
my $out = join( $dzen ? ' ^fg(#333333)|^fg(#ffffff) ' : ' | ', |
209 |
$load, |
$load, |
210 |
unit( $d_read ), unit( $d_write ), |
unit( $d_read ) . ' D ' . unit( $d_write, '-' ), |
211 |
unit( $net_rx ), unit( $net_tx ), |
unit( $net_rx ) . ' > ' . unit( $net_tx, '-' ), |
212 |
$bat, $temp, |
$bat, $temp, |
213 |
$s, |
$s, |
214 |
); |
); |
215 |
|
|
216 |
|
|
217 |
print "$out\n"; |
print "$out\n"; |
218 |
if ( $awesome ) { |
if ( $awesome ) { |
219 |
open(my $fh, '|-', 'awesome-client') || die "can't pipe to awesome-client: $!"; |
open(my $fh, '|-', 'awesome-client') || die "can't pipe to awesome-client: $!"; |