-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtmux_status
More file actions
executable file
·126 lines (101 loc) · 2.41 KB
/
tmux_status
File metadata and controls
executable file
·126 lines (101 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/perl -CS
use warnings;
use strict;
use POSIX ();
use Term::ANSIColor;
use utf8;
# array of sparks:
my @sparks = split('', '▁▂▃▄▅▆▇█');
# smelly tmux colors:
my %colors = (
black => '#[fg=black]',
red => '#[fg=red]',
green => '#[fg=green]',
brown => '#[fg=brown}',
blue => '#[fg=blue]',
magenta => '#[fg=magenta]',
cyan => '#[fg=cyan]',
white => '#[fg=white]',
yellow => '#[fg=yellow]',
orange => '#[fg=orange]',
blink => '#[blink]',
reset => '#[default]'
);
sub print_time {
print POSIX::strftime("%H:%M %m/%d/%Y", localtime);
}
sub print_battery {
if (`which acpi`) {
print_battery_acpi();
} elsif (`which ioreg`) {
print_battery_ioreg();
}
}
sub print_battery_acpi {
my $battery = `acpi -b`;
# skip if acpi not installed or no battery
# if no battery, acpi exists successfully but prints to stderr
if ($? != 0 || $battery eq '') {
return;
}
# remove newline
chomp $battery;
# gather battery info
my @info = split(/,?\s/, $battery);
my $state = $info[2];
my $percent = $info[3];
$percent =~ /(\d+)/;
$percent = $1;
# print a lightning when charging:
my $decoration = '';
if ($state eq 'Charging' || $state eq 'Charged' || $state eq 'Full') {
$decoration = '⌁';
}
&print_battery_status($percent, $decoration, $state);
}
sub print_battery_ioreg {
my $battery = `pmset -g batt`;
# remove newline
chomp $battery;
$battery =~ s/^(?:.*\n){1}//;
#gather battery info
my @info = split(/%?;?\s+/, $battery);
my $state = $info[4];
my $percent = $info[3];
#print a lightning when charging:
my $decoration = '';
if ($state eq 'charging' || $state eq 'charged' || $state eq 'Full') {
$decoration = '⌁';
}
&print_battery_status($percent, $decoration, $state);
}
# print battery status line
sub print_battery_status {
my ($percent, $decoration, $state) = @_;
# pull out battery spark:
# map [0, 100] -> [0, 7] as integers
my $spark = $sparks[POSIX::floor(0.0799 * $percent)];
# color text when battery low
if ($state eq 'discharging') {
if ($percent <= 40) {
print $colors{'yellow'};
}
if ($percent <= 20) {
print $colors{'red'};
}
if ($percent <= 5) {
print $colors{'blink'};
}
}
print $decoration;
print $spark;
print ' ';
print $percent;
print '%';
print $colors{'reset'};
}
print ' ';
print_battery;
print ' ';
print_time;
print ' ';