summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmin Bandali <bandali@gnu.org>2020-04-11 22:45:06 -0400
committerAmin Bandali <bandali@gnu.org>2020-04-11 22:45:06 -0400
commit5d3bd4099ecff7b02454efcb6f6bb355a992aef8 (patch)
tree542fdedd6259e91cec7ada5fc3783b9476c29c33
parente5e4450f889a82197d845cc06a63fcb3e740583d (diff)
downloadconfigs-5d3bd4099ecff7b02454efcb6f6bb355a992aef8.tar.gz
configs-5d3bd4099ecff7b02454efcb6f6bb355a992aef8.tar.xz
configs-5d3bd4099ecff7b02454efcb6f6bb355a992aef8.zip
move scripts from ~/.local/bin to rc.org
-rwxr-xr-x.local/bin/battery-percentage-time22
-rwxr-xr-x.local/bin/emcl2
-rwxr-xr-x.local/bin/my-i3status70
-rwxr-xr-x.local/bin/rofi-light5
-rwxr-xr-x.local/bin/rofi-remmina31
-rwxr-xr-x.local/bin/toggle-presentation-mode3
-rwxr-xr-x.local/bin/toggle-tablet32
-rwxr-xr-x.local/bin/volume-info9
-rwxr-xr-x.local/bin/zathura-sync8
-rw-r--r--rc.org252
10 files changed, 248 insertions, 186 deletions
diff --git a/.local/bin/battery-percentage-time b/.local/bin/battery-percentage-time
deleted file mode 100755
index b0122a8..0000000
--- a/.local/bin/battery-percentage-time
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/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
deleted file mode 100755
index b0f2de2..0000000
--- a/.local/bin/emcl
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/sh
-exec emacsclient --alternate-editor="" -c "$@"
diff --git a/.local/bin/my-i3status b/.local/bin/my-i3status
deleted file mode 100755
index 2831c15..0000000
--- a/.local/bin/my-i3status
+++ /dev/null
@@ -1,70 +0,0 @@
-#!/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 <valentin.haenel@gmx.de>
-# © 2018 Amin Bandali <bandali@gnu.org>
-#
-# 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
deleted file mode 100755
index f2a46af..0000000
--- a/.local/bin/rofi-light
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/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
deleted file mode 100755
index 153a5a6..0000000
--- a/.local/bin/rofi-remmina
+++ /dev/null
@@ -1,31 +0,0 @@
-#!/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
deleted file mode 100755
index 400084f..0000000
--- a/.local/bin/toggle-presentation-mode
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/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
deleted file mode 100755
index 819af42..0000000
--- a/.local/bin/toggle-tablet
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/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
deleted file mode 100755
index d87137e..0000000
--- a/.local/bin/volume-info
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/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
deleted file mode 100755
index 4384ffe..0000000
--- a/.local/bin/zathura-sync
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/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" )
diff --git a/rc.org b/rc.org
index 8533246..8d770c0 100644
--- a/rc.org
+++ b/rc.org
@@ -1,5 +1,5 @@
#+title: rc.org
-#+property: header-args :comments link :mkdirp yes :results silent
+#+property: header-args :comments no :mkdirp yes :results silent
* About
@@ -10,9 +10,6 @@ this file using =org-babel=.
Note: This file is best viewed inside Emacs with org mode.
* Configs
-:PROPERTIES:
-:header-args+: :comments no
-:END:
This section contains the configuration files (dotfiles) of various
programs I use besides GNU Emacs.
@@ -3379,3 +3376,250 @@ map [normal] i toggle_index
map [index] i toggle_index
map [index] q toggle_index
#+end_src
+
+* Scripts
+
+This section contains various useful scripts including ones used by
+the programs above. For instance, =toggle-tablet= for switching to
+and from tablet mode on my X220T, =toggle-presentation-mode= for
+toggling Xfce's presentation mode which keeps the screen awake, and
+=rofi-light= a small utility that uses [[https://github.com/DaveDavenport/rofi][rofi]] to ask and [[https://github.com/haikarainen/light][light]] to set an
+exact brightness value.
+
+** battery-percentage-time
+:PROPERTIES:
+:header-args+: :tangle ~/.local/bin/battery-percentage-time :shebang "#!/bin/sh"
+:END:
+
+#+begin_src sh :tangle no
+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))
+#+end_src
+
+** emcl
+:PROPERTIES:
+:header-args+: :tangle ~/.local/bin/emcl :shebang "#!/bin/sh"
+:END:
+
+#+begin_src sh
+exec emacsclient --alternate-editor="" -c "$@"
+#+end_src
+
+** my-i3status
+:PROPERTIES:
+:header-args+: :tangle ~/.local/bin/emcl :shebang "#!/usr/bin/env python2"
+:END:
+
+#+begin_src python
+# -*- 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 <valentin.haenel@gmx.de>
+# © 2018 Amin Bandali <bandali@gnu.org>
+#
+# 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)
+#+end_src
+
+** rofi-light
+:PROPERTIES:
+:header-args+: :tangle ~/.local/bin/rofi-light :shebang "#!/bin/sh"
+:END:
+
+#+begin_src sh
+cur=$(light -G)
+val=$(rofi -dmenu -mesg "light $cur" -p "light -S " -l 0 -width 12)
+[ -n "$val" ] && light -S "$val"
+#+end_src
+
+** rofi-remmina
+:PROPERTIES:
+:header-args+: :tangle ~/.local/bin/rofi-remmina :shebang "#!/usr/bin/env python2"
+:END:
+
+#+begin_src python
+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()
+#+end_src
+
+** toggle-presentation-mode
+:PROPERTIES:
+:header-args+: :tangle ~/.local/bin/toggle-presentation-mode :shebang "#!/bin/sh"
+:END:
+
+#+begin_src sh
+xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/presentation-mode -T
+#+end_src
+
+** toggle-tablet
+:PROPERTIES:
+:header-args+: :tangle ~/.local/bin/toggle-tablet :shebang "#!/bin/sh"
+:END:
+
+#+begin_src 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
+#+end_src
+
+** volume-info
+:PROPERTIES:
+:header-args+: :tangle ~/.local/bin/volume-info :shebang "#!/bin/sh"
+:END:
+
+#+begin_src sh
+cur_vol=$(pamixer --get-volume)
+
+if [ $(pamixer --get-mute) = true ]; then
+ printf 'mt \n' "$cur_vol"
+else
+ printf '%02d \n' "$cur_vol"
+fi
+#+end_src
+
+** zathura-sync
+:PROPERTIES:
+:header-args+: :tangle ~/.local/bin/zathura-sync :shebang "#!/bin/sh"
+:END:
+
+#+begin_src 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" )
+#+end_src