configure bar

This commit is contained in:
Simon Vieille 2019-01-28 11:13:11 +01:00
parent 542fa6e379
commit 62966c2fce
Signed by: deblan
GPG key ID: 03383D15A1D31745
15 changed files with 126 additions and 104 deletions

View file

@ -70,43 +70,11 @@ format=json
markup=pango markup=pango
interval=3 interval=3
#[spotify_ctrl] [spotify_ctrl]
#command=/home/simon/.i3/bar/src/spotify_ctrl.php command=/home/simon/.i3/bar/src/spotify_ctrl.php
#format=json
#interval=1
#[app_S]
#command=/home/simon/.i3/bar/src/app.php S "i3-msg workspace '6. MEDIA'" '#1db954' 0
#format=json
#interval=1000
[app_J]
command=/home/simon/.i3/bar/src/app.php J "/home/simon/bin/joplin" '#057bdd' '#fff' 0
format=json format=json
markup=pango markup=pango
interval=1000 interval=1
[app_Y]
command=/home/simon/.i3/bar/src/app.php Y "xdg-open https://www.youtube.com/feed/subscriptions" '#c74a42' '#fff' 0
format=json
markup=pango
interval=1000
[app_F]
command=/home/simon/.i3/bar/src/app.php F "xdg-open https://www.facebook.com/" '#598df3' '#fff' 1
format=json
markup=pango
interval=1000
#[app_C]
#command=/home/simon/.i3/bar/src/app.php C "xdg-open https://choualbox.com/new" '#eeb819' 0
#format=json
#interval=1000
#[app_R]
#command=/home/simon/.i3/bar/src/app.php "R" "xdg-open https://redmine.like-inn-developpement.com/client" '#ff4e51'
#format=json
#interval=1000
[volume] [volume]
command=/home/simon/.i3/bar/src/volume.php command=/home/simon/.i3/bar/src/volume.php
@ -120,20 +88,32 @@ format=json
markup=pango markup=pango
interval=3 interval=3
[app_C]
command=/home/simon/.i3/bar/src/app.php C "xdg-open https://cloud.deblan.org/nc/" '#5d5d7d' '#fff'
format=json
markup=pango
interval=1000
[app_Y]
command=/home/simon/.i3/bar/src/app.php Y "xdg-open https://www.youtube.com/feed/subscriptions" '#c74a42' '#fff'
format=json
markup=pango
interval=1000
[time] [time]
command=/home/simon/.i3/bar/src/time.php command=/home/simon/.i3/bar/src/time.php "H:i:s d/m/Y"
format=json format=json
markup=pango markup=pango
interval=1 interval=1
[date] #[date]
command=/home/simon/.i3/bar/src/date.php #command=/home/simon/.i3/bar/src/date.php
format=json #format=json
markup=pango #markup=pango
interval=30 #interval=30
[rss] [rss]
command=/home/simon/.i3/bar/src/rss.php "https://tiny.deblan.org/public.php?op=rss&id=-3&key=17c659af1ad27f30941a724fcf48421d1e83081a" "RSS" command=/home/simon/.i3/bar/src/rss.php "https://tiny.deblan.org/public.php?op=rss&id=-3&key=17c659af1ad27f30941a724fcf48421d1e83081a" "https://tiny.deblan.org/"
align=left align=left
interval=30 interval=30
format=json format=json

View file

@ -16,28 +16,37 @@ if (!preg_match('`Discharging`', $acpi)) {
} }
if ($charging < 20) { if ($charging < 20) {
$color = color('critical'); $foreground = '#333';
$background = color('critical');
} elseif ($charging < 50) { } elseif ($charging < 50) {
$color = color('warning'); $foreground = color('info');
$background = color('warning');
} else { } else {
$color = color('normal'); $foreground = '#333';
$background = color('normal');
} }
$charging .= '%↑'; $charging .= '% '.emoji(0xf0aa);
$text = span(' '.$charging.' ', $foreground, $background);
$block = block( $block = block(
'acpi', 'acpi',
[ [
'full_text' => $charging, 'full_text' => $text,
'color' => $color, 'color' => $color,
'separator' => false,
'separator_block_width' => 0,
] ]
); );
} else { } else {
$block = block( $block = block(
'acpi', 'acpi',
[ [
'full_text' => '??? ', 'full_text' => '??? '.emoji(0xf0aa),
'color' => color('info'), 'color' => color('info'),
'separator' => false,
'separator_block_width' => 0,
] ]
); );
} }
@ -45,22 +54,27 @@ if (!preg_match('`Discharging`', $acpi)) {
preg_match('`([0-9]+%), ([0-9]+:[0-9]+)`', $acpi, $values); preg_match('`([0-9]+%), ([0-9]+:[0-9]+)`', $acpi, $values);
if ($values[0] < 20) { if ($values[0] < 20) {
$color = color('critical'); $foreground = '#333';
$background = color('critical');
} elseif ($values[0] < 50) { } elseif ($values[0] < 50) {
$color = color('warning'); $foreground = color('info');
$background = color('warning');
} else { } else {
$color = color('info'); $foreground = '#333';
$background = color('normal');
} }
$charging = $values[1].'↓'; $charging = $values[1];
$times = str_replace(':', 'h', $values[2]); $times = str_replace(':', 'h', $values[2]);
$text = implode(' ', [$charging, $times]); $text = span(' '.implode(' ', [$charging, $times, emoji(0xf0ab)]).' ', $foreground, $background);
$block = block( $block = block(
'acpi', 'acpi',
[ [
'full_text' => $text, 'full_text' => $text,
'color' => $color, 'color' => $color,
'separator' => false,
'separator_block_width' => 0,
] ]
); );
} }

View file

@ -5,16 +5,13 @@ require __DIR__.'/base/block.php';
$name = $argv[1] ?? null; $name = $argv[1] ?? null;
$app = $argv[2] ?? null; $app = $argv[2] ?? null;
$background = $argv[3]; $background = $argv[3] ?? '#333';
$foreground = $argv[4]; $foreground = $argv[4] ?? '#fff';
$separator = (bool) ($argv[5] ?? true);
if (empty($name) && empty($app)) { if (empty($name) && empty($app)) {
die; die;
} }
$fullText = sprintf(' %s ', $name);
if (getenv('BLOCK_BUTTON') === '1') { if (getenv('BLOCK_BUTTON') === '1') {
pclose(popen($app, 'r')); pclose(popen($app, 'r'));
} }
@ -22,10 +19,6 @@ if (getenv('BLOCK_BUTTON') === '1') {
echo block( echo block(
'app_'.$name, 'app_'.$name,
[ [
'full_text' => span($fullText, $foreground, $background), 'full_text' => pspan($name, $foreground, $background),
//'separator' => $separator,
//'separator_block_width' => $separator ? 20 : 0,
'separator' => false,
'separator_block_width' => 0,
] ]
); );

View file

@ -1,4 +1,4 @@
#!/usr/bin/php #!/usr/bin/php7.1
<?php <?php
require __DIR__.'/base/block.php'; require __DIR__.'/base/block.php';
@ -18,21 +18,20 @@ if (empty($ip)) {
die; die;
} }
$bwidth = explode(' ', preg_replace('/ +/', ' ', trim(shell_exec('ifstat -i '.escapeshellcmd($iface).' 1 1 | tail -n 1')))); $bwidth = explode(' ', preg_replace('/ +/', ' ', trim(shell_exec('ifstat -i '.escapeshellcmd($iface).' 0.1 1 | tail -n 1'))));
if (empty($bwidth)) { if (empty($bwidth)) {
die; die;
} }
$fullText = span(' '.$iface.' ', '#ccc', '#222').span(' '.$bwidth[0].'Ko/s↓ '.$bwidth[1].'Ko/s↑', '#ddd', '#000').' '; $up = $bwidth[1].'Ko/s'.pemoji(0xf0aa);
$down = pemoji(0xf0ab).$bwidth[0].'Ko/s ';
$fullText = pspan($iface, '#ccc', '#222').pspan($down.$up, '#ddd', '#000');
echo block( echo block(
'bandwidth_'.$iface, 'bandwidth_'.$iface,
[ [
'full_text' => $fullText, 'full_text' => $fullText,
'color' => '#ffffff',
'urgent' => 1,
'separator' => false,
'separator_block_width' => 0,
] ]
); );

View file

@ -10,7 +10,7 @@
function color($label) function color($label)
{ {
$colors = [ $colors = [
'music' => '#C3D4FF', 'music' => '#cccccc',
'date' => '#E9F1FF', 'date' => '#E9F1FF',
'info' => '#E9F1FF', 'info' => '#E9F1FF',
'critical' => '#FF474A', 'critical' => '#FF474A',
@ -21,6 +21,40 @@ function color($label)
return $colors[$label] ?? $colors['info']; return $colors[$label] ?? $colors['info'];
} }
/**
* Create emoji with padding.
*
* @param mixed $char
*/
function pemoji($char)
{
return '<span font=\'FontAwesome\'> '.IntlChar::chr($char).' </span>';
}
/**
* Create emoji.
*
* @param mixed $char
*/
function emoji($char)
{
return '<span font=\'FontAwesome\'>'.IntlChar::chr($char).'</span>';
}
/**
* Creates span with padding.
*
* @param string $text
* @param string $foreground
* @param string $background
*
* @return string
*/
function pspan($text, $foreground = null, $background = null)
{
return span(sprintf(' %s ', $text), $foreground, $background);
}
/** /**
* Creates span. * Creates span.
* *
@ -56,8 +90,8 @@ function block(string $name, array $options = [])
'align' => 'left', 'align' => 'left',
'name' => $name, 'name' => $name,
'urgent' => false, 'urgent' => false,
'separator' => true, 'separator' => false,
'separator_block_width' => 20, 'separator_block_width' => 0,
], ],
$options $options
); );

View file

@ -1,11 +1,11 @@
#!/usr/bin/php #!/usr/bin/php7.1
<?php <?php
require __DIR__.'/base/block.php'; require __DIR__.'/base/block.php';
$format = $argv[1] ?? 'd/m/Y'; $format = $argv[1] ?? 'd/m/Y';
$fullText = span(' '.date($format).' ', color('date'), '#444'); $fullText = span(' '.emoji(0xf073).' '.date($format).' ', color('date'), '#444');
if (getenv('BLOCK_BUTTON') === '1') { if (getenv('BLOCK_BUTTON') === '1') {
shell_exec('i3-msg \'workspace "3. MAIL"\''); shell_exec('i3-msg \'workspace "3. MAIL"\'');

View file

@ -1,4 +1,4 @@
#!/usr/bin/php #!/usr/bin/php7.1
<?php <?php
require __DIR__.'/base/block.php'; require __DIR__.'/base/block.php';
@ -18,7 +18,7 @@ if (empty($ip)) {
die; die;
} }
$fullText = span(' '.$iface.' ', '#ccc', '#222').span(' '.$ip, '#ddd', '#000').' '; $fullText = pspan($iface, '#ccc', '#222').pspan($ip, '#ddd', '#000');
if (getenv('BLOCK_BUTTON') === '1') { if (getenv('BLOCK_BUTTON') === '1') {
shell_exec('export DISPLAY=:0; echo '.escapeshellarg($ip).' | xclip'); shell_exec('export DISPLAY=:0; echo '.escapeshellarg($ip).' | xclip');

View file

@ -22,7 +22,7 @@ if (getenv('BLOCK_BUTTON') === '1') {
shell_exec('export DISPLAY=:0; echo '.escapeshellarg($ip).' | xclip -sel clip'); shell_exec('export DISPLAY=:0; echo '.escapeshellarg($ip).' | xclip -sel clip');
} }
$fullText = span(' '.$iface.' ', '#ccc', '#222').span(' '.$ip, '#ddd', '#000').' '; $fullText = pspan($iface, '#ccc', '#222').pspan($ip, '#ddd', '#000');
echo block( echo block(
'ip_wan', 'ip_wan',

View file

@ -31,13 +31,13 @@ if ($percent < $range1) {
$color = color('critical'); $color = color('critical');
} }
$fullText = span(' '.$mountPoint.' ', '#ccc', '#222').span(' '.$percent.'% ', $color, '#000').' ';
if (getenv('BLOCK_BUTTON') === '1') { if (getenv('BLOCK_BUTTON') === '1') {
$command = 'export DISPLAY=:0; pcmanfm '.escapeshellarg('file://'.$mountPoint).'&'; $command = 'export DISPLAY=:0; pcmanfm '.escapeshellarg('file://'.$mountPoint).'&';
pclose(popen($command, 'r')); pclose(popen($command, 'r'));
} }
$fullText = pspan($mountPoint, '#ccc', '#222').pspan($percent.'%', $color, '#000');
echo block( echo block(
'mount_point_space_'.$name, 'mount_point_space_'.$name,
[ [

View file

@ -4,9 +4,9 @@
require __DIR__.'/base/block.php'; require __DIR__.'/base/block.php';
$rss = $argv[1] ?? null; $rss = $argv[1] ?? null;
$title = $argv[2] ?? null; $client = $argv[2] ?? null;
if (empty($rss) || empty($title)) { if (empty($rss)) {
die; die;
} }
@ -18,25 +18,22 @@ if (empty($content)) {
preg_match_all('/<entry/isU', $content, $matches, PREG_SET_ORDER); preg_match_all('/<entry/isU', $content, $matches, PREG_SET_ORDER);
$title = IntlChar::chr(0xf09e); $title = pemoji(0xf09e);
$count = count($matches); $count = count($matches);
if ($count > 0) { if ($count > 0) {
$title .= ' +'.$count; $title .= ' +'.$count;
} }
$fullText = span(' '.$title.' ', $count ? color('normal') : color('info'), '#333'); // sprintf('[%s] %s', $title, $count = count($matches)); $fullText = span($title, $count ? color('normal') : color('info'), '#333');
$blockButton = (int) getenv('BLOCK_BUTTON'); if ($client && (int) getenv('BLOCK_BUTTON') === 1) {
shell_exec(sprintf('xdg-open %s', escapeshellarg($client)));
if ($blockButton === 1) {
shell_exec('xdg-open "https://tiny.deblan.org/index.php"');
} }
echo block( echo block(
'rss', 'rss',
[ [
'full_text' => $fullText, 'full_text' => $fullText,
// 'color' => $count ? color('normal') : color('info'),
] ]
); );

View file

@ -11,10 +11,8 @@ if (empty($output)) {
echo block( echo block(
'screensaver', 'screensaver',
[ [
'full_text' => span(' • ', color('normal'), '#333'),//IntlChar::chr(0x1F5B5), 'full_text' => pspan(emoji(0xf108), color('normal'), '#000'),
'color' => color('normal'), 'color' => color('normal'),
'separator' => false,
'separator_block_width' => 0,
] ]
); );
@ -26,10 +24,8 @@ if (empty($output)) {
echo block( echo block(
'screensaver', 'screensaver',
[ [
'full_text' => span(' • ', color('warning'), '#333'),//IntlChar::chr(0x1F5B5), 'full_text' => pspan(emoji(0xf108), color('warning'), '#000'),
'color' => color('warning'), 'color' => color('warning'),
'separator' => false,
'separator_block_width' => 0,
] ]
); );

View file

@ -23,8 +23,7 @@ function cleanUp($d, $max = 20)
$title = cleanUp(shell_exec('playerctl -p spotify metadata xesam:title')); $title = cleanUp(shell_exec('playerctl -p spotify metadata xesam:title'));
$artist = cleanUp(shell_exec('playerctl -p spotify metadata xesam:artist')); $artist = cleanUp(shell_exec('playerctl -p spotify metadata xesam:artist'));
$label = sprintf('%s %s', $title, $artist); $fullText = pspan($artist, '#ccc', '#222').pspan($title, '#ddd', '#000');
$fullText = sprintf('%s %s', $title, $artist);
if (getenv('BLOCK_BUTTON') === '1') { if (getenv('BLOCK_BUTTON') === '1') {
shell_exec('i3-msg \'workspace "6. MEDIA"\''); shell_exec('i3-msg \'workspace "6. MEDIA"\'');
@ -35,5 +34,7 @@ echo block(
[ [
'full_text' => $fullText, 'full_text' => $fullText,
'color' => color('music'), 'color' => color('music'),
'separator' => false,
'separator_block_width' => 0,
] ]
); );

View file

@ -6,9 +6,9 @@ require __DIR__.'/base/block.php';
$status = trim(shell_exec('playerctl -p spotify status')); $status = trim(shell_exec('playerctl -p spotify status'));
if ($status === 'Playing') { if ($status === 'Playing') {
$fullText = '▮▮'; $fullText = pemoji(0xf04c);
} elseif ($status === 'Paused') { } elseif ($status === 'Paused') {
$fullText = '▶'; $fullText = pemoji(0xf04b);
} }
if (empty($fullText)) { if (empty($fullText)) {
@ -22,7 +22,7 @@ if (getenv('BLOCK_BUTTON') === '1') {
echo block( echo block(
'spotify_ctrl', 'spotify_ctrl',
[ [
'full_text' => $fullText, 'full_text' => span($fullText, '#ccc', '#000'),
'color' => color('music'), 'color' => color('music'),
] ]
); );

View file

@ -1,4 +1,4 @@
#!/usr/bin/php #!/usr/bin/php7.1
<?php <?php
require __DIR__.'/base/block.php'; require __DIR__.'/base/block.php';
@ -15,7 +15,7 @@ if (date('H:i:s') === '13:37:00') {
shell_exec('notify-send "1337" "Powaaaa" --icon=/home/simon/Images/if_geek_zombie_60815.png'); shell_exec('notify-send "1337" "Powaaaa" --icon=/home/simon/Images/if_geek_zombie_60815.png');
} }
$fullText = span(' '.$fullText.' ', color('date'), '#444'); $fullText = span(pemoji(0xf073).$fullText, color('date'), '#444');
echo block( echo block(
'time', 'time',

View file

@ -1,4 +1,4 @@
#!/usr/bin/php #!/usr/bin/php7.1
<?php <?php
require __DIR__.'/base/block.php'; require __DIR__.'/base/block.php';
@ -10,7 +10,15 @@ if ($volume) {
if (isset($mach[1])) { if (isset($mach[1])) {
$v = (int) str_replace('%', '', $mach[1]); $v = (int) str_replace('%', '', $mach[1]);
$fullText = ' '.$mach[1].' ♪ '; $fullText = ' '.$mach[1].' ';
if ($v === 0) {
$fullText.= emoji(0xf026);
} elseif ($v < 50) {
$fullText.= emoji(0xf027);
} else {
$fullText.= emoji(0xf028);
}
echo block( echo block(
'volume', 'volume',