This commit is contained in:
Simon Vieille 2017-06-19 16:36:59 +02:00
commit a0ab663573
12 changed files with 427 additions and 40 deletions

90
bar/bar1.conf Normal file
View file

@ -0,0 +1,90 @@
interval=1
color=#E9F1FF
[bandwidth_eth0]
command=/home/simon/.i3/bar/src/bandwidth.php eth0
format=json
interval=5
[bandwidth_eth1]
command=/home/simon/.i3/bar/src/bandwidth.php eth1
format=json
interval=5
[bandwidth_wlan0]
command=/home/simon/.i3/bar/src/bandwidth.php wlan0
format=json
interval=1
[inet_eth0]
command=/home/simon/.i3/bar/src/ip.php eth0
format=json
interval=10
[inet_eth0]
command=/home/simon/.i3/bar/src/ip.php eth0
format=json
interval=10
[inet_eth1]
command=/home/simon/.i3/bar/src/ip.php eth1
format=json
interval=10
[inet_wlan0]
command=/home/simon/.i3/bar/src/ip.php wlan0
format=json
interval=10
[inet_easytether0]
command=/home/simon/.i3/bar/src/ip.php easytether0
format=json
interval=100
[inet_wan]
command=/home/simon/.i3/bar/src/ip_wan.php
format=json
interval=100
[mount_point_space_root]
command=/home/simon/.i3/bar/src/mount_point_space.php /
format=json
interval=5
[mount_point_space_home]
command=/home/simon/.i3/bar/src/mount_point_space.php /home 80 90
format=json
interval=5
[mount_point_space_secured]
command=/home/simon/.i3/bar/src/mount_point_space.php /secured
format=json
interval=5
[memory]
command=memory
[spotify]
command=/home/simon/.i3/bar/src/spotify.php
format=json
interval=1
[volume]
command=/home/simon/.i3/bar/src/volume.php
format=json
interval=1
[time]
command=/home/simon/.i3/bar/src/time.php
format=json
interval=1
[date]
command=/home/simon/.i3/bar/src/date.php
format=json
interval=30
[acpi]
command=/home/simon/.i3/bar/src/acpi.php
format=json
interval=1

64
bar/src/acpi.php Executable file
View file

@ -0,0 +1,64 @@
#!/usr/bin/php
<?php
require __DIR__.'/base/block.php';
$acpi = shell_exec('acpi');
if (!preg_match('`Discharging`', $acpi)) {
preg_match('`([0-9]+%)`', $acpi, $values);
if (!empty($values)) {
$charging = $values[1];
if ($charging < 20) {
$color = color('critical');
} elseif ($charging < 50) {
$color = color('warning');
} else {
$color = color('normal');
}
$charging .= '↑';
$block = block(
'volume',
[
'full_text' => $charging,
'color' => $color,
]
);
} else {
$block = block(
'volume',
[
'full_text' => '??? ↑',
'color' => color('info'),
]
);
}
} else {
preg_match('`([0-9]+%), ([0-9]+:[0-9]+)`', $acpi, $values);
if ($values[0] < 20) {
$color = color('critical');
} elseif ($values[0] < 50) {
$color = color('warning');
} else {
$color = color('info');
}
$charging = $values[1].'↓';
$times = str_replace(':', 'h', $values[2]);
$text = implode(' ', array($charging, $times));
$block = block(
'volume',
[
'full_text' => $text,
'color' => $color,
]
);
}
echo $block;

35
bar/src/bandwidth.php Executable file
View file

@ -0,0 +1,35 @@
#!/usr/bin/php
<?php
require __DIR__.'/base/block.php';
$iface = $argv[1] ?? 'eth0';
$inet = ($argv[2] ?? 'inet').' ';
$command = sprintf(
'ip address show %s | grep %s | awk \'{ print $2 }\'',
escapeshellarg($iface),
escapeshellarg($inet)
);
$ip = trim(shell_exec($command));
if (empty($ip)) {
die;
}
$bwidth = explode(' ', preg_replace('/ +/', ' ', trim(shell_exec('ifstat -i '.escapeshellcmd($iface).' 1 1 | tail -n 1'))));
if (empty($bwidth)) {
die;
}
$fullText = '['.$iface.'] '.$bwidth[0].'Ko/s↓ '.$bwidth[1].'Ko/s↑';
echo block(
'bandwidth_'.$iface,
[
'full_text' => $fullText,
'color' => color('info'),
]
);

32
bar/src/base/block.php Normal file
View file

@ -0,0 +1,32 @@
<?php
function color($label)
{
$colors = [
'music' => '#C3D4FF',
'date' => '#98A6C7',
'info' => '#E9F1FF',
'critical' => '#FF474A',
'warning' => '#FF6836',
'normal' => '#B3FF6C',
];
return $colors[$label] ?? '#ffffff';
}
function block(string $name, array $options = [])
{
$options = array_merge(
[
'full_text' => '',
'align' => 'left',
'name' => $name,
'urgent' => false,
'separator' => true,
'separator_block_width' => 20,
],
$options
);
echo stripslashes(json_encode($options, JSON_UNESCAPED_UNICODE));
}

16
bar/src/date.php Executable file
View file

@ -0,0 +1,16 @@
#!/usr/bin/php
<?php
require __DIR__.'/base/block.php';
$format = $argv[1] ?? 'd/m/Y';
$fullText = date($format);
echo block(
'date_'.$format,
[
'full_text' => $fullText,
'color' => color('date'),
]
);

30
bar/src/ip.php Executable file
View file

@ -0,0 +1,30 @@
#!/usr/bin/php
<?php
require __DIR__.'/base/block.php';
$iface = $argv[1] ?? 'eth0';
$inet = ($argv[2] ?? 'inet').' ';
$command = sprintf(
'ip address show %s | grep %s | awk \'{ print $2 }\'',
escapeshellarg($iface),
escapeshellarg($inet)
);
$ip = trim(shell_exec($command));
if (empty($ip)) {
die;
}
$fullText = sprintf('[%s] %s', $iface, $ip);
$shortText = sprintf('%s: %s', $iface, $ip);
echo block(
'ip_'.$iface.'_'.$inet,
[
'full_text' => $fullText,
'short_text' => $shortText,
]
);

29
bar/src/ip_wan.php Executable file
View file

@ -0,0 +1,29 @@
#!/usr/bin/php
<?php
require __DIR__.'/base/block.php';
$ipv6 = !empty($argv[1]);
$iface = 'wan';
$command = sprintf(
'wget -O - -q %s "https://api.ipify.org/?format=text" | head -n 1 | cut -c1-50',
$ipv6 ? '-6' : null
);
$ip = trim(shell_exec($command));
if (empty($ip)) {
die;
}
$fullText = sprintf('[%s] %s', $iface, $ip);
$shortText = sprintf('%s: %s', $iface, $ip);
echo block(
'ip_'.$iface,
[
'full_text' => $fullText,
'short_text' => $shortText,
]
);

43
bar/src/mount_point_space.php Executable file
View file

@ -0,0 +1,43 @@
#!/usr/bin/php
<?php
require __DIR__.'/base/block.php';
$mountPoint = $argv[1] ?? '/';
$range1 = $argv[2] ?? 70;
$range2 = $argv[3] ?? 90;
$command = sprintf(
'df -h %s | tail -n 1',
escapeshellcmd($mountPoint)
);
$result = trim(shell_exec($command));
if (empty($result)) {
die;
}
list($dev, $size, $used, $free, $usedP, $point) = explode(' ', preg_replace('/\s+/', ' ', $result));
$percent = intval($usedP);
if ($percent < $range1) {
$color = color('normal');
} elseif ($percent < $range2) {
$color = color('warning');
} else {
$color = color('critical');
}
$fullText = sprintf('[%s] %s%%', $mountPoint, $percent);
$shortText = sprintf('%s: %s%%', $mountPoint, $percent);
echo block(
'mount_point_space_'.$mountPoint,
[
'full_text' => $fullText,
'short_text' => $shortText,
'color' => $color,
]
);

36
bar/src/spotify.php Executable file
View file

@ -0,0 +1,36 @@
#!/usr/bin/php
<?php
require __DIR__.'/base/block.php';
$status = trim(shell_exec('playerctl -p spotify status'));
if (!in_array($status, ['Playing'])) {
die;
}
function cleanUp($d)
{
$string = trim(str_replace(['"', "'"], ' ', $d));
if (mb_strlen($string) > 15) {
$string = substr($string, 0, 15).'…';
}
return $string;
}
$title = cleanUp(shell_exec('playerctl -p spotify metadata xesam:title'));
$artist = cleanUp(shell_exec('playerctl -p spotify metadata xesam:artist'));
$label = sprintf('%s %s', $title, $artist);
$fullText = sprintf('%s %s', $title, $artist);
echo block(
'spotify',
[
'full_text' => $fullText,
'color' => color('music'),
]
);

16
bar/src/time.php Executable file
View file

@ -0,0 +1,16 @@
#!/usr/bin/php
<?php
require __DIR__.'/base/block.php';
$format = $argv[1] ?? 'H:i:s';
$fullText = date($format);
echo block(
'time_'.$format,
[
'full_text' => $fullText,
'color' => color('date'),
]
);

20
bar/src/volume.php Executable file
View file

@ -0,0 +1,20 @@
#!/usr/bin/php
<?php
require __DIR__.'/base/block.php';
$volume = shell_exec('amixer get Master | grep Mono:');
if ($volume) {
preg_match('/\[([0-9%]+)\]/', $volume, $mach);
if (isset($mach[1])) {
echo block(
'volume',
[
'full_text' => $mach[1].' ♪',
'color' => color('music'),
]
);
}
}