This commit is contained in:
Simon Vieille 2017-06-19 16:36:59 +02:00
parent 36724e8dc3
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'),
]
);
}
}

56
config
View File

@ -19,8 +19,7 @@ bindsym $mod+Return exec /home/simon/bin/urxvt
bindsym $mod+Shift+A kill
# start dmenu (a program launcher)
bindsym $mod+d exec dmenu_run -nb '#333333' -nf '#ffffff' -sb '#982323' -p "$"
bindsym $mod+d exec dmenu_run -nb '#333333' -nf '#ffffff' -sb '#982323' -p "$" -fn 'Bitstream Vera Sans Mono-9'
# change focus
bindsym $mod+j focus left
@ -78,19 +77,7 @@ bindsym $mod+q focus parent
# bindsym $mod+x move workspace to output right
bindsym $mod+b workspace back_and_forth
# bindsym $mod+F1 workspace "1: IRC"
# bindsym $mod+F2 workspace "2: WWW"
# bindsym $mod+F3 workspace "3: MAIL"
# bindsym $mod+F4 workspace "4"
# bindsym $mod+F5 workspace "5"
# bindsym $mod+F6 workspace "6: MEDIA"
# bindsym $mod+F7 workspace "7"
# bindsym $mod+F8 workspace "8"
# bindsym $mod+F9 workspace "9"
# bindsym $mod+F10 workspace "10"
# bindsym $mod+F11 workspace "11"
# bindsym $mod+F12 workspace "12"
# Go to a workspace
bindsym $mod+F1 workspace "1. IRC"
bindsym $mod+F2 workspace "2. WWW"
bindsym $mod+F3 workspace "3. MAIL"
@ -98,28 +85,13 @@ bindsym $mod+F4 workspace "4"
bindsym $mod+F5 workspace "5"
bindsym $mod+F6 workspace "6. MEDIA"
bindsym $mod+F7 workspace "7: WORK"
bindsym $mod+F8 workspace "8"
bindsym $mod+F8 workspace "8: VM"
bindsym $mod+F9 workspace "9"
bindsym $mod+F10 workspace "10"
bindsym $mod+F11 workspace "11"
bindsym $mod+F12 workspace "12"
# move focused container to workspace
# bindsym $mod+Shift+F1 move container to workspace "1: IRC"
# bindsym $mod+Shift+F2 move container to workspace "2: WWW"
# bindsym $mod+Shift+F3 move container to workspace "3: MAIL"
# bindsym $mod+Shift+F4 move container to workspace "4"
# bindsym $mod+Shift+F5 move container to workspace "5"
# bindsym $mod+Shift+F6 move container to workspace "6: MEDIA"
# bindsym $mod+Shift+F7 move container to workspace "7"
# bindsym $mod+Shift+F8 move container to workspace "8"
# bindsym $mod+Shift+F9 move container to workspace "9"
# bindsym $mod+Shift+F10 move container to workspace "10"
# bindsym $mod+Shift+F11 move container to workspace "11"
# bindsym $mod+Shift+F12 move container to workspace "12"
bindsym $mod+Shift+F1 move container to workspace "1. IRC"
bindsym $mod+Shift+F2 move container to workspace "2. WWW"
bindsym $mod+Shift+F3 move container to workspace "3. MAIL"
@ -127,7 +99,7 @@ bindsym $mod+Shift+F4 move container to workspace "4"
bindsym $mod+Shift+F5 move container to workspace "5"
bindsym $mod+Shift+F6 move container to workspace "6. MEDIA"
bindsym $mod+Shift+F7 move container to workspace "7: WORK"
bindsym $mod+Shift+F8 move container to workspace "8"
bindsym $mod+Shift+F8 move container to workspace "8: VM"
bindsym $mod+Shift+F9 move container to workspace "9"
bindsym $mod+Shift+F10 move container to workspace "10"
bindsym $mod+Shift+F11 move container to workspace "11"
@ -172,12 +144,13 @@ bindsym $mod+r mode "resize"
# finds out, if available)
bar {
status_command ~/.i3/i3status.sh
#status_command ~/.i3/i3status.sh
status_command i3blocks -c /home/simon/.i3/bar/bar1.conf
position top
output eDP1
output DP1
output HDMI1
colors {
#background #111111
background #000000
@ -187,7 +160,7 @@ bar {
active_workspace #333333 #5f676a #ffffff
inactive_workspace #111111 #111111 #888888
urgent_workspace #2f343a #87af15 #ffffff
}
}
}
#bar {
@ -203,11 +176,12 @@ bar {
# active_workspace #333333 #5f676a #ffffff
# inactive_workspace #111111 #111111 #888888
# urgent_workspace #2f343a #87af15 #ffffff
# }
# }
#}
bar {
status_command ~/.i3/processList.sh
#status_command i3blocks
workspace_buttons yes
position top
tray_output none
@ -226,7 +200,7 @@ bar {
active_workspace #333333 #5f676a #ffffff
inactive_workspace #111111 #111111 #888888
urgent_workspace #2f343a #87af15 #ffffff
}
}
}
for_window [title="OBS"] floating enable
@ -244,6 +218,7 @@ for_window [title="Wicd"] floating enable
for_window [title="Qalculate!"] floating enable
for_window [title="Gnuplot"] floating enable
for_window [title="Network Connect"] floating enable
for_window [title="Android Emulator"] floating enable
for_window [title=".*"] border 1pixel
#exec utox
@ -258,7 +233,7 @@ exec alsactl init -c 1
exec volumeicon
exec /home/simon/bin/sshplus.py
exec dunst
exec /home/simon/bin/dual_screen_dp1.sh off
exec sleep 2 && /home/simon/bin/dual_screen_dp1.sh off
exec /home/simon/bin/reload_wallpaper
exec redshift-gtk -l 47.51659:6.7809
#exec pulseaudio --start
@ -266,11 +241,10 @@ exec redshift-gtk -l 47.51659:6.7809
# exec synclient MiddleButtonAreaLeft=2700
# exec synclient MiddleButtonAreaRight=3500
# exec synclient MiddleButtonAreaLeft=2700
exec xcompmgr -c
# exec xcompmgr -c
exec xbacklight + 100
# Softwares bind
bindsym Print exec ~/bin/screenshot
bindsym mod1+F10 exec ~/bin/screenshot_zone
bindsym $mod+Print exec ~/bin/upload_wall
@ -327,6 +301,8 @@ bindsym XF86Mail exec icedove
bindsym $mod+l exec mlclipboard
bindsym $mod+Shift+S exec i3-msg "sticky toggle"
# class border backgr. text indicator
client.focused #9B2A5D #000000 #ffffff #2e9ef4
client.focused_inactive #333333 #5f676a #ffffff #484e50