From ca3a844af240ca87882522d14b530e0f1a6327ef Mon Sep 17 00:00:00 2001 From: Amin Bandali Date: Tue, 6 Oct 2020 00:14:12 -0400 Subject: Move user-level configs out of rc.org I will keep rc.org around for now, only for system-level (global) config files. --- .local/bin/battery-percentage-time | 21 +++++++++++ .local/bin/emcl | 2 ++ .local/bin/my-i3status | 70 +++++++++++++++++++++++++++++++++++++ .local/bin/rofi-light | 4 +++ .local/bin/rofi-remmina | 30 ++++++++++++++++ .local/bin/toggle-presentation-mode | 2 ++ .local/bin/toggle-tablet | 31 ++++++++++++++++ .local/bin/volume-info | 8 +++++ .local/bin/zathura-sync | 7 ++++ 9 files changed, 175 insertions(+) create mode 100755 .local/bin/battery-percentage-time create mode 100755 .local/bin/emcl create mode 100755 .local/bin/my-i3status create mode 100755 .local/bin/rofi-light create mode 100755 .local/bin/rofi-remmina create mode 100755 .local/bin/toggle-presentation-mode create mode 100755 .local/bin/toggle-tablet create mode 100755 .local/bin/volume-info create mode 100755 .local/bin/zathura-sync (limited to '.local') diff --git a/.local/bin/battery-percentage-time b/.local/bin/battery-percentage-time new file mode 100755 index 0000000..690afa8 --- /dev/null +++ b/.local/bin/battery-percentage-time @@ -0,0 +1,21 @@ +#!/bin/sh +dbus_send() { + label=$1 + dbus-send --print-reply=literal --system \ + --dest=org.freedesktop.UPower \ + /org/freedesktop/UPower/devices/battery_BAT0 \ + org.freedesktop.DBus.Properties.Get \ + string:org.freedesktop.UPower.Device \ + string:"${label}" | awk '{print $3}' +} + +perc=$(dbus_send 'Percentage') +state=$(dbus_send 'State') + +if [ "$state" -eq 2 ]; then # Discharging + secs=$(dbus_send 'TimeToEmpty') +elif [ "$state" -eq 1 ]; then # Charging + secs=$(dbus_send 'TimeToFull') +fi + +printf '%s%%%%%2dh%02dm \n' "$perc" $((secs / 3600)) $((secs % 3600 / 60)) diff --git a/.local/bin/emcl b/.local/bin/emcl new file mode 100755 index 0000000..b0f2de2 --- /dev/null +++ b/.local/bin/emcl @@ -0,0 +1,2 @@ +#!/bin/sh +exec emacsclient --alternate-editor="" -c "$@" diff --git a/.local/bin/my-i3status b/.local/bin/my-i3status new file mode 100755 index 0000000..2831c15 --- /dev/null +++ b/.local/bin/my-i3status @@ -0,0 +1,70 @@ +#!/usr/bin/env python2 +# -*- coding: utf-8 -*- + +# This script is a simple wrapper which prefixes each i3status line with custom +# information. It is based on: +# https://github.com/i3/i3status/blob/master/contrib/wrapper.py +# +# In ~/.i3status.conf, add the following line: +# output_format = "i3bar" +# in the 'general' section. +# Then, in ~/.config/i3/config or ~/.config/sway/config add: +# status_command i3status | my-i3status.py +# in the 'bar' section. Make sure my-i3status.py is in $PATH. +# +# © 2012 Valentin Haenel +# © 2018 Amin Bandali +# +# This program is free software. It comes without any warranty, to the extent +# permitted by applicable law. You can redistribute it and/or modify it under +# the terms of the Do What The Fuck You Want To Public License (WTFPL), Version +# 2, as published by Sam Hocevar. See http://sam.zoy.org/wtfpl/COPYING for more +# details. + +import sys +import json +import os + +def get_nosleep(): + """ Return true if ~/.nosleep exists. """ + return os.path.isfile(os.path.expanduser("~/.nosleep")) + +def print_line(message): + """ Non-buffered printing to stdout. """ + sys.stdout.write(message + '\n') + sys.stdout.flush() + +def read_line(): + """ Interrupted respecting reader for stdin. """ + # try reading a line, removing any extra whitespace + try: + line = sys.stdin.readline().strip() + # i3status sends EOF, or an empty line + if not line: + sys.exit(3) + return line + # exit on ctrl-c + except KeyboardInterrupt: + sys.exit() + +if __name__ == '__main__': + # Skip the first line which contains the version header. + print_line(read_line()) + + # The second line contains the start of the infinite array. + print_line(read_line()) + + while True: + line, prefix = read_line(), '' + # ignore comma at start of lines + if line.startswith(','): + line, prefix = line[1:], ',' + + if get_nosleep(): + j = json.loads(line) + # insert information into the start of the json, but could be anywhere + j.insert(0, {'full_text' : '•', 'name' : 'nosleep'}) + # and echo back new encoded json + print_line(prefix+json.dumps(j)) + else: + print_line(prefix+line) diff --git a/.local/bin/rofi-light b/.local/bin/rofi-light new file mode 100755 index 0000000..f43543b --- /dev/null +++ b/.local/bin/rofi-light @@ -0,0 +1,4 @@ +#!/bin/sh +cur=$(light -G) +val=$(rofi -dmenu -mesg "light $cur" -p "light -S " -l 0 -width 12) +[ -n "$val" ] && light -S "$val" diff --git a/.local/bin/rofi-remmina b/.local/bin/rofi-remmina new file mode 100755 index 0000000..09b0e64 --- /dev/null +++ b/.local/bin/rofi-remmina @@ -0,0 +1,30 @@ +#!/usr/bin/env python2 +import ConfigParser +import os +from subprocess import Popen, PIPE + +remmina_dir = os.path.expanduser("~/.local/share/remmina") + +fdict = dict() + +for f in os.listdir(remmina_dir): + fp = os.path.join(remmina_dir, f) + c = ConfigParser.ConfigParser() + c.read(fp) + n = c.get('remmina', 'name') + fdict[n] = fp + +lines = max(min(15, len(fdict)), 1); +width = len(max(fdict.keys(), key=len)) +rofi = Popen(["rofi", "-i", "-dmenu", \ + "-l", str(lines), "-width", str(width), \ + "-p", "connection"], stdout=PIPE, stdin=PIPE) +selected = rofi.communicate("\n" \ + .join(fdict.keys()) \ + .encode("utf-8"))[0] \ + .decode("utf-8") \ + .strip() +rofi.wait() + +r = Popen(["remmina", "-c", fdict[selected]]) +r.wait() diff --git a/.local/bin/toggle-presentation-mode b/.local/bin/toggle-presentation-mode new file mode 100755 index 0000000..e939d8c --- /dev/null +++ b/.local/bin/toggle-presentation-mode @@ -0,0 +1,2 @@ +#!/bin/sh +xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/presentation-mode -T diff --git a/.local/bin/toggle-tablet b/.local/bin/toggle-tablet new file mode 100755 index 0000000..c79a4f4 --- /dev/null +++ b/.local/bin/toggle-tablet @@ -0,0 +1,31 @@ +#!/bin/sh +# This script toggles between a 'normal' mode and a 'tablet' mode, doing +# a few things: + +# - rotates the screen using =xrandr=, so that rotating the physical +# display of my X220t would have the laptop's battery on the right +# hand side, +# - enables touch screen, +# - properly rotates the stylus pen and touch screen pointers, and +# - toggles between RGB and Vertical BGR sub-pixel order. + +case $(xfconf-query -c pointers -p /Wacom_ISDv4_E6_Pen_stylus/Properties/Wacom_Rotation) in + 0) # Screen is not rotated, we should rotate it right (90°) + xrandr -o 3 + xfconf-query -c pointers -p /Wacom_ISDv4_E6_Pen_stylus/Properties/Wacom_Rotation -s 1 + xfconf-query -c pointers -p /Wacom_ISDv4_E6_Finger_touch/Properties/Device_Enabled -s 1 + xfconf-query -c pointers -p /Wacom_ISDv4_E6_Finger_touch/Properties/Wacom_Rotation -s 1 + xfconf-query -c xsettings -p /Xft/RGBA -s vbgr + ;; + 1) # Currently top is rotated right, we should set it normal (0°) + xrandr -o 0 + xfconf-query -c pointers -p /Wacom_ISDv4_E6_Pen_stylus/Properties/Wacom_Rotation -s 0 + xfconf-query -c pointers -p /Wacom_ISDv4_E6_Finger_touch/Properties/Wacom_Rotation -s 0 + xfconf-query -c pointers -p /Wacom_ISDv4_E6_Finger_touch/Properties/Device_Enabled -s 0 + xfconf-query -c xsettings -p /Xft/RGBA -s rgb + ;; + *) + echo "Unknown result from 'xfconf-query -c pointers -p /Wacom_ISDv4_E6_Pen_stylus/Properties/Wacom_Rotation'" >&2 + exit 1 + ;; +esac diff --git a/.local/bin/volume-info b/.local/bin/volume-info new file mode 100755 index 0000000..b9a8488 --- /dev/null +++ b/.local/bin/volume-info @@ -0,0 +1,8 @@ +#!/bin/sh +cur_vol=$(pamixer --get-volume) + +if [ $(pamixer --get-mute) = true ]; then + printf 'mt \n' "$cur_vol" +else + printf '%02d \n' "$cur_vol" +fi diff --git a/.local/bin/zathura-sync b/.local/bin/zathura-sync new file mode 100755 index 0000000..89dc620 --- /dev/null +++ b/.local/bin/zathura-sync @@ -0,0 +1,7 @@ +#!/bin/sh +pos="$1" +pdffile="$2" +zathura --synctex-forward "$pos" "$pdffile" || \ + ( + zathura -x "emacsclient --eval '(progn (switch-to-buffer (file-name-nondirectory \"%{input}\")) (goto-line %{line}))'" "$pdffile" & + sleep 1; zathura --synctex-forward "$pos" "$pdffile" ) -- cgit v1.2.3-60-g2f50