This commit is contained in:
Pavel Korytov 2020-07-18 12:24:25 +03:00
parent f8e1ccfd17
commit 0212d5380e
11 changed files with 79 additions and 486 deletions

View file

@ -1,90 +0,0 @@
#!/bin/bash
# Copyright (C) 2012 Stefan Breunig <stefan+measure-net-speed@mathphys.fsk.uni-heidelberg.de>
# Copyright (C) 2014 kaueraal
# Copyright (C) 2015 Thiago Perrotta <perrotta dot thiago at poli dot ufrj dot br>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Use the provided interface, otherwise the device used for the default route.
if [[ -n $BLOCK_INSTANCE ]]; then
INTERFACE=$BLOCK_INSTANCE
else
INTERFACE=$(ip route | awk '/^default/ { print $5 ; exit }')
fi
# Issue #36 compliant.
if ! [ -e "/sys/class/net/${INTERFACE}/operstate" ] || ! [ "`cat /sys/class/net/${INTERFACE}/operstate`" = "up" ]
then
echo "$INTERFACE down"
echo "$INTERFACE down"
echo "#FF0000"
exit 0
fi
# path to store the old results in
path="/dev/shm/$(basename $0)-${INTERFACE}"
# grabbing data for each adapter.
read rx < "/sys/class/net/${INTERFACE}/statistics/rx_bytes"
read tx < "/sys/class/net/${INTERFACE}/statistics/tx_bytes"
# get time
time=$(date +%s)
# write current data if file does not exist. Do not exit, this will cause
# problems if this file is sourced instead of executed as another process.
if ! [[ -f "${path}" ]]; then
echo "${time} ${rx} ${tx}" > "${path}"
chmod 0666 "${path}"
fi
# read previous state and update data storage
read old < "${path}"
echo "${time} ${rx} ${tx}" > "${path}"
# parse old data and calc time passed
old=(${old//;/ })
time_diff=$(( $time - ${old[0]} ))
# sanity check: has a positive amount of time passed
[[ "${time_diff}" -gt 0 ]] || exit
# calc bytes transferred, and their rate in byte/s
rx_diff=$(( $rx - ${old[1]} ))
tx_diff=$(( $tx - ${old[2]} ))
rx_rate=$(( $rx_diff / $time_diff ))
tx_rate=$(( $tx_diff / $time_diff ))
# shift by 10 bytes to get KiB/s. If the value is larger than
# 1024^2 = 1048576, then display MiB/s instead
# incoming
echo -n "IN "
rx_kib=$(( $rx_rate >> 10 ))
if [[ "$rx_rate" -gt 1048576 ]]; then
printf '%sM' "`echo "scale=1; $rx_kib / 1024" | bc`"
else
echo -n "${rx_kib}K"
fi
echo -n " "
# outgoing
echo -n "OUT "
tx_kib=$(( $tx_rate >> 10 ))
if [[ "$tx_rate" -gt 1048576 ]]; then
printf '%sM' "`echo "scale=1; $tx_kib / 1024" | bc`"
else
echo -n "${tx_kib}K"
fi

View file

@ -3,6 +3,7 @@
# Copyright 2014 Pierre Mavro <deimos@deimos.fr>
# Copyright 2014 Vivien Didelot <vivien@didelot.org>
# Copyright 2014 Andreas Guldstrand <andreas.guldstrand@gmail.com>
# Copyright 2020 Korytov Pavel <thexcloud@gmail.com>
#
# Licensed under the terms of the GNU GPL v3, or any later version.
@ -27,6 +28,13 @@ GetOptions("help|h" => \&help,
"w=i" => \$t_warn,
"c=i" => \$t_crit);
# Clicked on block
if (defined $ENV{'BLOCK_BUTTON'}) {
if ($ENV{'BLOCK_BUTTON'} == "1") {
exec('i3-sensible-terminal -e htop')
}
}
# Get CPU usage
$ENV{LC_ALL}="en_US"; # if mpstat is not run under en_US locale, things may break, so make sure it is
open (MPSTAT, 'mpstat 1 1 |') or die;

View file

@ -1,61 +0,0 @@
#!/bin/bash
# Copyright (C) 2014 Julien Bonjean <julien@bonjean.info>
# Copyright (C) 2014 Alexander Keller <github@nycroth.com>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#------------------------------------------------------------------------
# Use the provided interface, otherwise the device used for the default route.
if [[ -n $BLOCK_INSTANCE ]]; then
IF=$BLOCK_INSTANCE
else
IF=$(ip route | awk '/^default/ { print $5 ; exit }')
fi
#------------------------------------------------------------------------
# As per #36 -- It is transparent: e.g. if the machine has no battery or wireless
# connection (think desktop), the corresponding block should not be displayed.
[[ ! -d /sys/class/net/${IF} ]] && exit
#------------------------------------------------------------------------
if [[ "$(cat /sys/class/net/$IF/operstate)" = 'down' ]]; then
echo down # full text
echo down # short text
echo \#FF0000 # color
exit
fi
case $1 in
-4)
AF=inet ;;
-6)
AF=inet6 ;;
*)
AF=inet6? ;;
esac
# if no interface is found, use the first device with a global scope
IPADDR=$(ip addr show $IF | perl -n -e "/$AF ([^\/]+).* scope global/ && print \$1 and exit")
case $BLOCK_BUTTON in
3) echo -n "$IPADDR" | xclip -q -se c ;;
esac
#------------------------------------------------------------------------
echo "$IPADDR" # full text
echo "$IPADDR" # short text

View file

@ -1,70 +0,0 @@
#!/usr/bin/perl
#
# Copyright 2014 Marcelo Cerri <mhcerri at gmail dot com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
use strict;
use warnings;
use utf8;
use Getopt::Long;
use File::Basename;
# Default values
my $indicator = $ENV{BLOCK_INSTANCE} || "CAPS";
my $color_on = "#00FF00";
my $color_off = "#222222";
sub help {
my $program = basename($0);
printf "Usage: %s [-c <color on>] [-C <color off>]\n", $program;
printf " -c <color on>: hex color to use when indicator is on\n";
printf " -C <color off>: hex color to use when indicator is off\n";
printf "\n";
printf "Note: environment variable \$BLOCK_INSTANCE should be one of:\n";
printf " CAPS, NUM (default is CAPS).\n";
exit 0;
}
Getopt::Long::config qw(no_ignore_case);
GetOptions("help|h" => \&help,
"c=s" => \$color_on,
"C=s" => \$color_off) or exit 1;
# Key mapping
my %indicators = (
CAPS => 0x00000001,
NUM => 0x00000002,
);
# Retrieve key flags
my $mask = 0;
open(XSET, "xset -q |") or die;
while (<XSET>) {
if (/LED mask:\s*([0-9]+)/) {
$mask = $1;
last;
}
}
close(XSET);
# Output
printf "%s\n", $indicator;
printf "%s\n", $indicator;
if (($indicators{$indicator} || 0) & $mask) {
printf "%s\n", $color_on;
} else {
printf "%s\n", $color_off;
}
exit 0

View file

@ -1,149 +0,0 @@
#!/usr/bin/perl
# Made by Pierre Mavro/Deimosfr <deimos@deimos.fr>
# Licensed under the terms of the GNU GPL v3, or any later version.
# Version: 0.2
# Usage:
# 1. The configuration name of OpenVPN should be familiar for you (home,work...)
# 2. The device name in your configuration file should be fully named (tun0,tap1...not only tun or tap)
# 3. When you launch one or multiple OpenVPN connexion, be sure the PID file is written in the correct folder (ex: --writepid /run/openvpn/home.pid)
use strict;
use warnings;
use utf8;
use Getopt::Long;
my $openvpn_enabled='/dev/shm/openvpn_i3blocks_enabled';
my $openvpn_disabled='/dev/shm/openvpn_i3blocks_disabled';
# Print output
sub print_output {
my $ref_pid_files = shift;
my @pid_files = @$ref_pid_files;
my $change=0;
# Total pid files
my $total_pid = @pid_files;
if ($total_pid == 0) {
print "VPN: down\n"x2;
# Delete OpenVPN i3blocks temp files
if (-f $openvpn_enabled) {
unlink $openvpn_enabled or die "Can't delete $openvpn_enabled\n";
# Colorize if VPN has just went down
print '#FF0000\n';
}
unless (-f $openvpn_disabled) {
open(my $shm, '>', $openvpn_disabled) or die "Can't write $openvpn_disabled\n";
}
exit(0);
}
# Check if interface device is present
my $vpn_found=0;
my $pid;
my $cmd_line;
my @config_name;
my @config_path;
my $interface;
my $current_config_path;
my $current_config_name;
foreach (@pid_files) {
# Get current PID
$pid=0;
open(PID, '<', $_);
while(<PID>) {
chomp $_;
$pid = $_;
}
close(PID);
# Check if PID has been found
if ($pid ==0) {
print "Can't get PID $_: $!\n";
}
# Check if PID is still alive
$cmd_line='/proc/'.$pid.'/cmdline';
if (-f $cmd_line) {
# Get config name
open(CMD_LINE, '<', $cmd_line);
while(<CMD_LINE>) {
chomp $_;
if ($_ =~ /--config\s*(.*\.conf)/) {
# Get interface from config file
$current_config_path = $1;
# Remove unwanted escape chars
$current_config_path =~ s/\x{00}//g;
$interface = 'null';
# Get configuration name
if ($current_config_path =~ /(\w+).conf/) {
$current_config_name=$1;
} else {
$current_config_name='unknow';
}
# Get OpenVPN interface device name
open(CONFIG, '<', $current_config_path) or die "Can't read config file '$current_config_path': $!\n";
while(<CONFIG>) {
chomp $_;
if ($_ =~ /dev\s+(\w+)/) {
$interface=$1;
last;
}
}
close(CONFIG);
# check if interface exist
unless ($interface eq 'null') {
if (-d "/sys/class/net/$interface") {
push @config_name, $current_config_name;
$vpn_found=1;
# Write enabled file
unless (-f $openvpn_enabled) {
open(my $shm, '>', $openvpn_enabled) or die "Can't write $openvpn_enabled\n";
$change=1;
}
}
}
}
}
close(CMD_LINE);
}
}
# Check if PID found
my $names;
my $short_status;
if ($vpn_found == 1) {
$names = join('/', @config_name);
$short_status='up';
} else {
$short_status='down';
$names = $short_status;
}
print "VPN: $names\n";
print "VPN: $short_status\n";
# Print color if there were changes
print "#00FF00\n" if ($change == 1);
exit(0);
}
sub check_opts {
# Vars
my @pid_file=glob '/run/openvpn/*.pid';
# Set options
GetOptions( "help|h" => \&help,
"p=s" => \@pid_file);
print_output(\@pid_file);
}
sub help {
print "Usage: openvpn [-d pid folder files]\n";
print "-d : pid folder files (default /run/openvpn/*.pid)\n";
print "Note: devices in configuration file should be named with their number (ex: tun0, tap1)\n";
exit(1);
}
&check_opts;

View file

@ -1,69 +0,0 @@
#!/usr/bin/perl
# Copyright 2014 Pierre Mavro <deimos@deimos.fr>
# Copyright 2014 Vivien Didelot <vivien@didelot.org>
# Copyright 2014 Andreas Guldstrand <andreas.guldstrand@gmail.com>
# Copyright 2014 Benjamin Chretien <chretien at lirmm dot fr>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
use strict;
use warnings;
use utf8;
use Getopt::Long;
binmode(STDOUT, ":utf8");
# default values
my $t_warn = 70;
my $t_crit = 90;
my $chip = "";
my $temperature = -9999;
sub help {
print "Usage: temperature [-w <warning>] [-c <critical>] [--chip <chip>]\n";
print "-w <percent>: warning threshold to become yellow\n";
print "-c <percent>: critical threshold to become red\n";
print "--chip <chip>: sensor chip\n";
exit 0;
}
GetOptions("help|h" => \&help,
"w=i" => \$t_warn,
"c=i" => \$t_crit,
"chip=s" => \$chip);
# Get chip temperature
open (SENSORS, "sensors -u $chip |") or die;
while (<SENSORS>) {
if (/^\s+temp1_input:\s+[\+]*([\-]*\d+\.\d)/) {
$temperature = $1;
last;
}
}
close(SENSORS);
$temperature eq -9999 and die 'Cannot find temperature';
# Print short_text, full_text
print "$temperature°C\n" x2;
# Print color, if needed
if ($temperature >= $t_crit) {
print "#FF0000\n";
exit 33;
} elsif ($temperature >= $t_warn) {
print "#FFFC00\n";
}
exit 0;

6
bin/i3blocks/test_block Executable file
View file

@ -0,0 +1,6 @@
#!/bin/sh
echo "Hello"
if [ ! -z "${BLOCK_BUTTON}" ]; then
notify-send clicked $BLOCK_BUTTON
fi

View file

@ -1,6 +1,7 @@
#!/bin/bash
# Copyright (C) 2014 Julien Bonjean <julien@bonjean.info>
# Copyright (C) 2014 Alexander Keller <github@nycroth.com>
# Copyright (C) 2020 Korytov Pavel <thexcloud@gmail.com>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -62,9 +63,9 @@ format() {
#------------------------------------------------------------------------
case $BLOCK_BUTTON in
3) amixer -q -D $MIXER sset $SCONTROL $(capability) toggle ;; # right click, mute/unmute
4) amixer -q -D $MIXER sset $SCONTROL $(capability) ${STEP}+ unmute ;; # scroll up, increase
5) amixer -q -D $MIXER sset $SCONTROL $(capability) ${STEP}- unmute ;; # scroll down, decrease
1) cinnamon-settings sound > /dev/null ;;
4) ~/bin/scripts/vol volume +5% ;;
5) ~/bin/scripts/vol volume -5% ;;
esac
volume | format

16
bin/i3blocks/weather Executable file
View file

@ -0,0 +1,16 @@
#/bin/sh
bar_format="${BAR_FORMAT:-"%t"}"
location="${LOCATION:-"Saint-Petersburg"}"
format_1=${FORMAT_1:-"qF"}
format_2=${FORMAT_1:-"format=v2n"}
bar_weather=$(curl -s wttr.in/${location}?format=${bar_format})
if [ -z ${bar_weather} ]; then
exit 1
fi
echo ${bar_weather}
case $BLOCK_BUTTON in
1) i3-sensible-terminal -e "bash -c \"curl wttr.in/${location}?${format_1}; read -rsn1 -p 'Press any key to exit' \"";;
3) i3-sensible-terminal -e "bash -c \"curl wttr.in/${location}?${format_2}; read -rsn1 -p 'Press any key to exit' \"";;
esac

View file

@ -6,14 +6,11 @@ hide_edge_borders both
floating_modifier $mod
# start a terminal
bindsym $mod+Return exec gnome-terminal
bindsym $mod+Return exec "i3-msg 'workspace 1: Terminal; exec i3-sensible-terminal'"
# kill focused window
bindsym $mod+Shift+q kill
# start dmenu (a program launcher)
bindsym $mod+d exec dmenu_run
# change focus
bindsym $mod+h focus left
bindsym $mod+j focus down
@ -102,14 +99,15 @@ bindsym $mod+Shift+0 move container to workspace $w10
bindsym $mod+comma workspace prev
bindsym $mod+period workspace next
assign [class="X-terminal-emulator"] $w1
assign [class="Gnome-terminal"] $w1
assign [class="Terminal"] $w1
# assign [class="X-terminal-emulator"] $w1
# assign [class="Gnome-terminal"] $w1
# assign [class="Terminal"] $w1
assign [class="qutebrowser"] $w2
assign [class="VK"] $w3
assign [class="Slack"] $w3
assign [class="Postman"] $w4
assign [class="Chromium-browse"] $w4
assign [class="google-chrome"] $w4
assign [class="Electron"] $w4
assign [class="Google Play Music Desktop Player"] $w9
assign [class="jetbrains-datagrip"] $w4
@ -171,11 +169,19 @@ mode "move" {
bindsym Escape mode "default"
}
# dmenu
bindsym $mod+d exec i3-dmenu-desktop --dmenu="dmenu -l 10"
bindsym $mod+x mode "dmenu"
mode "dmenu" {
bindsym d exec i3-dmenu-desktop --dmenu="dmenu -l 10"; mode default
bindsym p exec dmenu_run -l 10; mode default
bindsym Escape mode "default"
}
# Start i3bar to display a workspace bar (plus the system information i3status
# finds out, if available)
exec ulauncher
bindsym $mod+Shift+x exec "i3lock -f -i /home/pavel/Pictures/lock-wallpaper.png"
# Colors
@ -208,9 +214,9 @@ bar {
# Pulse Audio controls
bindsym XF86AudioRaiseVolume exec --no-startup-id ~/Scripts/vol.sh volume +5% #increase sound volume
bindsym XF86AudioLowerVolume exec --no-startup-id ~/Scripts/vol.sh volume -5% #decrease sound volume
bindsym XF86AudioMute exec --no-startup-id ~/Scripts/vol.sh mute # mute sound
bindsym XF86AudioRaiseVolume exec --no-startup-id "~/bin/scripts/vol volume +5% && pkill -RTMIN+2 i3blocks"
bindsym XF86AudioLowerVolume exec --no-startup-id "~/bin/scripts/vol volume -5% && pkill -RTMIN+2 i3blocks"
bindsym XF86AudioMute exec --no-startup-id "~/bin/scripts/vol mute && pkill -RTMIN+2 i3blocks"
# Media player controls
bindsym XF86AudioPlay exec playerctl play
@ -232,13 +238,16 @@ exec_always "feh --bg-scale ~/Pictures/wallpaper.jpg"
# Compton
exec compton
exec blueberry-tray
# Activity watch
exec /home/pavel/Scripts/activity_watch.sh
exec activity_watch
exec_always setxkbmap -layout us,ru
exec_always setxkbmap -model pc105 -option 'grp:win_space_toggle' -option 'grp:alt_shift_toggle'
exec_always set_layout
# Keyring
# exec --no-startup-id /usr/bin/gnome-keyring-daemon --start --components=secrets
exec --no-startup-id /usr/bin/nm-applet
# Last window
exec --no-startup-id ~/bin/scripts/last_window

View file

@ -15,67 +15,59 @@
# signal
# urgent
command=/usr/share/i3blocks/$BLOCK_NAME
command=~/bin/i3blocks/$BLOCK_NAME
separator_block_width=15
markup=none
[volume]
label=♪
label=♪
instance=Master
interval=1
signal=10
command=/usr/share/i3blocks/volume 5 pulse
interval=once
signal=2
command=~/bin/i3blocks/volume 5 pulse
[cpu_usage]
label=
label=
color=#89ddf
interval=2
separator=false
[memory]
label=
label=
separator=false
color=#82aaff
interval=10
[memory]
label=
label=
color=#ffcb6b
instance=swap
separator=false
interval=10
[temperature]
label=
color=#f07178
# separator=false
interval=10
[wifi]
# instance=wlp3s0
instance=wlx58d56e980477
label=
color=#c3e88d
interval=10
separator=false
[bandwidth]
#instance=eth0
# INLABEL=IN
[bandwidth3]
interval=persist
color=#c3e88d
# separator=false
interval=1
label=
UNIT=KB
PRINTF_COMMAND=printf "%.0f/%.0f\n", rx, wx;
# [openvpn]
# LABEL=kek
# interval=20
[battery]
label=BAT
interval=30
[weather]
LOCATION="Saint-Petersburg"
color=#FF9600
interval=3600
[uptime]
command=uptime | awk -F'( |,|:)+' '{if ($7 == "min") {print "00:"$6} else {print $6":"$7}}'
interval=10
interval=60
[time]
command=date '+%H:%M'