Ajout de confs i3blocks
This commit is contained in:
parent
6357571c07
commit
a9f933eeff
3 changed files with 211 additions and 149 deletions
180
.i3blocks/batterybar
Executable file
180
.i3blocks/batterybar
Executable file
|
@ -0,0 +1,180 @@
|
|||
#!/usr/bin/env bash
|
||||
# batterybar; displays battery percentage as a bar on i3blocks
|
||||
#
|
||||
# Copyright 2015 Keftaa <adnan.37h@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
|
||||
# the Free Software Foundation; either version 2 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, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301, USA.
|
||||
#
|
||||
#
|
||||
readarray -t output <<< $(acpi battery)
|
||||
battery_count=${#output[@]}
|
||||
|
||||
for line in "${output[@]}";
|
||||
do
|
||||
percentages+=($(echo "$line" | grep -o -m1 '[0-9]\{1,3\}%' | tr -d '%'))
|
||||
statuses+=($(echo "$line" | egrep -o -m1 'Discharging|Charging|AC|Full|Unknown'))
|
||||
remaining=$(echo "$line" | egrep -o -m1 '[0-9][0-9]:[0-9][0-9]')
|
||||
if [[ -n $remaining ]]; then
|
||||
remainings+=(" ($remaining)")
|
||||
else
|
||||
remainings+=("")
|
||||
fi
|
||||
done
|
||||
|
||||
#There are 8 colors that reflect the current battery percentage when
|
||||
#discharging
|
||||
dis_colors=("#F2777A" "#F2777A" "#F99157" "#F99157" "#FFCC66" "#FFCC66"
|
||||
"#99CC99" "#99CC99")
|
||||
charging_color="#66CCCC"
|
||||
full_color="#D3D0C8"
|
||||
ac_color="#6699CC"
|
||||
|
||||
|
||||
while getopts 1:2:3:4:5:6:7:8:c:f:a:h opt; do
|
||||
case "$opt" in
|
||||
1) dis_colors[0]="$OPTARG";;
|
||||
2) dis_colors[1]="$OPTARG";;
|
||||
3) dis_colors[2]="$OPTARG";;
|
||||
4) dis_colors[3]="$OPTARG";;
|
||||
5) dis_colors[4]="$OPTARG";;
|
||||
6) dis_colors[5]="$OPTARG";;
|
||||
7) dis_colors[6]="$OPTARG";;
|
||||
8) dis_colors[7]="$OPTARG";;
|
||||
c) charging_color="$OPTARG";;
|
||||
f) full_color="$OPTARG";;
|
||||
a) ac_color="$OPTARG";;
|
||||
h) printf "Usage: batterybar [OPTION] color
|
||||
When discharging, there are 8 [1-8] levels colors.
|
||||
You can specify custom colors, for example:
|
||||
|
||||
batterybar -1 red -2 \"#F6F6F6\" -8 green
|
||||
|
||||
You can also specify the colors for the charging, AC and
|
||||
charged states:
|
||||
|
||||
batterybar -c green -f white -a \"#EEEEEE\"\n";
|
||||
exit 0;
|
||||
esac
|
||||
done
|
||||
|
||||
end=$(($battery_count - 1))
|
||||
for i in $(seq 0 $end);
|
||||
do
|
||||
# if (( percentages[$i] > 0 && percentages[$i] < 20 )); then
|
||||
# squares="■"
|
||||
# elif (( percentages[$i] >= 20 && percentages[$i] < 40 )); then
|
||||
# squares="■■"
|
||||
# elif (( percentages[$i] >= 40 && percentages[$i] < 60 )); then
|
||||
# squares="■■■"
|
||||
# elif (( percentages[$i] >= 60 && percentages[$i] < 80 )); then
|
||||
# squares="■■■■"
|
||||
# elif (( percentages[$i] >=80 )); then
|
||||
# squares="■■■■■"
|
||||
# fi
|
||||
percents[$i]=$(( percentages[$i] / 2 ))
|
||||
(( percents > 48 )) && percents=48
|
||||
_full_squares=$(( percents[$i] /8 ))
|
||||
for t in $(seq 1 $_full_squares)
|
||||
do
|
||||
squares+="█"
|
||||
done
|
||||
|
||||
if [[ $(( percents[$i] - ( _full_squares * 8 ) )) -eq 7 ]]
|
||||
then
|
||||
squares+="▉"
|
||||
#squares+="▇"
|
||||
elif [[ $(( percents[$i] - ( _full_squares * 8 ) )) -eq 6 ]]
|
||||
then
|
||||
squares+="▊"
|
||||
#squares+="▆"
|
||||
elif [[ $(( percents[$i] - ( _full_squares * 8 ) )) -eq 5 ]]
|
||||
then
|
||||
squares+="▋"
|
||||
#squares+="▅"
|
||||
elif [[ $(( percents[$i] - ( _full_squares * 8 ) )) -eq 4 ]]
|
||||
then
|
||||
squares+="▌"
|
||||
#squares+="▄"
|
||||
elif [[ $(( percents[$i] - ( _full_squares * 8 ) )) -eq 3 ]]
|
||||
then
|
||||
squares+="▍"
|
||||
#squares+="▃"
|
||||
elif [[ $(( percents[$i] - ( _full_squares * 8 ) )) -eq 2 ]]
|
||||
then
|
||||
squares+="▎"
|
||||
#squares+="▂"
|
||||
elif [[ $(( percents[$i] - ( _full_squares * 8 ) )) -eq 1 ]]
|
||||
then
|
||||
squares+="▏"
|
||||
#squares+="▁"
|
||||
fi
|
||||
|
||||
if [[ "${statuses[$i]}" = "Unknown" ]]; then
|
||||
squares="<sup>?</sup>$squares"
|
||||
fi
|
||||
|
||||
case "${statuses[$i]}" in
|
||||
"Charging")
|
||||
color="$charging_color"
|
||||
if (( percentages[$i] <= 10 ))
|
||||
then echo 0 on > /proc/acpi/ibm/led
|
||||
fi
|
||||
;;
|
||||
"Full")
|
||||
color="$full_color"
|
||||
;;
|
||||
"AC")
|
||||
color="$ac_color"
|
||||
;;
|
||||
"Discharging"|"Unknown")
|
||||
if (( percentages[$i] >= 0 && percentages[$i] < 10 )); then
|
||||
color="${dis_colors[0]}"
|
||||
echo 0 blink > /proc/acpi/ibm/led
|
||||
elif (( percentages[$i] >= 10 && percentages[$i] < 20 )); then
|
||||
color="${dis_colors[1]}"
|
||||
elif (( percentages[$i] >= 20 && percentages[$i] < 30 )); then
|
||||
color="${dis_colors[2]}"
|
||||
elif (( percentages[$i] >= 30 && percentages[$i] < 40 )); then
|
||||
color="${dis_colors[3]}"
|
||||
elif (( percentages[$i] >= 40 && percentages[$i] < 60 )); then
|
||||
color="${dis_colors[4]}"
|
||||
elif (( percentages[$i] >= 60 && percentages[$i] < 70 )); then
|
||||
color="${dis_colors[5]}"
|
||||
elif (( percentages[$i] >= 70 && percentages[$i] < 80 )); then
|
||||
color="${dis_colors[6]}"
|
||||
elif (( percentages[$i] >= 80 )); then
|
||||
color="${dis_colors[7]}"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
_blanks=$(( 6 - ${#squares} ))
|
||||
for t in $(seq 1 $_blanks)
|
||||
do
|
||||
squares+=" "
|
||||
done
|
||||
# Print Battery number if there is more than one
|
||||
if (( $end > 0 )) ; then
|
||||
message="$message$(($i + 1)): "
|
||||
fi
|
||||
|
||||
if [[ "$BLOCK_BUTTON" -eq 1 ]]; then
|
||||
message="$message${statuses[$i]} <span foreground=\"$color\">${percentages[$i]}%${remainings[i]}</span> "
|
||||
fi
|
||||
message="$message<span foreground=\"$color\" background=\"#515151\">$squares</span>"
|
||||
done
|
||||
|
||||
echo "$message"
|
31
.i3blocks/internet
Executable file
31
.i3blocks/internet
Executable file
|
@ -0,0 +1,31 @@
|
|||
#!/bin/bash
|
||||
|
||||
color=""
|
||||
|
||||
if ! nmcli dev | grep " connecté" &>/dev/null
|
||||
then
|
||||
color="#515151"
|
||||
if [ ! -f /dev/shm/claws_offline ]
|
||||
then
|
||||
claws-mail --offline
|
||||
touch /dev/shm/claws_offline
|
||||
fi
|
||||
elif ping -c 1 93.184.216.34 -W 1 &>/dev/null
|
||||
then
|
||||
color="#99CC99"
|
||||
if [ -f /dev/shm/claws_offline ]
|
||||
then
|
||||
claws-mail --online
|
||||
rm /dev/shm/claws_offline
|
||||
fi
|
||||
else
|
||||
color="#F2777A"
|
||||
if [ ! -f /dev/shm/claws_offline ]
|
||||
then
|
||||
claws-mail --offline
|
||||
touch /dev/shm/claws_offline
|
||||
color="#FFCC66"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "<span foreground=\"$color\">█</span>"
|
|
@ -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;
|
Loading…
Reference in a new issue