diff options
author | Camil Staps | 2017-02-20 10:06:38 +0100 |
---|---|---|
committer | Camil Staps | 2017-02-20 10:06:38 +0100 |
commit | 73ae3a47a410eb2db9c3c776c0252e1feaeb2d7e (patch) | |
tree | 4835551f5d769ede433ed390d3cfc2406975480c /i3/bin | |
parent | Cloogle stats in status bar (diff) |
Reorganise binaries
Diffstat (limited to 'i3/bin')
-rw-r--r-- | i3/bin/.gitignore | 1 | ||||
-rw-r--r-- | i3/bin/Makefile | 3 | ||||
-rwxr-xr-x | i3/bin/askpass | 4 | ||||
-rwxr-xr-x | i3/bin/cloogle_stats.py | 35 | ||||
-rwxr-xr-x | i3/bin/dualmon | 4 | ||||
-rwxr-xr-x | i3/bin/i3status.py | 72 | ||||
-rwxr-xr-x | i3/bin/kbdbacklight | 19 | ||||
-rw-r--r-- | i3/bin/kbdlayout.c | 54 | ||||
-rwxr-xr-x | i3/bin/newws | 2 | ||||
-rwxr-xr-x | i3/bin/nowplaying | 2 | ||||
-rwxr-xr-x | i3/bin/passmenu | 26 | ||||
l--------- | i3/bin/setbg | 1 | ||||
-rwxr-xr-x | i3/bin/setbg-pgfplots | 22 | ||||
-rwxr-xr-x | i3/bin/setbg-texample | 46 | ||||
-rwxr-xr-x | i3/bin/singlemon | 4 |
15 files changed, 295 insertions, 0 deletions
diff --git a/i3/bin/.gitignore b/i3/bin/.gitignore new file mode 100644 index 0000000..95d9967 --- /dev/null +++ b/i3/bin/.gitignore @@ -0,0 +1 @@ +kbdlayout diff --git a/i3/bin/Makefile b/i3/bin/Makefile new file mode 100644 index 0000000..221dde7 --- /dev/null +++ b/i3/bin/Makefile @@ -0,0 +1,3 @@ +kbdlayout: kbdlayout.c + $(CC) $(CCFLAGS) -lX11 $< -o $@ + diff --git a/i3/bin/askpass b/i3/bin/askpass new file mode 100755 index 0000000..dfa595a --- /dev/null +++ b/i3/bin/askpass @@ -0,0 +1,4 @@ +#!/bin/bash +p=$(echo -e "GETPIN\nBYE\n" | pinentry | grep D) +echo "${p:2}" + diff --git a/i3/bin/cloogle_stats.py b/i3/bin/cloogle_stats.py new file mode 100755 index 0000000..0c48b70 --- /dev/null +++ b/i3/bin/cloogle_stats.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +import json +import ssl +import websocket + +def format_query(query): + if 'className' in query: + return 'class ' + query['className'] + elif 'typeName' in query: + return 'type ' + query['typeName'] + elif 'unify' in query: + if 'name' in query and query['name'] != '': + return query['name'] + ' :: ' + query['unify'] + else: + return ':: ' + query['unify'] + else: + return query['name'] + +def on_message(ws, msg): + try: + print(format_query(json.loads(msg))) + except: + pass + +def on_error(ws, err): + print(err) + +def on_close(ws): + print('Closed.') + +if __name__ == '__main__': + ws = websocket.WebSocketApp('wss://cloogle.org:31216', + subprotocols=['cloogle-stats'], + on_message=on_message, on_error=on_error, on_close=on_close) + ws.run_forever(sslopt={'cert_reqs': ssl.CERT_NONE}) diff --git a/i3/bin/dualmon b/i3/bin/dualmon new file mode 100755 index 0000000..02ae65d --- /dev/null +++ b/i3/bin/dualmon @@ -0,0 +1,4 @@ +#!/bin/bash +xrandr --output eDP1 --below HDMI2 --primary --output HDMI2 --auto +xinput disable Atmel +setbg diff --git a/i3/bin/i3status.py b/i3/bin/i3status.py new file mode 100755 index 0000000..1e00e62 --- /dev/null +++ b/i3/bin/i3status.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python +import json +from select import select +from subprocess import Popen, PIPE +import sys + +def remove_empty_outputs(obj): + return [o for o in obj if o['full_text'].strip() != ''] + +first = True +def print_i3stat(j): + global first + j = remove_empty_outputs(j) + sys.stdout.write(('' if first else ',') + json.dumps(j) + '\n') + sys.stdout.flush() + first = False + +def parse_i3stat(s): + if s[0] == ',': + s = s[1:] + j = json.loads(s) + return j + +def parse_kbdlayout(s): + colors = { 'us(intl)' : '#66ccff', + 'us(dvorak-intl)' : '#dc68fc', + 'ru(phonetic)' : '#ff3300', + 'il(biblicalSIL)' : '#66ff66' + } + return [{'full_text': s, 'color': colors[s]}] + +def parse_cloogle(s): + return [{'full_text': s}] + +def merge_status_items(*args): + return [item for sublist in args for item in sublist] + +if __name__ == '__main__': + timeout = 0.1 + + # open subprocesses + i3stat = Popen(['i3status'], stdout=PIPE, bufsize=1, close_fds=True) + kbdlayout = Popen(['unbuffer', 'kbdlayout'], + stdout=PIPE, bufsize=1, close_fds=True) + cloogle = Popen(['unbuffer', 'cloogle_stats.py'], + stdout=PIPE, bufsize=1, close_fds=True) + + # skip i3status header + sys.stdout.write(i3stat.stdout.readline()) + sys.stdout.write(i3stat.stdout.readline()) + + stat, kbd, clg = [], [], [] + try: + stdouts = [p.stdout for p in [i3stat, kbdlayout, cloogle]] + while True: + fs = select(stdouts, [], [])[0] + for f in fs: + line = f.readline()[:-1] + if f == kbdlayout.stdout: + kbd = parse_kbdlayout(line) + elif f == cloogle.stdout: + clg = parse_cloogle(line) + elif f == i3stat.stdout: + stat = parse_i3stat(line) + + print_i3stat(merge_status_items(kbd, clg, stat)) + + except Exception, e: + print(e) + i3stat.kill() + kbdlayout.kill() + cloogle.kill() diff --git a/i3/bin/kbdbacklight b/i3/bin/kbdbacklight new file mode 100755 index 0000000..f8d1e02 --- /dev/null +++ b/i3/bin/kbdbacklight @@ -0,0 +1,19 @@ +#!/bin/sh +FILE="/sys/class/leds/asus::kbd_backlight/brightness" +SETTING=`cat "$FILE"` +COMMAND="$1" + +if [ "$COMMAND" = "set" ]; then + echo $2 > "$FILE" +elif [ "$COMMAND" = "up" ]; then + echo "$(($SETTING+1))" > "$FILE" +elif [ "$COMMAND" = "down" ]; then + if [ "$SETTING" != "0" ]; then + echo "$(($SETTING-1))" > "$FILE" + fi +elif [ "$COMMAND" = "party" ]; then + while :; do + $0 set 0; sleep 1; $0 set 3; sleep 1 + done +fi + diff --git a/i3/bin/kbdlayout.c b/i3/bin/kbdlayout.c new file mode 100644 index 0000000..bb030bb --- /dev/null +++ b/i3/bin/kbdlayout.c @@ -0,0 +1,54 @@ +#include <X11/XKBlib.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +char* getActiveLayout(char* names, unsigned char active) { + int i; + for (i = 0; names[i]; i++) { + if (names[i] == '+') { + if (active <= 0) { + int j = ++i; + for (; names[j] && names[j] != '+' && names[j] != ':'; j++); + char* ret = malloc(j - i + 1); + strncpy(ret, names + i, j - i); + ret[j - i] = '\0'; + return ret; + } else { + active--; + } + } + } + return NULL; +} + +int main(void) { + int evCode, errRet, rsnRet; + int maj = XkbMajorVersion; + int min = XkbMinorVersion; + + Display* disp = XkbOpenDisplay("", &evCode, &errRet, &maj, &min, &rsnRet); + + // State + XkbStatePtr state = calloc(1, sizeof(XkbStateRec)); + XkbGetState(disp, 0x100, state); + + // Names + XkbDescPtr desc = XkbAllocKeyboard(); + XkbGetNames(disp, XkbSymbolsNameMask, desc); + + Atom symNameAtom = desc->names->symbols; + char* layouts = XGetAtomName(disp, symNameAtom); + + printf("%s\n", getActiveLayout(layouts, state->group)); + + unsigned int mask = XkbStateNotifyMask; + XkbSelectEvents(disp, XkbUseCoreKbd, mask, mask); + + XkbEvent event; + while (1) { + XNextEvent(disp, &event.core); + if (event.state.changed & 0x90) + printf("%s\n", getActiveLayout(layouts, event.state.group)); + } +} diff --git a/i3/bin/newws b/i3/bin/newws new file mode 100755 index 0000000..386b353 --- /dev/null +++ b/i3/bin/newws @@ -0,0 +1,2 @@ +#!/bin/sh +i3-msg workspace $(($(i3-msg -t get_workspaces | tr , '\n' | grep '"num":' | cut -d : -f 2 | sort -rn | head -1) + 1)) diff --git a/i3/bin/nowplaying b/i3/bin/nowplaying new file mode 100755 index 0000000..650e6e8 --- /dev/null +++ b/i3/bin/nowplaying @@ -0,0 +1,2 @@ +#!/bin/sh +cmus-remote -Q | grep '^tag \(artist\|album\|title\) ' | cut -d' ' -f 3- | tr '\n' '\t' | awk 'BEGIN { FS = "\t" } ; { print $3 " (" $2 ", " $1 ")" }'; echo -n ' ' diff --git a/i3/bin/passmenu b/i3/bin/passmenu new file mode 100755 index 0000000..9b5239d --- /dev/null +++ b/i3/bin/passmenu @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +shopt -s nullglob globstar + +typeit=0 +if [[ $1 == "--type" ]]; then + typeit=1 + shift +fi + +prefix=${PASSWORD_STORE_DIR-~/.password-store} +password_files=( "$prefix"/**/*.gpg ) +password_files=( "${password_files[@]#"$prefix"/}" ) +password_files=( "${password_files[@]%.gpg}" ) + +password=$(printf '%s\n' "${password_files[@]}" | dmenu "$@") + +[[ -n $password ]] || exit + +if [[ $typeit -eq 0 ]]; then + pass show -c "$password" 2>/dev/null +else + pass show "$password" | + awk 'BEGIN{ORS=""} {print; exit}' | + xdotool type --clearmodifiers --file - +fi diff --git a/i3/bin/setbg b/i3/bin/setbg new file mode 120000 index 0000000..d445e5c --- /dev/null +++ b/i3/bin/setbg @@ -0,0 +1 @@ +setbg-texample
\ No newline at end of file diff --git a/i3/bin/setbg-pgfplots b/i3/bin/setbg-pgfplots new file mode 100755 index 0000000..7343f35 --- /dev/null +++ b/i3/bin/setbg-pgfplots @@ -0,0 +1,22 @@ +#!/bin/bash + +SCR_WIDTH=1980 +SCR_HEIGHT=1080 +PADDING=50 +FONT_SIZE=20 + +let "SCR_WIDTH -= 2 * $PADDING" +let "SCR_WIDTH /= 2" +let "SCR_HEIGHT -= 2 * $PADDING" + +NR=$RANDOM +let "NR %= 524" + +wget -qO- "http://pgfplots.sourceforge.net/example_$NR.pdf" | convert -size "x$SCR_HEIGHT" -density 300 - /tmp/bg.png +wget -qO- "http://pgfplots.sourceforge.net/gallery.html" | sed -n "/example_$NR\.pdf/,/<\/div>/p" | tail -n +6 | head -n -1 | pygmentize -l latex -O font_size=$FONT_SIZE -o /tmp/bg-src.png + +montage -geometry "+$PADDING+$PADDING" /tmp/bg-src.png /tmp/bg.png "/tmp/bg-$NR.png" +rm /tmp/bg{,-src}.png + +feh -B white --bg-max "/tmp/bg-$NR.png" + diff --git a/i3/bin/setbg-texample b/i3/bin/setbg-texample new file mode 100755 index 0000000..ee996d3 --- /dev/null +++ b/i3/bin/setbg-texample @@ -0,0 +1,46 @@ +#!/bin/bash + +SCR_WIDTH=1980 +SCR_HEIGHT=1080 +PADDING=50 +FONT_SIZE=20 + +function fail() { + if [ -f ~/.bg.png ]; then + feh --bg-max -B white ~/.bg.png + fi + exit -1; +} + +# Test internet +timeout 4 wget -q --spider http://texample.net +if [ $? -ne 0 ]; then fail; fi + +let "SCR_WIDTH -= 2 * $PADDING" +let "SCR_WIDTH /= 2" +let "SCR_HEIGHT -= 2 * $PADDING" + +PAGE=$RANDOM; let "PAGE %= 22"; let "PAGE += 1" + +# Fetch list of texamples +cd /tmp +wget -qO texample.html "http://texample.net/tikz/examples/all/?page=$PAGE" +if [ $? -ne 0 ]; then fail; fi + +EXAMPLES="$(grep '^<dl' texample.html | wc -l)" +awk -v n=0 "BEGIN{n=int(rand()*$EXAMPLES)+1} /^<dl/{l++} (l==n){print} END{}" texample.html | sponge texample.html + +PDF="$(grep '\/media\/tikz\/examples\/PDF' texample.html | sed "s/.*<a href=\"\([^\"]*\)\">PDF<\/a>.*/\1/")" +TEX="$(grep '\/media\/tikz\/examples\/TEX' texample.html | grep -v writelatex | sed "s/.*<a href=\"\(.*\)\">TEX<\/a>.*/\1/")" + +echo $PDF $TEX + +wget -qO- "http://texample.net$PDF" | convert -size "x$SCR_HEIGHT" -density 300 - /tmp/bg.png +wget -qO- "http://texample.net$TEX" | sed -n '/\\begin{document}/,/\\end{document}/p' | pygmentize -l latex -O font_size=$FONT_SIZE -o /tmp/bg-src.png + +montage -geometry "+$PADDING+$PADDING" /tmp/bg-src.png /tmp/bg.png "/tmp/bg-$PAGE.png" +rm /tmp/bg{,-src}.png +if [ $? -ne 0 ]; then fail; fi + +feh -B white --bg-max "/tmp/bg-$PAGE.png" + diff --git a/i3/bin/singlemon b/i3/bin/singlemon new file mode 100755 index 0000000..8034639 --- /dev/null +++ b/i3/bin/singlemon @@ -0,0 +1,4 @@ +#!/bin/bash +xrandr --output eDP1 --primary --auto --output HDMI2 --off +xinput enable Atmel +setbg |