mirror of
https://github.com/dnlbauer/dotfiles.git
synced 2026-09-10 21:45:30 +00:00
updated
This commit is contained in:
215
.i3/config
Normal file
215
.i3/config
Normal file
@@ -0,0 +1,215 @@
|
||||
# This file has been auto-generated by i3-config-wizard(1).
|
||||
# It will not be overwritten, so edit it as you like.
|
||||
#
|
||||
# Should you change your keyboard layout somewhen, delete
|
||||
# this file and re-run i3-config-wizard(1).
|
||||
#
|
||||
|
||||
# i3 config file (v4)
|
||||
#
|
||||
# Please see http://i3wm.org/docs/userguide.html for a complete reference!
|
||||
exec xrandr --auto --output DVI-D-0 --left-of HDMI-0 --primary
|
||||
|
||||
set $mod Mod4
|
||||
|
||||
# Font for window titles. Will also be used by the bar unless a different font
|
||||
# is used in the bar {} block below. ISO 10646 = Unicode
|
||||
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
|
||||
# The font above is very space-efficient, that is, it looks good, sharp and
|
||||
# clear in small sizes. However, if you need a lot of unicode glyphs or
|
||||
# right-to-left text rendering, you should instead use pango for rendering and
|
||||
# chose a FreeType font, such as:
|
||||
font pango:Source Code Pro for Powerline, FontAwesome Regular, Icons 12.5
|
||||
|
||||
# Use Mouse+$mod to drag floating windows to their wanted position
|
||||
floating_modifier $mod
|
||||
|
||||
# start a terminal
|
||||
bindsym $mod+Return exec i3-sensible-terminal
|
||||
|
||||
# kill focused window
|
||||
bindsym $mod+Shift+q kill
|
||||
|
||||
# start dmenu (a program launcher)
|
||||
#bindsym $mod+d exec dmenu_run
|
||||
|
||||
# rofi
|
||||
bindsym $mod+Tab exec rofi -show window
|
||||
bindsym $mod+d exec "rofi -show combi -combi-modi window,drun"
|
||||
|
||||
|
||||
# There also is the (new) i3-dmenu-desktop which only displays applications
|
||||
# shipping a .desktop file. It is a wrapper around dmenu, so you need that
|
||||
# installed.
|
||||
# bindsym $mod+d exec --no-startup-id i3-dmenu-desktop
|
||||
|
||||
# change focus
|
||||
bindsym $mod+j focus left
|
||||
bindsym $mod+k focus down
|
||||
bindsym $mod+l focus up
|
||||
bindsym $mod+semicolon focus right
|
||||
|
||||
# alternatively, you can use the cursor keys:
|
||||
bindsym $mod+Left focus left
|
||||
bindsym $mod+Down focus down
|
||||
bindsym $mod+Up focus up
|
||||
bindsym $mod+Right focus right
|
||||
|
||||
# move focused window
|
||||
bindsym $mod+Shift+j move left
|
||||
bindsym $mod+Shift+k move down
|
||||
bindsym $mod+Shift+l move up
|
||||
bindsym $mod+Shift+colon move right
|
||||
|
||||
# alternatively, you can use the cursor keys:
|
||||
bindsym $mod+Shift+Left move left
|
||||
bindsym $mod+Shift+Down move down
|
||||
bindsym $mod+Shift+Up move up
|
||||
bindsym $mod+Shift+Right move right
|
||||
|
||||
# split in horizontal orientation
|
||||
bindsym $mod+h split h
|
||||
|
||||
# split in vertical orientation
|
||||
bindsym $mod+v split v
|
||||
|
||||
# enter fullscreen mode for the focused container
|
||||
bindsym $mod+f fullscreen
|
||||
|
||||
# change container layout (stacked, tabbed, toggle split)
|
||||
bindsym $mod+s layout stacking
|
||||
bindsym $mod+w layout tabbed
|
||||
bindsym $mod+e layout toggle split
|
||||
|
||||
# toggle tiling / floating
|
||||
bindsym $mod+Shift+space floating toggle
|
||||
|
||||
# change focus between tiling / floating windows
|
||||
bindsym $mod+space focus mode_toggle
|
||||
|
||||
# focus the parent container
|
||||
bindsym $mod+a focus parent
|
||||
|
||||
# focus the child container
|
||||
#bindsym $mod+d focus child
|
||||
|
||||
set $workspace1 1
|
||||
set $workspace2 2
|
||||
set $workspace3 3
|
||||
set $workspace4 4
|
||||
set $workspace5 5
|
||||
set $workspace6 6
|
||||
set $workspace7
|
||||
set $workspace8
|
||||
set $workspace9
|
||||
|
||||
# switch to workspace
|
||||
bindsym $mod+1 workspace $workspace1
|
||||
bindsym $mod+2 workspace $workspace2
|
||||
bindsym $mod+3 workspace $workspace3
|
||||
bindsym $mod+4 workspace $workspace4
|
||||
bindsym $mod+5 workspace $workspace5
|
||||
bindsym $mod+6 workspace $workspace6
|
||||
bindsym $mod+7 workspace $workspace7
|
||||
bindsym $mod+8 workspace $workspace8
|
||||
bindsym $mod+9 workspace $workspace9
|
||||
|
||||
# move focused container to workspace
|
||||
bindsym $mod+Shift+1 move container to workspace $workspace1
|
||||
bindsym $mod+Shift+2 move container to workspace $workspace2
|
||||
bindsym $mod+Shift+3 move container to workspace $workspace3
|
||||
bindsym $mod+Shift+4 move container to workspace $workspace4
|
||||
bindsym $mod+Shift+5 move container to workspace $workspace5
|
||||
bindsym $mod+Shift+6 move container to workspace $workspace6
|
||||
bindsym $mod+Shift+7 move container to workspace $workspace7
|
||||
bindsym $mod+Shift+8 move container to workspace $workspace8
|
||||
bindsym $mod+Shift+9 move container to workspace $workspace9
|
||||
|
||||
# reload the configuration file
|
||||
bindsym $mod+Shift+c reload
|
||||
# restart i3 inplace (preserves your layout/session, can be used to upgrade i3)
|
||||
bindsym $mod+Shift+r restart
|
||||
# exit i3 (logs you out of your X session)
|
||||
bindsym $mod+Shift+e exec "i3-nagbar -t warning -m 'You pressed the exit shortcut. Do you really want to exit i3? This will end your X session.' -b 'Yes, exit i3' 'i3-msg exit'"
|
||||
|
||||
# resize window (you can also use the mouse for that)
|
||||
mode "resize" {
|
||||
# These bindings trigger as soon as you enter the resize mode
|
||||
|
||||
# Pressing left will shrink the window’s width.
|
||||
# Pressing right will grow the window’s width.
|
||||
# Pressing up will shrink the window’s height.
|
||||
# Pressing down will grow the window’s height.
|
||||
bindsym j resize shrink width 10 px or 10 ppt
|
||||
bindsym k resize grow height 10 px or 10 ppt
|
||||
bindsym l resize shrink height 10 px or 10 ppt
|
||||
bindsym semicolon resize grow width 10 px or 10 ppt
|
||||
|
||||
# same bindings, but for the arrow keys
|
||||
bindsym Left resize shrink width 10 px or 10 ppt
|
||||
bindsym Down resize grow height 10 px or 10 ppt
|
||||
bindsym Up resize shrink height 10 px or 10 ppt
|
||||
bindsym Right resize grow width 10 px or 10 ppt
|
||||
|
||||
# back to normal: Enter or Escape
|
||||
bindsym Return mode "default"
|
||||
bindsym Escape mode "default"
|
||||
}
|
||||
|
||||
bindsym $mod+r mode "resize"
|
||||
|
||||
# Start i3bar to display a workspace bar (plus the system information i3status
|
||||
# finds out, if available)
|
||||
bar {
|
||||
position top
|
||||
status_command i3blocks -c ~/.i3/i3blocks.conf
|
||||
}
|
||||
|
||||
#$workspace1 output DVI-D-0
|
||||
#$workspace7 output HDMI-0
|
||||
#$workspace8 output HDMI-0
|
||||
#$workspace9 output HDMI-0
|
||||
|
||||
for_window [window_role="pop-up"] floating enable
|
||||
for_window [class="Tk"] floating enable
|
||||
for_window [title="PyMOL Viewer"] floating enable
|
||||
for_window [class="Toplevel"] floating enable
|
||||
for_window [title="VMD*"] floating enable
|
||||
for_window [title="Area per Lipid*"] floating enable
|
||||
for_window [title="MEMBPLUGIN"] floating enable
|
||||
for_window [title="Figure*"] floating enable
|
||||
for_window [window_role="conversation" class="Pidgin"] floating enable
|
||||
for_window [class="Spotify"] move to workspace $workspace8
|
||||
assign [class="Thunderbird"] → $workspace9
|
||||
assign [class="Mendeley"] → $workspace7
|
||||
#assign [class="Spotify"] → $workspace8
|
||||
assign [title="Buddy List"] → $workspace9
|
||||
exec --no-startup-id thunderbird
|
||||
exec --no-startup-id mendeleydesktop
|
||||
exec --no-startup-id spotify
|
||||
exec --no-startup-id pidgin
|
||||
|
||||
|
||||
|
||||
exec feh --bg-scale ~/wallpaper.jpg
|
||||
exec volumeicon
|
||||
exec thunar --daemon
|
||||
exec --no-startup-id xautolock -time 5 -locker 'i3lock -i ~/.lockscreen/`ls ~/lockscreens | shuf -n 1` -t -f'
|
||||
|
||||
# Pulse Audio controls
|
||||
bindsym XF86AudioRaiseVolume exec --no-startup-id amixer -D pulse sset Master 5%+ #increase sound volume
|
||||
bindsym XF86AudioLowerVolume exec --no-startup-id amixer -D pulse sset Master 5%- #decrease sound volume
|
||||
bindsym XF86AudioMute exec --no-startup-id amixer -D pulse sset Master toggle # mute sound
|
||||
|
||||
# Sreen brightness controls
|
||||
bindsym XF86MonBrightnessUp exec xbacklight -inc 20 # increase screen brightness
|
||||
bindsym XF86MonBrightnessDown exec xbacklight -dec 20 # decrease screen brightness
|
||||
|
||||
# Touchpad controls
|
||||
bindsym XF86TouchpadToggle exec /some/path/toggletouchpad.sh # toggle touchpad
|
||||
|
||||
# Media player controls
|
||||
bindsym XF86AudioPlay exec playerctl play-pause
|
||||
bindsym XF86AudioNext exec playerctl next
|
||||
bindsym XF86AudioPrev exec playerctl previous
|
||||
bindsym XF86HomePage exec "i3lock -i ~/lockscreens/`ls ~/lockscreens | shuf -n 1` -t -f"
|
||||
78
.i3/i3blocks.conf
Normal file
78
.i3/i3blocks.conf
Normal file
@@ -0,0 +1,78 @@
|
||||
command=$SCRIPT_DIR/$BLOCK_NAME
|
||||
full_text=|
|
||||
color=#BFFF00
|
||||
align=center
|
||||
separator=false
|
||||
separator_block_width=8
|
||||
markup=pango
|
||||
|
||||
[spotify]
|
||||
command=python /home/bauer/.i3/scripts/spotify.py
|
||||
interval=5
|
||||
label=
|
||||
|
||||
[separator]
|
||||
color=#a89984
|
||||
|
||||
[cpu_usage]
|
||||
command=/home/bauer/.i3/scripts/cpu_usage
|
||||
interval=1
|
||||
label=
|
||||
|
||||
[separator]
|
||||
color=#a89984
|
||||
|
||||
[gpu]
|
||||
command=/home/bauer/.i3/scripts/gpu
|
||||
interval=1
|
||||
label=
|
||||
|
||||
[separator]
|
||||
color=#a89984
|
||||
|
||||
[memory]
|
||||
command=/home/bauer/.i3/scripts/memory
|
||||
interval=1
|
||||
label=
|
||||
|
||||
[separator]
|
||||
color=#a89984
|
||||
|
||||
[disk]
|
||||
command=/home/bauer/.i3/scripts/disk
|
||||
interval=1
|
||||
label= HDD
|
||||
|
||||
[separator]
|
||||
color=#a89984
|
||||
|
||||
[disk]
|
||||
command=/home/bauer/.i3/scripts/ssd
|
||||
interval=1
|
||||
label= SSD
|
||||
|
||||
|
||||
[separator]
|
||||
color=#a89984
|
||||
|
||||
[date]
|
||||
command=date '+%a %d %B'
|
||||
interval=5
|
||||
|
||||
[time]
|
||||
command=date '+%R'
|
||||
interval=5
|
||||
|
||||
[separator]
|
||||
color=#a89984
|
||||
|
||||
#if you prefer automatic updating
|
||||
[volume-pulseaudio]
|
||||
command=/home/bauer/.i3/scripts/volume-pulseaudio -SF 3
|
||||
interval=persist
|
||||
|
||||
|
||||
[shutdown_menu]
|
||||
full_text=V
|
||||
command=/home/bauer/.i3/scripts/shutdown_menu -c
|
||||
|
||||
6
.i3/i3log
Normal file
6
.i3/i3log
Normal file
@@ -0,0 +1,6 @@
|
||||
11.11.2016 10:11:58 - ERROR: Using Xinerama instead of RandR. This option should be avoided at all cost because it does not refresh the list of screens, so you cannot configure displays at runtime. Please check if your driver really does not support RandR and disable this option as soon as you can.
|
||||
11.11.2016 10:11:58 - i3 4.7.2 (2014-01-23, branch "tags/4.7.2") starting
|
||||
11.11.2016 10:11:58 - Parsing configfile /home/bauer/.i3/config
|
||||
deciding for version 4 due to this line: # i3 config file (v4)
|
||||
11.11.2016 10:11:58 - [libi3] libi3/font.c Using X font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
|
||||
ERROR: Another window manager seems to be running (X error 10)
|
||||
60
.i3/scripts/cpu_usage
Executable file
60
.i3/scripts/cpu_usage
Executable file
@@ -0,0 +1,60 @@
|
||||
#!/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>
|
||||
#
|
||||
# Licensed under the terms of the GNU GPL v3, or any later version.
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
use Getopt::Long;
|
||||
|
||||
# default values
|
||||
my $t_warn = 50;
|
||||
my $t_crit = 80;
|
||||
my $cpu_usage = -1;
|
||||
my $decimals = 0;
|
||||
|
||||
sub help {
|
||||
print "Usage: cpu_usage [-w <warning>] [-c <critical>] [-d <decimals>]\n";
|
||||
print "-w <percent>: warning threshold to become yellow\n";
|
||||
print "-c <percent>: critical threshold to become red\n";
|
||||
print "-d <decimals>: Use <decimals> decimals for percentage (default is $decimals) \n";
|
||||
exit 0;
|
||||
}
|
||||
|
||||
GetOptions("help|h" => \&help,
|
||||
"w=i" => \$t_warn,
|
||||
"c=i" => \$t_crit,
|
||||
"d=i" => \$decimals,
|
||||
);
|
||||
|
||||
# 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;
|
||||
while (<MPSTAT>) {
|
||||
if (/^.*\s+(\d+\.\d+)\s+$/) {
|
||||
$cpu_usage = 100 - $1; # 100% - %idle
|
||||
last;
|
||||
}
|
||||
}
|
||||
close(MPSTAT);
|
||||
|
||||
$cpu_usage eq -1 and die 'Can\'t find CPU information';
|
||||
|
||||
# Print short_text, full_text
|
||||
printf "%.${decimals}f%%\n", $cpu_usage;
|
||||
printf "%.${decimals}f%%\n", $cpu_usage;
|
||||
|
||||
# Print color, if needed
|
||||
if ($cpu_usage >= $t_crit) {
|
||||
print "#fb4934\n";
|
||||
exit 33;
|
||||
} elsif ($cpu_usage >= $t_warn) {
|
||||
print "#fabd2f\n";
|
||||
}
|
||||
|
||||
exit 0;
|
||||
|
||||
4
.i3/scripts/current_track
Executable file
4
.i3/scripts/current_track
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
eval $($(dirname $0)/sp eval)
|
||||
echo ${SPOTIFY_ARTIST} - ${SPOTIFY_TITLE}
|
||||
42
.i3/scripts/disk
Executable file
42
.i3/scripts/disk
Executable file
@@ -0,0 +1,42 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2014 Julien Bonjean <julien@bonjean.info>
|
||||
|
||||
# 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/>.
|
||||
|
||||
DIR="/scratch"
|
||||
ALERT_LOW="${1:-10}" # color will turn red under this value (default: 10%)
|
||||
|
||||
df -h -P "$DIR" | awk -v alert_low=$ALERT_LOW '
|
||||
/\/.*/ {
|
||||
# full text
|
||||
print $4" ("$5")"
|
||||
|
||||
# short text
|
||||
print $4
|
||||
|
||||
use=$5
|
||||
|
||||
# no need to continue parsing
|
||||
exit 0
|
||||
}
|
||||
|
||||
END {
|
||||
gsub(/%$/,"",use)
|
||||
if (100 - use < alert_low) {
|
||||
# color
|
||||
print "#FF0000"
|
||||
}
|
||||
}
|
||||
'
|
||||
|
||||
12
.i3/scripts/exit_menu
Executable file
12
.i3/scripts/exit_menu
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
while [ "$select" != "NO" -a "$select" != "YES" ]; do
|
||||
select=$(echo -e 'NO\nYES' | dmenu -nb '#2f343f'
|
||||
-nf '#f3f4f5'
|
||||
-sb '#9575cd'
|
||||
-sf '#f3f4f5'
|
||||
-fn '-*-*-medium-r-normal-*-*-*-*-*-*-100-*-*' -
|
||||
i -p "Are you sure you want to logout?")
|
||||
[ -z "$select" ] && exit 0
|
||||
done
|
||||
[ "$select" = "NO" ] && exit 0
|
||||
i3-msg exit
|
||||
21
.i3/scripts/gpu
Executable file
21
.i3/scripts/gpu
Executable file
@@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
|
||||
t_warn=50
|
||||
t_crit=70
|
||||
|
||||
GPU=$(nvidia-smi -q | grep Gpu | awk '{print $3}')
|
||||
|
||||
if [ $GPU -gt $t_crit ]
|
||||
then
|
||||
printf " %d%%" "$GPU"
|
||||
printf "\n %d%%" "$GPU"
|
||||
printf "\n#fb4934\n"
|
||||
elif [ $GPU -gt $t_warn ]
|
||||
then
|
||||
printf " %d%%" "$GPU"
|
||||
printf "\n %d%%" "$GPU"
|
||||
printf "\n#fabd2f\n"
|
||||
else
|
||||
printf " %d%%" "$GPU"
|
||||
printf "\n %d%%" "$GPU"
|
||||
fi
|
||||
1
.i3/scripts/keyboard_layout
Executable file
1
.i3/scripts/keyboard_layout
Executable file
@@ -0,0 +1 @@
|
||||
xkb-switch
|
||||
35
.i3/scripts/load_average
Executable file
35
.i3/scripts/load_average
Executable file
@@ -0,0 +1,35 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2014 Julien Bonjean <julien@bonjean.info>
|
||||
|
||||
# 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/>.
|
||||
|
||||
load="$(cut -d ' ' -f1 /proc/loadavg)"
|
||||
cpus="$(nproc)"
|
||||
|
||||
# full text
|
||||
echo "$load"
|
||||
|
||||
# short text
|
||||
echo "$load"
|
||||
|
||||
# color if load is too high
|
||||
awk -v cpus=$cpus -v cpuload=$load '
|
||||
BEGIN {
|
||||
if (cpus <= cpuload) {
|
||||
print "#FF0000";
|
||||
exit 33;
|
||||
}
|
||||
}
|
||||
'
|
||||
|
||||
67
.i3/scripts/memory
Executable file
67
.i3/scripts/memory
Executable file
@@ -0,0 +1,67 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2014 Julien Bonjean <julien@bonjean.info>
|
||||
|
||||
# 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/>.
|
||||
|
||||
TYPE="${BLOCK_INSTANCE:-mem}"
|
||||
|
||||
awk -v type=$TYPE '
|
||||
/^MemTotal:/ {
|
||||
mem_total=$2
|
||||
}
|
||||
/^MemFree:/ {
|
||||
mem_free=$2
|
||||
}
|
||||
/^Buffers:/ {
|
||||
mem_free+=$2
|
||||
}
|
||||
/^Cached:/ {
|
||||
mem_free+=$2
|
||||
}
|
||||
/^SwapTotal:/ {
|
||||
swap_total=$2
|
||||
}
|
||||
/^SwapFree:/ {
|
||||
swap_free=$2
|
||||
}
|
||||
END {
|
||||
if (type == "swap") {
|
||||
free=swap_free/1024/102
|
||||
used=(swap_total-swap_free)/1024/1024
|
||||
total=swap_total/1024/1024
|
||||
} else {
|
||||
free=mem_free/1024/1024
|
||||
used=(mem_total-mem_free)/1024/1024
|
||||
total=mem_total/1024/1024
|
||||
}
|
||||
pct=used/total*100
|
||||
|
||||
# full text
|
||||
printf("%.1fG / %.1fG ( %.f%% )\n", used, total, pct)
|
||||
|
||||
# short text
|
||||
printf("%.f%%\n", pct)
|
||||
|
||||
# color
|
||||
if (pct > 90) {
|
||||
print("#E53935\n")
|
||||
|
||||
} else if (pct > 80) {
|
||||
print("#FFAE00\n")
|
||||
} else if (pct > 70) {
|
||||
print("#FFF600\n")
|
||||
}
|
||||
}
|
||||
' /proc/meminfo
|
||||
|
||||
151
.i3/scripts/openvpn
Executable file
151
.i3/scripts/openvpn
Executable file
@@ -0,0 +1,151 @@
|
||||
#!/usr/bin/perl
|
||||
# Made by Pierre Mavro/Deimosfr <deimos@deimos.fr>
|
||||
# Minor contribution by Thor K. H. <thor@roht.no>
|
||||
# Licensed under the terms of the GNU GPL v3, or any later version.
|
||||
# Version: 0.3
|
||||
|
||||
# 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 "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 "$names\n";
|
||||
print "$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;
|
||||
|
||||
186
.i3/scripts/shutdown_menu
Executable file
186
.i3/scripts/shutdown_menu
Executable file
@@ -0,0 +1,186 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Use rofi/zenity to change system runstate thanks to systemd.
|
||||
#
|
||||
# Note: this currently relies on associative array support in the shell.
|
||||
#
|
||||
# Inspired from i3pystatus wiki:
|
||||
# https://github.com/enkore/i3pystatus/wiki/Shutdown-Menu
|
||||
#
|
||||
# Copyright 2015 Benjamin Chrétien <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/>.
|
||||
|
||||
#######################################################################
|
||||
# BEGIN CONFIG #
|
||||
#######################################################################
|
||||
|
||||
# Use a custom lock script
|
||||
#LOCKSCRIPT="i3lock-extra -m pixelize"
|
||||
|
||||
# Colors: FG (foreground), BG (background), HL (highlighted)
|
||||
FG_COLOR="#bbbbbb"
|
||||
BG_COLOR="#111111"
|
||||
HLFG_COLOR="#111111"
|
||||
HLBG_COLOR="#bbbbbb"
|
||||
BORDER_COLOR="#222222"
|
||||
|
||||
# Options not related to colors
|
||||
ROFI_TEXT="Menu:"
|
||||
ROFI_OPTIONS="-width -11 -location 3 -hide-scrollbar -bw 2"
|
||||
|
||||
# Zenity options
|
||||
ZENITY_TITLE="Menu"
|
||||
ZENITY_TEXT="Action:"
|
||||
ZENITY_OPTIONS="--column= --hide-header"
|
||||
|
||||
#######################################################################
|
||||
# END CONFIG #
|
||||
#######################################################################
|
||||
|
||||
# Whether to ask for user's confirmation
|
||||
enable_confirmation=false
|
||||
|
||||
# Preferred launcher if both are available
|
||||
preferred_launcher="rofi"
|
||||
|
||||
usage="$(basename "$0") [-h] [-c] [-p name] -- display a menu for shutdown, reboot, lock etc.
|
||||
|
||||
where:
|
||||
-h show this help text
|
||||
-c ask for user confirmation
|
||||
-p preferred launcher (rofi or zenity)
|
||||
|
||||
This script depends on:
|
||||
- systemd,
|
||||
- i3,
|
||||
- rofi or zenity."
|
||||
|
||||
# Check whether the user-defined launcher is valid
|
||||
launcher_list=(rofi zenity)
|
||||
function check_launcher() {
|
||||
if [[ ! "${launcher_list[@]}" =~ (^|[[:space:]])"$1"($|[[:space:]]) ]]; then
|
||||
echo "Supported launchers: ${launcher_list[*]}"
|
||||
exit 1
|
||||
else
|
||||
# Get array with unique elements and preferred launcher first
|
||||
# Note: uniq expects a sorted list, so we cannot use it
|
||||
i=1
|
||||
launcher_list=($(for l in "$1" "${launcher_list[@]}"; do printf "%i %s\n" "$i" "$l"; let i+=1; done \
|
||||
| sort -uk2 | sort -nk1 | cut -d' ' -f2- | tr '\n' ' '))
|
||||
fi
|
||||
}
|
||||
|
||||
# Parse CLI arguments
|
||||
while getopts "hcp:" option; do
|
||||
case "${option}" in
|
||||
h) echo "${usage}"
|
||||
exit 0
|
||||
;;
|
||||
c) enable_confirmation=true
|
||||
;;
|
||||
p) preferred_launcher="${OPTARG}"
|
||||
check_launcher "${preferred_launcher}"
|
||||
;;
|
||||
*) exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Check whether a command exists
|
||||
function command_exists() {
|
||||
command -v "$1" &> /dev/null 2>&1
|
||||
}
|
||||
|
||||
# systemctl required
|
||||
if ! command_exists systemctl ; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# menu defined as an associative array
|
||||
typeset -A menu
|
||||
|
||||
# Menu with keys/commands
|
||||
menu=(
|
||||
[Shutdown]="systemctl poweroff"
|
||||
[Reboot]="systemctl reboot"
|
||||
[Hibernate]="systemctl hibernate"
|
||||
[Suspend]="systemctl suspend"
|
||||
[Halt]="systemctl halt"
|
||||
[Lock]="${LOCKSCRIPT:-i3lock --color=${BG_COLOR#"#"}}"
|
||||
[Logout]="i3-msg exit"
|
||||
[Cancel]=""
|
||||
)
|
||||
menu_nrows=${#menu[@]}
|
||||
|
||||
# Menu entries that may trigger a confirmation message
|
||||
menu_confirm="Shutdown Reboot Hibernate Suspend Halt Logout"
|
||||
|
||||
launcher_exe=""
|
||||
launcher_options=""
|
||||
rofi_colors=""
|
||||
|
||||
function prepare_launcher() {
|
||||
if [[ "$1" == "rofi" ]]; then
|
||||
rofi_colors="-bc ${BORDER_COLOR} -bg ${BG_COLOR} -fg ${FG_COLOR} \
|
||||
-hlfg ${HLFG_COLOR} -hlbg ${HLBG_COLOR}"
|
||||
launcher_exe="rofi"
|
||||
launcher_options="-dmenu -i -lines ${menu_nrows} -p ${ROFI_TEXT} \
|
||||
${rofi_colors} ${ROFI_OPTIONS}"
|
||||
elif [[ "$1" == "zenity" ]]; then
|
||||
launcher_exe="zenity"
|
||||
launcher_options="--list --title=${ZENITY_TITLE} --text=${ZENITY_TEXT} \
|
||||
${ZENITY_OPTIONS}"
|
||||
fi
|
||||
}
|
||||
|
||||
for l in "${launcher_list[@]}"; do
|
||||
if command_exists "${l}" ; then
|
||||
prepare_launcher "${l}"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# No launcher available
|
||||
if [[ -z "${launcher_exe}" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
launcher="${launcher_exe} ${launcher_options}"
|
||||
selection="$(printf '%s\n' "${!menu[@]}" | sort | ${launcher})"
|
||||
|
||||
function ask_confirmation() {
|
||||
if [ "${launcher_exe}" == "rofi" ]; then
|
||||
confirmed=$(echo -e "Yes\nNo" | rofi -dmenu -i -lines 2 -p "${selection}?" \
|
||||
${rofi_colors} ${ROFI_OPTIONS})
|
||||
[ "${confirmed}" == "Yes" ] && confirmed=0
|
||||
elif [ "${launcher_exe}" == "zenity" ]; then
|
||||
zenity --question --text "Are you sure you want to ${selection,,}?"
|
||||
confirmed=$?
|
||||
fi
|
||||
|
||||
if [ "${confirmed}" == 0 ]; then
|
||||
i3-msg -q "exec ${menu[${selection}]}"
|
||||
fi
|
||||
}
|
||||
|
||||
if [[ $? -eq 0 && ! -z ${selection} ]]; then
|
||||
if [[ "${enable_confirmation}" = true && \
|
||||
${menu_confirm} =~ (^|[[:space:]])"${selection}"($|[[:space:]]) ]]; then
|
||||
ask_confirmation
|
||||
else
|
||||
i3-msg -q "exec ${menu[${selection}]}"
|
||||
fi
|
||||
fi
|
||||
|
||||
22
.i3/scripts/song.awk
Executable file
22
.i3/scripts/song.awk
Executable file
@@ -0,0 +1,22 @@
|
||||
/string *"xesam:artist/{
|
||||
while (1) {
|
||||
getline line
|
||||
if (line ~ /string "/) {
|
||||
sub(/.*string "/, "artist:", line)
|
||||
sub(/".*$/, "", line)
|
||||
print line
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
/string *"xesam:title/{
|
||||
while(1) {
|
||||
getline line
|
||||
if (line ~ /string "/) {
|
||||
sub(/.*string "/, "title:", line)
|
||||
sub(/".*$/, "", line)
|
||||
print line
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
12
.i3/scripts/spotify.py
Executable file
12
.i3/scripts/spotify.py
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import dbus
|
||||
try:
|
||||
bus = dbus.SessionBus()
|
||||
spotify = bus.get_object("org.mpris.MediaPlayer2.spotify", "/org/mpris/MediaPlayer2")
|
||||
spotify_iface = dbus.Interface(spotify, 'org.freedesktop.DBus.Properties')
|
||||
props = spotify_iface.Get('org.mpris.MediaPlayer2.Player', 'Metadata')
|
||||
print(str(props['xesam:artist'][0]) + " - " + str(props['xesam:title']))
|
||||
exit
|
||||
except dbus.exceptions.DBusException:
|
||||
exit
|
||||
40
.i3/scripts/spotify_control
Executable file
40
.i3/scripts/spotify_control
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ $# -lt 1 ]
|
||||
then
|
||||
echo "No command?"
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ "$(pidof spotify)" = "" ]
|
||||
then
|
||||
echo "Spotify is not running"
|
||||
exit
|
||||
fi
|
||||
|
||||
case $1 in
|
||||
"play")
|
||||
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause
|
||||
;;
|
||||
"next")
|
||||
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next
|
||||
;;
|
||||
"prev")
|
||||
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous
|
||||
;;
|
||||
"getTitle")
|
||||
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata'|egrep -A 1 "title"|egrep -v "title"|cut -b 44-|cut -d '"' -f 1|egrep -v ^$
|
||||
;;
|
||||
"getArtist")
|
||||
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata'|egrep -A 2 "artist"|egrep -v "artist"|egrep -v "array"|cut -b 27-|cut -d '"' -f 1|egrep -v ^$
|
||||
;;
|
||||
"getAlbum")
|
||||
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata'|egrep -A 2 "album"|egrep -v "album"|egrep -v "array"|cut -b 44-|cut -d '"' -f 1|egrep -v ^$
|
||||
;;
|
||||
"getStatus")
|
||||
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'PlaybackStatus'|grep 'string "[^"]*"'|sed 's/.*"\(.*\)"[^"]*$/\1/'
|
||||
;;
|
||||
*)
|
||||
echo "Unknown command: " $1
|
||||
;;
|
||||
esac
|
||||
40
.i3/scripts/spotify_control.bck
Executable file
40
.i3/scripts/spotify_control.bck
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ $# -lt 1 ]
|
||||
then
|
||||
echo "No command?"
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ "$(pidof spotify)" = "" ]
|
||||
then
|
||||
echo "Spotify is not running"
|
||||
exit
|
||||
fi
|
||||
|
||||
case $1 in
|
||||
"play")
|
||||
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause
|
||||
;;
|
||||
"next")
|
||||
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next
|
||||
;;
|
||||
"prev")
|
||||
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous
|
||||
;;
|
||||
"getTitle")
|
||||
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata'|egrep -A 1 "title"|egrep -v "title"|cut -b 44-|cut -d '"' -f 1|egrep -v ^$
|
||||
;;
|
||||
"getArtist")
|
||||
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata'|egrep -A 2 "artist"|egrep -v "artist"|egrep -v "array"|cut -b 27-|cut -d '"' -f 1|egrep -v ^$
|
||||
;;
|
||||
"getAlbum")
|
||||
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata'|egrep -A 2 "album"|egrep -v "album"|egrep -v "array"|cut -b 44-|cut -d '"' -f 1|egrep -v ^$
|
||||
;;
|
||||
"getStatus")
|
||||
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'PlaybackStatus'|grep 'string "[^"]*"'|sed 's/.*"\(.*\)"[^"]*$/\1/'
|
||||
;;
|
||||
*)
|
||||
echo "Unknown command: " $1
|
||||
;;
|
||||
esac
|
||||
41
.i3/scripts/ssd
Executable file
41
.i3/scripts/ssd
Executable file
@@ -0,0 +1,41 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2014 Julien Bonjean <julien@bonjean.info>
|
||||
|
||||
# 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/>.
|
||||
|
||||
DIR="/"
|
||||
ALERT_LOW="${1:-10}" # color will turn red under this value (default: 10%)
|
||||
|
||||
df -h -P "$DIR" | awk -v alert_low=$ALERT_LOW '
|
||||
/\/.*/ {
|
||||
# full text
|
||||
print $4" ("$5")"
|
||||
|
||||
# short text
|
||||
print $4
|
||||
use=$5
|
||||
|
||||
# no need to continue parsing
|
||||
exit 0
|
||||
}
|
||||
|
||||
END {
|
||||
gsub(/%$/,"",use)
|
||||
if (100 - use < alert_low) {
|
||||
# color
|
||||
print "#FF0000"
|
||||
}
|
||||
}
|
||||
'
|
||||
|
||||
4
.i3/scripts/tmux
Executable file
4
.i3/scripts/tmux
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
tmux list-sessions | wc -l
|
||||
|
||||
46
.i3/scripts/volume
Executable file
46
.i3/scripts/volume
Executable file
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
## The sink we are interested in should be given as the
|
||||
## 1st argument to the script.
|
||||
my $sink=$ARGV[0] || die("Need a sink number as the first argument\n");
|
||||
|
||||
## If the script has been run with a second argument,
|
||||
## that argument will be the volume threshold we are checking
|
||||
my $volume_limit=$ARGV[1]||undef;
|
||||
|
||||
## Run the pactl command and save the output in
|
||||
## ther filehandle $fh
|
||||
open(my $fh, '-|', 'pactl list sinks');
|
||||
|
||||
## Set the record separator to consecutive newlines (same as -000)
|
||||
## this means we read the info for each sink as a single "line".
|
||||
$/="\n\n";
|
||||
|
||||
## Go through the pactl output
|
||||
while (<$fh>) {
|
||||
## If this is the sink we are interested in
|
||||
if (/#$sink/) {
|
||||
## Extract the current colume of this sink
|
||||
/Volume:.*?(\d+)%/;
|
||||
my $volume=$1;
|
||||
## If the script has been run with a second argument,
|
||||
## check whether the volume is above or below that
|
||||
if ($volume_limit) {
|
||||
## If the volume os greater than or equal to the
|
||||
## value passed, print "y"
|
||||
if ($volume >= $volume_limit) {
|
||||
print "y\n";
|
||||
exit 0;
|
||||
}
|
||||
else {
|
||||
print "n\n";
|
||||
exit 1;
|
||||
}
|
||||
}
|
||||
## Else, if the script has been run with just one argument,
|
||||
## print the current volume.
|
||||
else {
|
||||
print "$volume%\n";
|
||||
}
|
||||
}#
|
||||
}
|
||||
162
.i3/scripts/volume-pulseaudio
Executable file
162
.i3/scripts/volume-pulseaudio
Executable file
@@ -0,0 +1,162 @@
|
||||
#!/bin/bash
|
||||
# Displays the default device, volume, and mute status for i3blocks
|
||||
|
||||
AUDIO_HIGH_SYMBOL=' '
|
||||
|
||||
AUDIO_MED_THRESH=50
|
||||
AUDIO_MED_SYMBOL=' '
|
||||
|
||||
AUDIO_LOW_THRESH=0
|
||||
AUDIO_LOW_SYMBOL=' '
|
||||
|
||||
AUDIO_MUTED_SYMBOL=' '
|
||||
|
||||
AUDIO_INTERVAL=5
|
||||
|
||||
DEFAULT_COLOR="#ffffff"
|
||||
MUTED_COLOR="#a0a0a0"
|
||||
|
||||
LONG_FORMAT=0
|
||||
SHORT_FORMAT=2
|
||||
USE_PERCENT=1
|
||||
USE_ALSA_NAME=0
|
||||
USE_DESCRIPTION=0
|
||||
|
||||
SUBSCRIBE=0
|
||||
|
||||
while getopts F:Sf:padH:M:L:X:T:t:C:c:i:h opt; do
|
||||
case "$opt" in
|
||||
S) SUBSCRIBE=1 ;;
|
||||
F) LONG_FORMAT="$OPTARG" ;;
|
||||
f) SHORT_FORMAT="$OPTARG" ;;
|
||||
p) USE_PERCENT=0 ;;
|
||||
a) USE_ALSA_NAME=1 ;;
|
||||
d) USE_DESCRIPTION=1 ;;
|
||||
H) AUDIO_HIGH_SYMBOL="$OPTARG" ;;
|
||||
M) AUDIO_MED_SYMBOL="$OPTARG" ;;
|
||||
L) AUDIO_LOW_SYMBOL="$OPTARG" ;;
|
||||
X) AUDIO_MUTED_SYMBOL="$OPTARG" ;;
|
||||
T) AUDIO_MED_THRESH="$OPTARG" ;;
|
||||
t) AUDIO_LOW_THRESH="$OPTARG" ;;
|
||||
C) DEFAULT_COLOR="$OPTARG" ;;
|
||||
c) MUTED_COLOR="$OPTARG" ;;
|
||||
i) AUDIO_INTERVAL="$OPTARG" ;;
|
||||
h) printf \
|
||||
"Usage: volume-pulseaudio [-S] [-F format] [-f format] [-p] [-a|-d] [-H symb] [-M symb]
|
||||
[-L symb] [-X symb] [-T thresh] [-t thresh] [-C color] [-c color] [-i inter] [-h]
|
||||
Options:
|
||||
-F, -f\tOutput format (-F long format, -f short format) to use, amonst:
|
||||
\t0\t symb vol [index:name]\t (default long)
|
||||
\t1\t symb vol [name]
|
||||
\t2\t symb vol [index]\t (default short)
|
||||
\t3\t symb vol
|
||||
-S\tSubscribe to volume events (requires persistent block, always uses long format)
|
||||
-p\tOmit the percent sign (%%) in volume
|
||||
-a\tUse ALSA name if possible
|
||||
-d\tUse device description instead of name if possible
|
||||
-H\tSymbol to use when audio level is high. Default: '$AUDIO_HIGH_SYMBOL'
|
||||
-M\tSymbol to use when audio level is medium. Default: '$AUDIO_MED_SYMBOL'
|
||||
-L\tSymbol to use when audio level is low. Default: '$AUDIO_LOW_SYMBOL'
|
||||
-X\tSymbol to use when audio is muted. Default: '$AUDIO_MUTED_SYMBOL'
|
||||
-T\tThreshold for medium audio level. Default: $AUDIO_MED_THRESH
|
||||
-t\tThreshold for low audio level. Default: $AUDIO_LOW_THRESH
|
||||
-C\tColor for non-muted audio. Default: $DEFAULT_COLOR
|
||||
-c\tColor for muted audio. Default: $MUTED_COLOR
|
||||
-i\tInterval size of volume increase/decrease. Default: $AUDIO_INTERVAL
|
||||
-h\tShow this help text
|
||||
" && exit 0;;
|
||||
esac
|
||||
done
|
||||
|
||||
function move_sinks_to_new_default {
|
||||
DEFAULT_SINK=$1
|
||||
pacmd list-sink-inputs | grep index: | grep -o '[0-9]\+' | while read SINK
|
||||
do
|
||||
pacmd move-sink-input $SINK $DEFAULT_SINK
|
||||
done
|
||||
}
|
||||
|
||||
function set_default_playback_device_next {
|
||||
inc=${1:-1}
|
||||
num_devices=$(pacmd list-sinks | grep -c index:)
|
||||
sink_arr=($(pacmd list-sinks | grep index: | grep -o '[0-9]\+'))
|
||||
default_sink_index=$(( $(pacmd list-sinks | grep index: | grep -no '*' | grep -o '^[0-9]\+') - 1 ))
|
||||
default_sink_index=$(( ($default_sink_index + $num_devices + $inc) % $num_devices ))
|
||||
default_sink=${sink_arr[$default_sink_index]}
|
||||
pacmd set-default-sink $default_sink
|
||||
move_sinks_to_new_default $default_sink
|
||||
}
|
||||
|
||||
case "$BLOCK_BUTTON" in
|
||||
1) set_default_playback_device_next ;;
|
||||
2) amixer -q -D pulse sset Master toggle ;;
|
||||
3) set_default_playback_device_next -1 ;;
|
||||
4) amixer -q -D pulse sset Master $AUDIO_INTERVAL%+ ;;
|
||||
5) amixer -q -D pulse sset Master $AUDIO_INTERVAL%- ;;
|
||||
esac
|
||||
|
||||
function print_format {
|
||||
PERCENT="%"
|
||||
[[ $USE_PERCENT == 0 ]] && PERCENT=""
|
||||
case "$1" in
|
||||
1) echo "$SYMBOL$VOL$PERCENT [$NAME]" ;;
|
||||
2) echo "$SYMBOL$VOL$PERCENT [$INDEX]";;
|
||||
3) echo "$SYMBOL$VOL$PERCENT" ;;
|
||||
*) echo "$SYMBOL$VOL$PERCENT [$INDEX:$NAME]" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
function print_block {
|
||||
for name in INDEX NAME VOL MUTED; do
|
||||
read $name
|
||||
done < <(pacmd list-sinks | grep "index:\|name:\|volume: front\|muted:" | grep -A3 '*')
|
||||
INDEX=$(echo "$INDEX" | grep -o '[0-9]\+')
|
||||
VOL=$(echo "$VOL" | grep -o "[0-9]*%" | head -1 )
|
||||
VOL="${VOL%?}"
|
||||
|
||||
NAME=$(echo "$NAME" | sed \
|
||||
's/.*<.*\.\(.*\)>.*/\1/; t;'\
|
||||
's/.*<\(.*\)>.*/\1/; t;'\
|
||||
's/.*/unknown/')
|
||||
|
||||
if [[ $USE_ALSA_NAME == 1 ]] ; then
|
||||
ALSA_NAME=$(pacmd list-sinks |\
|
||||
awk '/^\s*\*/{f=1}/^\s*index:/{f=0}f' |\
|
||||
grep "alsa.name\|alsa.mixer_name" |\
|
||||
head -n1 |\
|
||||
sed 's/.*= "\(.*\)".*/\1/')
|
||||
NAME=${ALSA_NAME:-$NAME}
|
||||
elif [[ $USE_DESCRIPTION == 1 ]] ; then
|
||||
DESCRIPTION=$(pacmd list-sinks |\
|
||||
awk '/^\s*\*/{f=1}/^\s*index:/{f=0}f' |\
|
||||
grep "device.description" |\
|
||||
head -n1 |\
|
||||
sed 's/.*= "\(.*\)".*/\1/')
|
||||
NAME=${DESCRIPTION:-$NAME}
|
||||
fi
|
||||
|
||||
if [[ $MUTED =~ "no" ]] ; then
|
||||
SYMBOL=$AUDIO_HIGH_SYMBOL
|
||||
[[ $VOL -le $AUDIO_MED_THRESH ]] && SYMBOL=$AUDIO_MED_SYMBOL
|
||||
[[ $VOL -le $AUDIO_LOW_THRESH ]] && SYMBOL=$AUDIO_LOW_SYMBOL
|
||||
COLOR=$DEFAULT_COLOR
|
||||
else
|
||||
SYMBOL=$AUDIO_MUTED_SYMBOL
|
||||
COLOR=$MUTED_COLOR
|
||||
fi
|
||||
|
||||
if [[ $SUBSCRIBE == 1 ]] ; then
|
||||
print_format "$LONG_FORMAT"
|
||||
else
|
||||
print_format "$LONG_FORMAT"
|
||||
print_format "$SHORT_FORMAT"
|
||||
echo "$COLOR"
|
||||
fi
|
||||
}
|
||||
|
||||
print_block
|
||||
if [[ $SUBSCRIBE == 1 ]] ; then
|
||||
while read -r EVENT; do
|
||||
print_block
|
||||
done < <(pactl subscribe | stdbuf -oL grep change)
|
||||
fi
|
||||
71
.i3/scripts/volume_1
Executable file
71
.i3/scripts/volume_1
Executable file
@@ -0,0 +1,71 @@
|
||||
#!/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/>.
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
# The second parameter overrides the mixer selection
|
||||
# For PulseAudio users, use "pulse"
|
||||
# For Jack/Jack2 users, use "jackplug"
|
||||
# For ALSA users, you may use "default" for your primary card
|
||||
# or you may use hw:# where # is the number of the card desired
|
||||
MIXER="default"
|
||||
[ -n "$(lsmod | grep pulse)" ] && MIXER="pulse"
|
||||
[ -n "$(lsmod | grep jack)" ] && MIXER="jackplug"
|
||||
MIXER="${2:-$MIXER}"
|
||||
|
||||
# The instance option sets the control to report and configure
|
||||
# This defaults to the first control of your selected mixer
|
||||
# For a list of the available, use `amixer -D $Your_Mixer scontrols`
|
||||
SCONTROL="${BLOCK_INSTANCE:-$(amixer -D $MIXER scontrols |
|
||||
sed -n "s/Simple mixer control '\([A-Za-z ]*\)',0/\1/p" |
|
||||
head -n1
|
||||
)}"
|
||||
|
||||
# The first parameter sets the step to change the volume by (and units to display)
|
||||
# This may be in in % or dB (eg. 5% or 3dB)
|
||||
STEP="${1:-5%}"
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
capability() { # Return "Capture" if the device is a capture device
|
||||
amixer -D $MIXER get $SCONTROL |
|
||||
sed -n "s/ Capabilities:.*cvolume.*/Capture/p"
|
||||
}
|
||||
|
||||
volume() {
|
||||
amixer -D $MIXER get $SCONTROL $(capability)
|
||||
}
|
||||
|
||||
format() {
|
||||
perl_filter='if (/.*\[(\d+%)\] (\[(-?\d+.\d+dB)\] )?\[(on|off)\]/)'
|
||||
perl_filter+='{CORE::say $4 eq "off" ? "0%" : "'
|
||||
# If dB was selected, print that instead
|
||||
perl_filter+=$([[ $STEP = *dB ]] && echo '$3' || echo '$1')
|
||||
perl_filter+='"; exit}'
|
||||
perl -ne "$perl_filter"
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
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
|
||||
esac
|
||||
|
||||
volume | format
|
||||
|
||||
3429
.i3/session
Normal file
3429
.i3/session
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user