aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlec Goncharow <Alec.Goncharow@gmail.com>2018-08-06 23:17:05 -0400
committerAlec Goncharow <Alec.Goncharow@gmail.com>2018-08-06 23:17:05 -0400
commit1f03f2b3ed8e9151a06bcb5635a061fb6098ea50 (patch)
tree950931c33352c55a41b49e8a80c4f76184efa56c
parentcdbc5a4a00526b9963b82efb0651f8a5c5515bb9 (diff)
Added some scripts I imported/wrote for my i3blocks
-rwxr-xr-x.config/i3blocks/scripts/arch-update.py116
-rwxr-xr-x.config/i3blocks/scripts/brightness.py42
-rwxr-xr-x.config/i3blocks/scripts/disk-io91
-rwxr-xr-x.config/i3blocks/scripts/myCalendar15
-rwxr-xr-x.config/i3blocks/scripts/old_brightness.py17
5 files changed, 281 insertions, 0 deletions
diff --git a/.config/i3blocks/scripts/arch-update.py b/.config/i3blocks/scripts/arch-update.py
new file mode 100755
index 0000000..d1b1c6f
--- /dev/null
+++ b/.config/i3blocks/scripts/arch-update.py
@@ -0,0 +1,116 @@
+#!/usr/bin/python3
+#
+# Copyright (C) 2017 Marcel Patzwahl
+# Licensed under the terms of the GNU GPL v3 only.
+#
+# i3blocks blocklet script to see the available updates of pacman and the AUR
+import subprocess
+from subprocess import check_output
+import argparse
+import re
+
+
+def create_argparse():
+ parser = argparse.ArgumentParser(description='Check for pacman updates')
+ parser.add_argument(
+ '-b',
+ '--base_color',
+ default='cyan',
+ help='base color of the output(default=cyan)'
+ )
+ parser.add_argument(
+ '-u',
+ '--updates_available_color',
+ default='yellow',
+ help='color of the output, when updates are available(default=yellow)'
+ )
+ parser.add_argument(
+ '-a',
+ '--aur',
+ action='store_true',
+ help='Include AUR packages. Attn: Yaourt must be installed'
+ )
+ parser.add_argument(
+ '-q',
+ '--quiet',
+ action='store_true',
+ help='Do not produce output when system is up to date'
+ )
+ parser.add_argument(
+ '-w',
+ '--watch',
+ nargs='*',
+ default=[],
+ help='Explicitly watch for specified packages. '
+ 'Listed elements are treated as regular expressions for matching.'
+ )
+ return parser.parse_args()
+
+
+def get_updates():
+ output = check_output(['checkupdates']).decode('utf-8')
+ if not output:
+ return []
+
+ updates = [line.split(' ')[0]
+ for line in output.split('\n')
+ if line]
+
+ return updates
+
+
+def get_aur_updates():
+ output = ''
+ try:
+ output = check_output(['yaourt', '-Qua']).decode('utf-8')
+ except subprocess.CalledProcessError as exc:
+ # yaourt exits with 1 and no output if no updates are available.
+ # we ignore this case and go on
+ if not (exc.returncode == 1 and not exc.output):
+ raise exc
+ if not output:
+ return []
+
+ aur_updates = [line.split(' ')[0]
+ for line in output.split('\n')
+ if line.startswith('aur/')]
+
+ return aur_updates
+
+
+def matching_updates(updates, watch_list):
+ matches = set()
+ for u in updates:
+ for w in watch_list:
+ if re.match(w, u):
+ matches.add(u)
+
+ return matches
+
+
+message = "<span color='{0}'>{1}</span>"
+args = create_argparse()
+
+updates = get_updates()
+if args.aur:
+ updates += get_aur_updates()
+
+update_count = len(updates)
+if update_count > 0:
+ info = '-Syu updates available: {}'.format(update_count)
+ matches = matching_updates(updates, args.watch)
+ if matches:
+ info += ' [{0}]'.format(', '.join(matches))
+ print(message.format(args.updates_available_color, info))
+
+ import os
+ if 'BLOCK_BUTTON' in os.environ:
+ button = os.environ['BLOCK_BUTTON']
+ if button is not '':
+ button = int(button)
+ if button is 1:
+ subprocess.call("termite -e 'sudo pacman -Syu' --hold",
+ shell=True)
+
+elif not args.quiet:
+ print(message.format(args.base_color, '-Syu ✓'))
diff --git a/.config/i3blocks/scripts/brightness.py b/.config/i3blocks/scripts/brightness.py
new file mode 100755
index 0000000..983a54f
--- /dev/null
+++ b/.config/i3blocks/scripts/brightness.py
@@ -0,0 +1,42 @@
+#!/usr/bin/python3
+# This script is for my i3blocks bar, its handles scrolling to change
+# brightness of monitor
+
+import subprocess
+import re
+import os
+
+display = "eDP-1"
+
+proc = subprocess.Popen("xrandr --verbose | grep Brightness", shell=True,
+ stdout=subprocess.PIPE)
+
+
+res = proc.stdout.readline().strip()
+res = str(res)
+
+num = re.compile("\d\.\d+")
+bri = num.findall(res)[0]
+
+bri = round(float(bri)*100)
+
+env = os.environ
+if 'BLOCK_BUTTON' in env:
+ button = env['BLOCK_BUTTON']
+ if button is not '':
+ button = int(button)
+ if button is 4:
+ new_bri = bri + 5
+ elif button is 5:
+ new_bri = bri - 5
+ else:
+ new_bri = bri
+
+ if new_bri <= 100 and new_bri >= 10:
+ bri = new_bri
+ new_bri = new_bri/100
+ subprocess.call(f"xrandr --output {display} --brightness {new_bri}",
+ shell=True)
+ subprocess.call(f"echo {new_bri} > ~/.last_brightness", shell=True)
+
+print(f"{bri}%")
diff --git a/.config/i3blocks/scripts/disk-io b/.config/i3blocks/scripts/disk-io
new file mode 100755
index 0000000..14ccc14
--- /dev/null
+++ b/.config/i3blocks/scripts/disk-io
@@ -0,0 +1,91 @@
+#!/usr/bin/env bash
+#
+# Copyright (C) 2016 James Murphy
+# Licensed under the terms of the GNU GPL v2 only.
+#
+# i3blocks blocklet script to monitor disk io
+
+label=""
+dt=5
+MB_only=0
+kB_only=0
+width=4
+MB_precision=1
+kB_precision=0
+regex="${BLOCK_INSTANCE:-/^(s|h)d[a-zA-Z]+/}"
+threshold=0
+warn_color="#FF0000"
+sep="/"
+unit_suffix="B/s"
+
+function list_devices {
+ echo "Devices iostat reports that match our regex:"
+ iostat | awk '$1~/^(s|h)d[a-zA-Z]+/{print $1}'
+}
+
+while getopts L:t:w:p:P:R:s:ST:C:lLMmKkh opt; do
+ case "$opt" in
+ L) label="$OPTARG" ;;
+ t) dt="$OPTARG" ;;
+ w) width="$OPTARG" ;;
+ p) kB_precision="$OPTARG" ;;
+ P) MB_precision="$OPTARG" ;;
+ R) regex="$OPTARG" ;;
+ s) sep="$OPTARG" ;;
+ S) unit_suffix="" ;;
+ T) threshold="$OPTARG" ;;
+ C) warn_color="$OPTARG" ;;
+ l) list_devices; exit 0 ;;
+ M|m) MB_only=1 ;;
+ K|k) kB_only=1 ;;
+ h) printf \
+"Usage: disk-io [-t time] [-w width] [-p kB_precision] [-P MB_precision] [-R regex] [-s separator] [-S] [-T threshold [-C warn_color]] [-k|-M] [-l] [-h]
+Options:
+-L\tLabel to put in front of the text. Default: $label
+-t\tTime interval in seconds between measurements. Default: $dt
+-w\tThe width of printed floats. Default: $width
+-p\tThe precision of kB/s floats. Default: $kB_precision
+-P\tThe precision of MB/s floats. Default: $MB_precision
+-R\tRegex that devices must match. Default: $regex
+-s\tSeparator to put between rates. Default: $sep
+-S\tShort units, omit B/s in kB/s and MB/s.
+-T\tRate in kB/s to exceed to trigger a warning. Default: not enabled
+-C\tColor to change the blocklet to warn the user. Default: $warn_color
+-l\tList devices that iostat reports
+-M\tDo not switch between MB/s and kB/s, use only MB/s
+-k\tDo not switch between MB/s and kB/s, use only kB/s
+-h\tShow this help text
+" && exit 0;;
+ esac
+done
+
+iostat -dyz "$dt" | awk -v sep="$sep" "
+ BEGIN {
+ rx = wx = 0;
+ }
+ {
+ if(\$0 == \"\") {
+ if ($threshold > 0 && (rx >= $threshold || wx >= $threshold)) {
+ printf \"<span color='$warn_color'>\";
+ }
+ printf \"$label\";
+ if(!$kB_only && ($MB_only || rx >= 1024 || wx >= 1024)) {
+ printf \"%-$width.${MB_precision}f%s%$width.${MB_precision}f M$unit_suffix\", rx/1024, sep, wx/1024;
+ }
+ else {
+ printf \"%-$width.${kB_precision}f%s%$width.${kB_precision}f k$unit_suffix\", rx, sep, wx;
+ }
+ if ($threshold > 0 && (rx >= $threshold || wx >= $threshold)) {
+ printf \"</span>\";
+ }
+ printf \"\n\";
+ fflush(stdout);
+ }
+ else if(\$1~/^Device:?/) {
+ rx = wx = 0;
+ }
+ else if(\$1~$regex) {
+ rx += \$3;
+ wx += \$4;
+ }
+ }"
diff --git a/.config/i3blocks/scripts/myCalendar b/.config/i3blocks/scripts/myCalendar
new file mode 100755
index 0000000..686fd00
--- /dev/null
+++ b/.config/i3blocks/scripts/myCalendar
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+datefmt='+%a %Y-%m-%d %H:%M:%S'
+
+while getopts "f:" opt; do
+ case $opt in
+ f) datefmt="$OPTARG" ;;
+ esac
+done
+
+case "$BLOCK_BUTTON" in 1|2|3)
+ exec termite -e "bash -c 'cal -Y'" --hold & disown
+esac
+
+date "$datefmt"
diff --git a/.config/i3blocks/scripts/old_brightness.py b/.config/i3blocks/scripts/old_brightness.py
new file mode 100755
index 0000000..993856e
--- /dev/null
+++ b/.config/i3blocks/scripts/old_brightness.py
@@ -0,0 +1,17 @@
+#!/usr/bin/python3
+
+backlight_dir = '/sys/class/backlight/intel_backlight/'
+
+brightness_file = 'brightness'
+max_brightness_file = 'max_brightness'
+
+brightness = int(open(backlight_dir + brightness_file).read())
+max_brightness = int(open(backlight_dir + max_brightness_file).read())
+
+ratio = (brightness / max_brightness)
+percent = ratio * 100
+
+round_percent = percent + 2.5
+round_percent = round_percent - round_percent%5
+
+print("{}%".format(round(round_percent)))