From 2e8bd7c21c3677407f9a529a3ee10011fba42ad4 Mon Sep 17 00:00:00 2001 From: Unixsys Date: Sun, 18 Oct 2020 12:47:18 -0500 Subject: [PATCH 001/197] README --- README | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 README diff --git a/README b/README new file mode 100644 index 0000000..600ccce --- /dev/null +++ b/README @@ -0,0 +1,4 @@ +utils +===== + +basic shell script utilities From 9f91a082534feb0d6c471b7b3392360dd13b32d8 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 18 Oct 2020 18:40:53 +0000 Subject: [PATCH 002/197] ttm.sh pastebin wrapper and battery script --- bat | 3 +++ paste | 5 +++++ 2 files changed, 8 insertions(+) create mode 100755 bat create mode 100755 paste diff --git a/bat b/bat new file mode 100755 index 0000000..88788aa --- /dev/null +++ b/bat @@ -0,0 +1,3 @@ +#!/bin/sh + +cat /sys/class/power_supply/BAT?/capacity diff --git a/paste b/paste new file mode 100755 index 0000000..89b5eb0 --- /dev/null +++ b/paste @@ -0,0 +1,5 @@ +#!/bin/sh +set -x + +[ "$1" = "" ] && exit 1 +[ -f "$1" ] && curl -F"file=@${1}" https://ttm.sh && exit 0 From e97c820f6cca461b94e274f19914359a28627c0f Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 13 Dec 2020 13:55:55 -0600 Subject: [PATCH 003/197] replace README for man page --- README | 4 ---- rndutils.1 | 11 +++++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) delete mode 100644 README create mode 100644 rndutils.1 diff --git a/README b/README deleted file mode 100644 index 600ccce..0000000 --- a/README +++ /dev/null @@ -1,4 +0,0 @@ -utils -===== - -basic shell script utilities diff --git a/rndutils.1 b/rndutils.1 new file mode 100644 index 0000000..8b50645 --- /dev/null +++ b/rndutils.1 @@ -0,0 +1,11 @@ +.TH RNDUTILS 1 rndutils +.SH NAME +rndutils \- simple shell script utilities +.SH INSTALLATION +.B make install +.SH LICENSE +The author, randomuser (randomuser at tilde dot club) hereby +releases the software in this distribution and all +accompanying texts into the public domain, thereby relieving +him of any warranty of any kind. + From 5ebfec6678e5d707462d524a1c61f2713abc301d Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 13 Dec 2020 14:10:20 -0600 Subject: [PATCH 004/197] add makefile --- Makefile | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..48b62f1 --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +install: man sh +man: + mkdir -p $(DESTDIR)$(PREFIX)/man1 + cp -f *.1 $(DESTDIR)$(PREFIX)/man1 +sh: + mkdir -p $(DESTDIR)$(PREFIX)/bin + cp -f paste $(DESTDIR)$(PREFIX)/bin + cp -f bat $(DESTDIR)$(PREFIX)/bin From e74bd8604c2cc4fdecefce1300843f2885309105 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sat, 19 Dec 2020 19:03:47 -0600 Subject: [PATCH 005/197] added shime --- shime | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 shime diff --git a/shime b/shime new file mode 100755 index 0000000..256f9f4 --- /dev/null +++ b/shime @@ -0,0 +1,52 @@ +#!/bin/sh + +case $0 in + *"timer"*) + [ $# -ne 2 ] && printf "specify minutes and \ + seconds\n" && exit 1 + sleep $(($1 * 60 + $2)) + printf "your timer is done\a\n" + exit 0 + ;; + *"alarm"*) + [ $# -ne 1 ] && printf "specify time\n" && exit 1 + ttw=$(($(date +%s --date="$1 tomorrow") - $(date +%s))) + sleep $ttw + printf "your alarm is done\a\n" + exit 0 + ;; + *"tomato"*) + [ $# -ne 2 ] && \ + printf "specify work and rest time\n" && exit 1 + counter=0 + while true; do + printf "start work cycle %s\a\n" $(($counter + 1)) + sleep $(($1 * 60)) + printf "start rest cycle %s\a\n" $(($counter + 1)) + sleep $(($2 * 60)) + counter=$(($counter + 1)) + done + exit 0 + ;; + *"stopwatch"*) + now=$(date +%s) + read var + printf "%s\n" $(($(date +%s) - $now)) + exit 0 + ;; + *"verbosewatch"*) + min=59 + sec=55 + while true; do + printf "%02d:%02d\r" $min $sec + sleep 1 + sec=$(($sec + 1)) + [ $sec -eq 60 ] && min=$(($min + 1)) && sec=0 + done + exit 0 + ;; + *) + printf "unknown invocation\n" + exit 2 + ;; +esac From 0930e15efd1b6daf60c31d601e1efa27f75449ef Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 20 Dec 2020 11:39:12 -0600 Subject: [PATCH 006/197] minor changes --- .gitignore | 2 ++ shime | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fb1aaf1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.swp +*.tmp diff --git a/shime b/shime index 256f9f4..911ca16 100755 --- a/shime +++ b/shime @@ -35,8 +35,8 @@ case $0 in exit 0 ;; *"verbosewatch"*) - min=59 - sec=55 + min=0 + sec=0 while true; do printf "%02d:%02d\r" $min $sec sleep 1 From 66ce84a3093e4477cb16e31fe0e4f81cb5c605c8 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 20 Dec 2020 11:40:05 -0600 Subject: [PATCH 007/197] add an alternate commandline youtube client --- yt | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 yt diff --git a/yt b/yt new file mode 100755 index 0000000..2256739 --- /dev/null +++ b/yt @@ -0,0 +1,35 @@ +#!/bin/sh + +DATFILE="~/.config/youtube" +CACHEDIR="~/.config/youtube/cache" +tmp1=$(mktemp) +tmp2=$(mktemp) + +mkdir -p $DATFILE +mkdir -p $CACHEDIR + +sync () { + for i in $(cat $DATFILE | tr '\n' ' '); do + curl -s \ + https://www.youtube.com/feeds/videos.xml?channel_id=$i\ + > ${CACHEDIR}/$i + done +} +display () { + for i in $(ls $CACHEDIR | tr '\n' ' '); do + grep \ ${CACHEDIR}/$i | cut -c 17- | \ + rev | cut -c 15- | rev >> $tmp1 + grep 'link rel' ${CACHEDIR}/$i | grep 'watch' | \ + cut -c31- | rev | cut -c4- | rev >> $tmp2 + done + cat $tmp1 $tmp2 | pr -2t -s" | " +} +case $1 in + *"sync"*) + sync + ;; + *) + display + ;; +esac +exit 0 From f7e4897de899599f484d3910476bf6cd63356a34 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 20 Dec 2020 11:50:47 -0600 Subject: [PATCH 008/197] add more functions to yt --- yt | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/yt b/yt index 2256739..9e57483 100755 --- a/yt +++ b/yt @@ -1,11 +1,11 @@ #!/bin/sh -DATFILE="~/.config/youtube" +DATFILE="~/.config/youtube/dat" CACHEDIR="~/.config/youtube/cache" tmp1=$(mktemp) tmp2=$(mktemp) -mkdir -p $DATFILE +touch $DATFILE mkdir -p $CACHEDIR sync () { @@ -24,10 +24,22 @@ display () { done cat $tmp1 $tmp2 | pr -2t -s" | " } +add () { # $1: name of channel id + printf "%s\n" $1 >> $DATFILE +} +del () { # $1: line number of channel id + sed -i "${1}d" $DATFILE +} case $1 in *"sync"*) sync ;; + *"add"*) + [ $# -eq 2 ] && add $2 + ;; + *"del"*) + [ $# -eq 2 ] && del $2 + ;; *) display ;; From 45a43206932fe82921361e398dc782ee171a5820 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 20 Dec 2020 13:59:30 -0600 Subject: [PATCH 009/197] minor changes to yt --- yt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yt b/yt index 9e57483..edcd5a4 100755 --- a/yt +++ b/yt @@ -1,7 +1,7 @@ #!/bin/sh -DATFILE="~/.config/youtube/dat" -CACHEDIR="~/.config/youtube/cache" +DATFILE="${HOME}/.config/youtube/dat" +CACHEDIR="${HOME}/.config/youtube/cache" tmp1=$(mktemp) tmp2=$(mktemp) @@ -10,7 +10,7 @@ mkdir -p $CACHEDIR sync () { for i in $(cat $DATFILE | tr '\n' ' '); do - curl -s \ + torify curl -s \ https://www.youtube.com/feeds/videos.xml?channel_id=$i\ > ${CACHEDIR}/$i done From 89dcb1ec506f4969223010fa7a0300abfcb07043 Mon Sep 17 00:00:00 2001 From: randomuser Date: Thu, 31 Dec 2020 18:18:19 -0600 Subject: [PATCH 010/197] add scripts directory --- bat => scripts/bat | 0 paste => scripts/paste | 0 shime => scripts/shime | 0 yt => scripts/yt | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename bat => scripts/bat (100%) rename paste => scripts/paste (100%) rename shime => scripts/shime (100%) rename yt => scripts/yt (100%) diff --git a/bat b/scripts/bat similarity index 100% rename from bat rename to scripts/bat diff --git a/paste b/scripts/paste similarity index 100% rename from paste rename to scripts/paste diff --git a/shime b/scripts/shime similarity index 100% rename from shime rename to scripts/shime diff --git a/yt b/scripts/yt similarity index 100% rename from yt rename to scripts/yt From cec737e0f81c0fafdf742b7fd209801a96fd7095 Mon Sep 17 00:00:00 2001 From: randomuser Date: Thu, 31 Dec 2020 18:24:47 -0600 Subject: [PATCH 011/197] add program for doing shouty caps --- Makefile | 9 ++++++--- progs/scream.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 progs/scream.c diff --git a/Makefile b/Makefile index 48b62f1..df863ca 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,11 @@ -install: man sh +install: man sh c man: mkdir -p $(DESTDIR)$(PREFIX)/man1 cp -f *.1 $(DESTDIR)$(PREFIX)/man1 sh: mkdir -p $(DESTDIR)$(PREFIX)/bin - cp -f paste $(DESTDIR)$(PREFIX)/bin - cp -f bat $(DESTDIR)$(PREFIX)/bin + cp -f scripts/paste $(DESTDIR)$(PREFIX)/bin + cp -f scripts/bat $(DESTDIR)$(PREFIX)/bin +c: + cc progs/scream.c -o progs/scream + cp -f progs/scream $(DESTDIR)$(PREFIX)/bin diff --git a/progs/scream.c b/progs/scream.c new file mode 100644 index 0000000..c39b08f --- /dev/null +++ b/progs/scream.c @@ -0,0 +1,34 @@ +#include +#include + +/* written on new year's eve 2020 + * good night and good riddance */ + +char newchar(char c, int i) { + switch(i) { + case 0: + if(isupper(c)) return c + 32; + if(c == 33) return -2; + else return c; + case 1: + if(islower(c)) return c - 32; + if(c == 33) return -2; + else return c; + default: return -1; + } +} +int advi(int i) { + switch(i) { + case 0: return 1; + case 1: return 0; + default: return -1; + } +} +int main(void) { + char c; + int i = 0; + while((c = getchar()) != EOF) { + putchar(newchar(c, i)); + i = advi(i); + } +} From 5dd0007c04d0264460f309d781cdab65164c1520 Mon Sep 17 00:00:00 2001 From: randomuser Date: Mon, 15 Feb 2021 12:02:09 -0600 Subject: [PATCH 012/197] add some scripts --- Makefile | 12 ++++++++++-- scripts/disp | 29 +++++++++++++++++++++++++++++ scripts/wall | 42 ++++++++++++++++++++++++++++++++++++++++++ scripts/yt | 43 +++++++++++++++++++++++++++++++------------ 4 files changed, 112 insertions(+), 14 deletions(-) create mode 100755 scripts/disp create mode 100755 scripts/wall diff --git a/Makefile b/Makefile index df863ca..658d78d 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,7 @@ -install: man sh c +all: mkc +install: man sh mkc c +.PHONY: man sh mkc c + man: mkdir -p $(DESTDIR)$(PREFIX)/man1 cp -f *.1 $(DESTDIR)$(PREFIX)/man1 @@ -6,6 +9,11 @@ sh: mkdir -p $(DESTDIR)$(PREFIX)/bin cp -f scripts/paste $(DESTDIR)$(PREFIX)/bin cp -f scripts/bat $(DESTDIR)$(PREFIX)/bin -c: + cp -f scripts/disp $(DESTDIR)$(PREFIX)/bin + cp -f scripts/shime $(DESTDIR)$(PREFIX)/bin + cp -f scripts/wall $(DESTDIR)$(PREFIX)/bin + cp -f scripts/yt $(DESTDIR)$(PREFIX)/bin +mkc: cc progs/scream.c -o progs/scream +c: cp -f progs/scream $(DESTDIR)$(PREFIX)/bin diff --git a/scripts/disp b/scripts/disp new file mode 100755 index 0000000..c78563f --- /dev/null +++ b/scripts/disp @@ -0,0 +1,29 @@ +#!/bin/sh + +exists() { + xrandr | grep ' connected' | grep "${1}" | wc -l +} + +# usual setup: thinkpad x220 on dock connected to external +# monitor + +[ $(exists "HDMI2") -gt 0 ] && \ + [ $(exists "LVDS1") -gt 0 ] && \ + xrandr --output LVDS1 --below HDMI2 --auto && \ + exit 0 || exit 1 + +# thinkpad x220 connected to display on local port + +[ $(exists "HDMI1") -gt 0 ] && \ + [ $(exists "LVDS1") -gt 0 ] && \ + xrandr --output LVDS1 --below HDMI1 --auto && \ + exit 0 || exit 1 + +# only the thinkpad + +[ $(exists "HDMI2") -eq 0 ] && \ + [ $(exists "LVDS1") -gt 0 ] && \ + xrandr --output LVDS1 --auto && \ + exit 0 || exit 1 + +exit 1 diff --git a/scripts/wall b/scripts/wall new file mode 100755 index 0000000..bb16c60 --- /dev/null +++ b/scripts/wall @@ -0,0 +1,42 @@ +#!/bin/sh + +WALLDIR="${HOME}/.share/wallpapers" +BASECMD="feh --bg-fill" + +generate_wall () { + GENWALL=$( \ + ls $WALLDIR | \ + shuf -n 1 + ) + GENWALL="${WALLDIR}/${GENWALL}" +} +wall () { + generate_wall + while [ "${GENWALL}" = "${1}" ]; do + generate_wall + done +} +displays () { + displays=$(xrandr | grep ' connected' | wc -l) +} +check () { + which $1 &>/dev/null +} + +cmd="" +check "feh" || exit 1 +if check "xrandr"; then + displays + for i in $(seq 1 $displays); do + wall ${tmp} + tmp=${GENWALL} + echo ${GENWALL} ${i} + cmd="${cmd} ${GENWALL}" + done + eval ${BASECMD} ${cmd} +else + generate_wall + eval ${BASECMD} ${GENWALL} +fi +unset GENWALL BASECMD tmp cmd displays i +exit 0 diff --git a/scripts/yt b/scripts/yt index edcd5a4..fbd2625 100755 --- a/scripts/yt +++ b/scripts/yt @@ -1,25 +1,41 @@ #!/bin/sh -DATFILE="${HOME}/.config/youtube/dat" -CACHEDIR="${HOME}/.config/youtube/cache" -tmp1=$(mktemp) -tmp2=$(mktemp) +[ -z "${YT_DATFILE}" ] && YT_DATFILE="${HOME}/.local/share/ytdat" +[ -z "${YT_CACHEDIR}" ] && YT_CACHEDIR="${HOME}/.local/share/ytcache" +ver=0.1 touch $DATFILE mkdir -p $CACHEDIR +info () { + printf %s "\ +yt - youtube tool + +=> [s]ync - Sync RSS feeds +=> [a]dd [id] - Add a channel to the list +=> [d]el [id] - Remove a channel from the list +=> [h]elp - Show this help + +List file: export DATFILE= +Cache directory: export CACHEDIR= + +see yt(1) for more information on usage +" +} sync () { - for i in $(cat $DATFILE | tr '\n' ' '); do + for i in $(cat $YT_DATFILE | tr '\n' ' '); do torify curl -s \ https://www.youtube.com/feeds/videos.xml?channel_id=$i\ - > ${CACHEDIR}/$i + > ${YT_CACHEDIR}/$i done } display () { - for i in $(ls $CACHEDIR | tr '\n' ' '); do - grep \ ${CACHEDIR}/$i | cut -c 17- | \ + tmp1=$(mktemp) + tmp2=$(mktemp) + for i in $(ls $YT_CACHEDIR | tr '\n' ' '); do + grep \ ${YT_CACHEDIR}/$i | cut -c 17- | \ rev | cut -c 15- | rev >> $tmp1 - grep 'link rel' ${CACHEDIR}/$i | grep 'watch' | \ + grep 'link rel' ${YT_CACHEDIR}/$i | grep 'watch' | \ cut -c31- | rev | cut -c4- | rev >> $tmp2 done cat $tmp1 $tmp2 | pr -2t -s" | " @@ -31,15 +47,18 @@ del () { # $1: line number of channel id sed -i "${1}d" $DATFILE } case $1 in - *"sync"*) + *"s"*) sync ;; - *"add"*) + *"a"*) [ $# -eq 2 ] && add $2 ;; - *"del"*) + *"d"*) [ $# -eq 2 ] && del $2 ;; + *"h"*) + info + ;; *) display ;; From 1abf6914e977a872a89bf49369ce67d05a444c15 Mon Sep 17 00:00:00 2001 From: randomuser Date: Mon, 15 Feb 2021 17:16:23 -0600 Subject: [PATCH 013/197] more updates --- scripts/disp | 12 +++++++++++- scripts/wall | 4 +++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/scripts/disp b/scripts/disp index c78563f..cce2c71 100755 --- a/scripts/disp +++ b/scripts/disp @@ -4,6 +4,16 @@ exists() { xrandr | grep ' connected' | grep "${1}" | wc -l } +# commands + +[ "$1" = "big" ] && \ + xrandr --output LVDS1 --off && \ + exit 0 || exit 1 + +[ "$1" = "small" ] && \ + xrandr --output HDMI2 --off && \ + exit 0 || exit 1 + # usual setup: thinkpad x220 on dock connected to external # monitor @@ -23,7 +33,7 @@ exists() { [ $(exists "HDMI2") -eq 0 ] && \ [ $(exists "LVDS1") -gt 0 ] && \ - xrandr --output LVDS1 --auto && \ + xrandr --output HDMI2 --off && \ exit 0 || exit 1 exit 1 diff --git a/scripts/wall b/scripts/wall index bb16c60..a32eebe 100755 --- a/scripts/wall +++ b/scripts/wall @@ -1,11 +1,13 @@ #!/bin/sh WALLDIR="${HOME}/.share/wallpapers" +TEEFILE="${WALLDIR}/hist" BASECMD="feh --bg-fill" generate_wall () { GENWALL=$( \ ls $WALLDIR | \ + grep "." | \ shuf -n 1 ) GENWALL="${WALLDIR}/${GENWALL}" @@ -30,7 +32,7 @@ if check "xrandr"; then for i in $(seq 1 $displays); do wall ${tmp} tmp=${GENWALL} - echo ${GENWALL} ${i} + echo ${GENWALL} ${i} | tee $TEEFILE cmd="${cmd} ${GENWALL}" done eval ${BASECMD} ${cmd} From a2055f3deb2f2d0e95f094092501cba557f2f759 Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 16 Feb 2021 10:31:48 -0600 Subject: [PATCH 014/197] removing breaking section from disp and retab shime, yt --- scripts/disp | 10 ------ scripts/shime | 94 +++++++++++++++++++++++++-------------------------- scripts/yt | 62 ++++++++++++++++----------------- 3 files changed, 78 insertions(+), 88 deletions(-) diff --git a/scripts/disp b/scripts/disp index cce2c71..f4ac8d4 100755 --- a/scripts/disp +++ b/scripts/disp @@ -4,16 +4,6 @@ exists() { xrandr | grep ' connected' | grep "${1}" | wc -l } -# commands - -[ "$1" = "big" ] && \ - xrandr --output LVDS1 --off && \ - exit 0 || exit 1 - -[ "$1" = "small" ] && \ - xrandr --output HDMI2 --off && \ - exit 0 || exit 1 - # usual setup: thinkpad x220 on dock connected to external # monitor diff --git a/scripts/shime b/scripts/shime index 911ca16..da5fa4c 100755 --- a/scripts/shime +++ b/scripts/shime @@ -1,52 +1,52 @@ #!/bin/sh case $0 in - *"timer"*) - [ $# -ne 2 ] && printf "specify minutes and \ - seconds\n" && exit 1 - sleep $(($1 * 60 + $2)) - printf "your timer is done\a\n" - exit 0 - ;; - *"alarm"*) - [ $# -ne 1 ] && printf "specify time\n" && exit 1 - ttw=$(($(date +%s --date="$1 tomorrow") - $(date +%s))) - sleep $ttw - printf "your alarm is done\a\n" - exit 0 - ;; + *"timer"*) + [ $# -ne 2 ] && printf "specify minutes and \ + seconds\n" && exit 1 + sleep $(($1 * 60 + $2)) + printf "your timer is done\a\n" + exit 0 + ;; + *"alarm"*) + [ $# -ne 1 ] && printf "specify time\n" && exit 1 + ttw=$(($(date +%s --date="$1 tomorrow") - $(date +%s))) + sleep $ttw + printf "your alarm is done\a\n" + exit 0 + ;; *"tomato"*) - [ $# -ne 2 ] && \ - printf "specify work and rest time\n" && exit 1 - counter=0 - while true; do - printf "start work cycle %s\a\n" $(($counter + 1)) - sleep $(($1 * 60)) - printf "start rest cycle %s\a\n" $(($counter + 1)) - sleep $(($2 * 60)) - counter=$(($counter + 1)) - done - exit 0 - ;; - *"stopwatch"*) - now=$(date +%s) - read var - printf "%s\n" $(($(date +%s) - $now)) - exit 0 - ;; - *"verbosewatch"*) - min=0 - sec=0 - while true; do - printf "%02d:%02d\r" $min $sec - sleep 1 - sec=$(($sec + 1)) - [ $sec -eq 60 ] && min=$(($min + 1)) && sec=0 - done - exit 0 - ;; - *) - printf "unknown invocation\n" - exit 2 - ;; + [ $# -ne 2 ] && \ + printf "specify work and rest time\n" && exit 1 + counter=0 + while true; do + printf "start work cycle %s\a\n" $(($counter + 1)) + sleep $(($1 * 60)) + printf "start rest cycle %s\a\n" $(($counter + 1)) + sleep $(($2 * 60)) + counter=$(($counter + 1)) + done + exit 0 + ;; + *"stopwatch"*) + now=$(date +%s) + read var + printf "%s\n" $(($(date +%s) - $now)) + exit 0 + ;; + *"verbosewatch"*) + min=0 + sec=0 + while true; do + printf "%02d:%02d\r" $min $sec + sleep 1 + sec=$(($sec + 1)) + [ $sec -eq 60 ] && min=$(($min + 1)) && sec=0 + done + exit 0 + ;; + *) + printf "unknown invocation\n" + exit 2 + ;; esac diff --git a/scripts/yt b/scripts/yt index fbd2625..7fa360f 100755 --- a/scripts/yt +++ b/scripts/yt @@ -23,44 +23,44 @@ see yt(1) for more information on usage " } sync () { - for i in $(cat $YT_DATFILE | tr '\n' ' '); do - torify curl -s \ - https://www.youtube.com/feeds/videos.xml?channel_id=$i\ - > ${YT_CACHEDIR}/$i - done + for i in $(cat $YT_DATFILE | tr '\n' ' '); do + torify curl -s \ + https://www.youtube.com/feeds/videos.xml?channel_id=$i\ + > ${YT_CACHEDIR}/$i + done } display () { - tmp1=$(mktemp) - tmp2=$(mktemp) - for i in $(ls $YT_CACHEDIR | tr '\n' ' '); do - grep \ ${YT_CACHEDIR}/$i | cut -c 17- | \ - rev | cut -c 15- | rev >> $tmp1 - grep 'link rel' ${YT_CACHEDIR}/$i | grep 'watch' | \ - cut -c31- | rev | cut -c4- | rev >> $tmp2 - done - cat $tmp1 $tmp2 | pr -2t -s" | " + tmp1=$(mktemp) + tmp2=$(mktemp) + for i in $(ls $YT_CACHEDIR | tr '\n' ' '); do + grep \ ${YT_CACHEDIR}/$i | cut -c 17- | \ + rev | cut -c 15- | rev >> $tmp1 + grep 'link rel' ${YT_CACHEDIR}/$i | grep 'watch' | \ + cut -c31- | rev | cut -c4- | rev >> $tmp2 + done + cat $tmp1 $tmp2 | pr -2t -s" | " } add () { # $1: name of channel id - printf "%s\n" $1 >> $DATFILE + printf "%s\n" $1 >> $DATFILE } del () { # $1: line number of channel id - sed -i "${1}d" $DATFILE + sed -i "${1}d" $DATFILE } case $1 in - *"s"*) - sync - ;; - *"a"*) - [ $# -eq 2 ] && add $2 - ;; - *"d"*) - [ $# -eq 2 ] && del $2 - ;; - *"h"*) - info - ;; - *) - display - ;; + *"s"*) + sync + ;; + *"a"*) + [ $# -eq 2 ] && add $2 + ;; + *"d"*) + [ $# -eq 2 ] && del $2 + ;; + *"h"*) + info + ;; + *) + display + ;; esac exit 0 From 55f62d3467d1f712fb277e1961f07ec90c7bda45 Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 16 Feb 2021 10:38:21 -0600 Subject: [PATCH 015/197] retab scream.c --- progs/scream.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/progs/scream.c b/progs/scream.c index c39b08f..eacf2a9 100644 --- a/progs/scream.c +++ b/progs/scream.c @@ -5,30 +5,30 @@ * good night and good riddance */ char newchar(char c, int i) { - switch(i) { - case 0: - if(isupper(c)) return c + 32; - if(c == 33) return -2; - else return c; - case 1: - if(islower(c)) return c - 32; - if(c == 33) return -2; - else return c; - default: return -1; - } + switch(i) { + case 0: + if(isupper(c)) return c + 32; + if(c == 33) return -2; + else return c; + case 1: + if(islower(c)) return c - 32; + if(c == 33) return -2; + else return c; + default: return -1; + } } int advi(int i) { - switch(i) { - case 0: return 1; - case 1: return 0; - default: return -1; - } + switch(i) { + case 0: return 1; + case 1: return 0; + default: return -1; + } } int main(void) { - char c; - int i = 0; - while((c = getchar()) != EOF) { - putchar(newchar(c, i)); - i = advi(i); - } + char c; + int i = 0; + while((c = getchar()) != EOF) { + putchar(newchar(c, i)); + i = advi(i); + } } From 1071d2c3729dc6d1b645cb3eaf4d4a5a9c306e21 Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 16 Feb 2021 22:59:36 -0600 Subject: [PATCH 016/197] assorted updates --- progs/scream | Bin 0 -> 16256 bytes scripts/timer | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ scripts/wall | 4 ++-- 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100755 progs/scream create mode 100755 scripts/timer diff --git a/progs/scream b/progs/scream new file mode 100755 index 0000000000000000000000000000000000000000..cd4cd03a1554352d23d753d4cf9b5cfbe45dcac9 GIT binary patch literal 16256 zcmeHOU2GKB6~4Q+!4$k}e&Yba8v?3H<;DD2PE&_j+iS+i{1j}GD8P8VJGNI^@4CCQ z#Ezh~)FYoG_90}YOXZ<-Sge^oqOlZo$+1o+;4>2TfH8S;8G$U6KHi+T8zRC4O|gI5e=dO zKG%r{!~&p8;ZUgAiC4T<17kV)l>nly3M)l$twjq)9w8#??p1z*1A@XR=sZwYh7Dvp zv5dyS$nE+50w{(Oke_+%LI)^}b{!67s#Z3Osm4Nlg7VTu$T~DpH%q!%(lJg_e~g?@ z%n2S1bRJGrpbd*6KZS7W21)0{7V>ArKCm2o+lc)){p}}RX+VY%PULx@nm+ecCewowtjmslL~H?J>$6Q;J`Vx zYj3CU4vPuoSnm;@0^3VAxX6OOE8xJiqyFbTzc`!SSF`ER?u*KeGfh*sHr#g;eegUm zCi-AOf1WaEV;di6|EC2t%ZfO60T(F32Z1Z*zvv$Pao_`RILjyy0VfG|H5}`U@JoR! z)~^`I8qvN;TJ-7`YFgA78ql?FEs=@}um&SqPdph(#Glc@gv%M#GDakAX#J6RQlO1j zvtI0KZ)amgx1!vM~mrcy*HjQ^mNCb=0qx~cSO1q7_GNIm858z8xEXLW;AX(h!2g_q5B%#sR!80~S4Yd<*erzl?1bSp zFRLTJDZe0Nn>(%nZEk!EKK<1S)X?t3w(FB7l#PEz8<%$1FH8FmXyX#|`UKb*f6G7H za<3j$bJx_7w`TTtw2ze?gLZYS!UUN*);JDet~>y`4^M&lQ>dt8Wj{oCWY$;-LknUZ zhPKF@^j8lba=Cde>M10m>*qxjEV6uWp&w z8n59u9X0p1QK61Dt^(d%c^RmwD4fj2vL!%xj$G&o`m4W*!w?sG z=IfXrjCZ{kd^;fqB(^d)o6F8V7oHnAF)NI6`1Bac^zo_J?wY1LTB-V94$rBc3DtAi ze^&U7_&@Ip>6Ifth$z8^ zRzNWS%M(z0^NwkbhUcJm2Dn^!Zt5y9&xLOfpSW#ie|7d+}Cf6M*@=kHTTLWe^~LPtZI{Tg9^II|JuywA^cJT8xEXLW;AY_eHv{;4lxI!JqY9iN{^qiF#xxDU!+?hYJ8zigIN&Y7mjDCro915u zj|0vDz6;m_UmEeZOe~&f4hYX+rDx5Oh2^J+Ukm)~zf2RqWQ&%C@~5v2P~8s4Y2Xz= z;j3)*RqggKe!6^E>|Fim!`n8jM;f(<;dlYYa|Vf!ukxg~xnhBL9D1hxaF`WiyMx{$A?$rotyRWq-Hv?`4+zhxG za5La$z|DZ00XG9~20qUW@Oy*&o*;Zxkwqa~LdY*B!b^#=%+kx3_mj=Fti7ZX+yt|Vk2nGlM_!0({4sD%9e z6u;wQxz7U8MIAGLng+(_H9>y(o+}pa|F&tJ4^Yw-evp;tH$Zy$1ytIcXZZRm?W5HG z5!v~1%jlo~2ftVD?75y^P;DhV#4oIpBfnR=tGW5hff{%_c~f9ZU2to#&KbyIV?Ij7 z4bwpjoPQo@8K;B<$YB*=G5-hd!Pfxq6+UswF<$)N0P+(KzL9voFTj-LAbfhn{X$VJ zo3EoL`4##1Z>?4#PC^Ca=kGIW_^$L{o_~**{a=8}XF0E5$vDfz;RiXwJQj=dTiLw) z6XSeC##t$x*Zms#^Zm`yZ_3J2Q5s;z!g5H62k#=Kkbe_+FJ4VYp4S1t4DvHW&l9>0 zL{RdDG0iyjzWg5W(C|n2}0nv`BVPL{t3(3Ej|R@Ng>Xf%^pFS|pv03~74ONDqmgbfjO`V%h%w zA&}TC4M$Sonu(_MNWUCy>w(aouom9iqQRzsLeH4cTAth++SArt*dli%00j?FEv#x* z1hwUW&~~-&YYMe%`&wHMhC8&5P*Zytqsn~@(M(p3nKwZwyocdacP{9$h!Np1^V=Z` z18C@EZExW16%L2O{SR6!lhXPk$r$d9Xxj(MSUjm^GkQ!U^{3@74covmgD`^bOoqCU z`!OQ1V{u?%p9LonH((UqRZ+ON!!a`3CXjr~HX(wUp?)LM4QQk-?BiNI3Hv(+L{Lt; z-efj7kWLNgX=BJnb!X$S6DS@dD%8|gi_HeGy(f!pk>QaSToU5a2*0i`r}dPH3hNY zBPcttf z?1k55%+*81t{)^lBmT}{FZ{e^t_>=7J+D6)1MEoX)ISdVEm+I(_<4QH$mh@NTj%&A zpvSc>>v{dlc!m1KF=C!s&+E`QaCpkB=k+w>^U!857{gw^1_rKGS!8QAFWbESWvrvloa5&)j6nr+%6eXZGft2r_wPLaACSI@{CGXjsM_?n=6CAP0Eao@ z`1q$;7DE1>L#!Mt*Ad6zug3 zIQDnW-xo>G*I5L}lhEnUHsh~J&%@+(B4Z1MV_+TImmGREV6`w-VRCGRuOCx?go+Oi zy6yApY~Jtb^kcPDB5IRCM*j<4f~ zz@ZE4d7s`DTDaAq$W~a-_z|?(^+F-%ItvMiobR9YUJ%>$b)>H&A&-*-ur6bw8| literal 0 HcmV?d00001 diff --git a/scripts/timer b/scripts/timer new file mode 100755 index 0000000..da5fa4c --- /dev/null +++ b/scripts/timer @@ -0,0 +1,52 @@ +#!/bin/sh + +case $0 in + *"timer"*) + [ $# -ne 2 ] && printf "specify minutes and \ + seconds\n" && exit 1 + sleep $(($1 * 60 + $2)) + printf "your timer is done\a\n" + exit 0 + ;; + *"alarm"*) + [ $# -ne 1 ] && printf "specify time\n" && exit 1 + ttw=$(($(date +%s --date="$1 tomorrow") - $(date +%s))) + sleep $ttw + printf "your alarm is done\a\n" + exit 0 + ;; + *"tomato"*) + [ $# -ne 2 ] && \ + printf "specify work and rest time\n" && exit 1 + counter=0 + while true; do + printf "start work cycle %s\a\n" $(($counter + 1)) + sleep $(($1 * 60)) + printf "start rest cycle %s\a\n" $(($counter + 1)) + sleep $(($2 * 60)) + counter=$(($counter + 1)) + done + exit 0 + ;; + *"stopwatch"*) + now=$(date +%s) + read var + printf "%s\n" $(($(date +%s) - $now)) + exit 0 + ;; + *"verbosewatch"*) + min=0 + sec=0 + while true; do + printf "%02d:%02d\r" $min $sec + sleep 1 + sec=$(($sec + 1)) + [ $sec -eq 60 ] && min=$(($min + 1)) && sec=0 + done + exit 0 + ;; + *) + printf "unknown invocation\n" + exit 2 + ;; +esac diff --git a/scripts/wall b/scripts/wall index a32eebe..2dbf520 100755 --- a/scripts/wall +++ b/scripts/wall @@ -1,7 +1,7 @@ #!/bin/sh -WALLDIR="${HOME}/.share/wallpapers" -TEEFILE="${WALLDIR}/hist" +WALLDIR="${HOME}/.local/share/wallpapers" +TEEFILE="${WALLDIR}/.hist" BASECMD="feh --bg-fill" generate_wall () { From ce3431afa85539236a267a072f62114d36a9924c Mon Sep 17 00:00:00 2001 From: randomuser Date: Sat, 6 Mar 2021 21:40:23 -0600 Subject: [PATCH 017/197] updates to yt --- scripts/yt | 61 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 16 deletions(-) diff --git a/scripts/yt b/scripts/yt index 7fa360f..eeaa914 100755 --- a/scripts/yt +++ b/scripts/yt @@ -2,11 +2,9 @@ [ -z "${YT_DATFILE}" ] && YT_DATFILE="${HOME}/.local/share/ytdat" [ -z "${YT_CACHEDIR}" ] && YT_CACHEDIR="${HOME}/.local/share/ytcache" +[ -z "${YT_TORIFY}" ] && YT_TORIFY="torify" ver=0.1 -touch $DATFILE -mkdir -p $CACHEDIR - info () { printf %s "\ yt - youtube tool @@ -15,21 +13,38 @@ yt - youtube tool => [a]dd [id] - Add a channel to the list => [d]el [id] - Remove a channel from the list => [h]elp - Show this help +=> [i]d [url] - Show internal channel id -List file: export DATFILE= -Cache directory: export CACHEDIR= - -see yt(1) for more information on usage +List file: export YT_DATFILE= +Cache directory: export YT_CACHEDIR= +Torify wrapper: export YT_TORIFY= " } +cache () { + touch ${YT_DATFILE} + mkdir -p ${YT_CACHEDIR} +} +err () { + printf "err: %s\n" ${1} + [ -z ${2} ] 2=1 + exit ${2} +} sync () { + cache for i in $(cat $YT_DATFILE | tr '\n' ' '); do - torify curl -s \ + ${YT_TORIFY} curl -s \ https://www.youtube.com/feeds/videos.xml?channel_id=$i\ > ${YT_CACHEDIR}/$i done } +id () { + ${YT_TORIFY} curl "${1}" -s | \ + grep 'youtube/www\.youtube\.com/channel/.\{24\}' -o | \ + awk -F'/' '{print $NF}' | \ + sed 1q +} display () { + cache tmp1=$(mktemp) tmp2=$(mktemp) for i in $(ls $YT_CACHEDIR | tr '\n' ' '); do @@ -41,26 +56,40 @@ display () { cat $tmp1 $tmp2 | pr -2t -s" | " } add () { # $1: name of channel id - printf "%s\n" $1 >> $DATFILE + cache + printf "%s\n" $1 >> ${YT_DATFILE} } del () { # $1: line number of channel id - sed -i "${1}d" $DATFILE + cache + sed -i "${1}d" ${YT_DATFILE} } case $1 in - *"s"*) + "s"*) sync + exit 0 ;; - *"a"*) - [ $# -eq 2 ] && add $2 + "a"*) + [ $# -eq 2 ] && add $2 || \ + err "two args required" + exit 0 ;; - *"d"*) - [ $# -eq 2 ] && del $2 + "d"*) + [ $# -eq 2 ] && del $2 || \ + err "two args required" + exit 0 ;; - *"h"*) + "h"*) info + exit 0 + ;; + "i"*) + [ $# -eq 2 ] && id $2 || \ + err "two args required" + exit 0 ;; *) display + exit 0 ;; esac exit 0 From 014ed7757438965f3b0ffe3d11532e30a8e98bc7 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sat, 6 Mar 2021 21:47:29 -0600 Subject: [PATCH 018/197] remove bug in err --- scripts/yt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/yt b/scripts/yt index eeaa914..d334c10 100755 --- a/scripts/yt +++ b/scripts/yt @@ -26,7 +26,7 @@ cache () { } err () { printf "err: %s\n" ${1} - [ -z ${2} ] 2=1 + [ -z "${2}" ] 2=1 exit ${2} } sync () { From d454a801de98759aa08de926504c5f383908b180 Mon Sep 17 00:00:00 2001 From: randomuser Date: Mon, 26 Apr 2021 10:58:26 -0500 Subject: [PATCH 019/197] add bspc support --- scripts/disp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/scripts/disp b/scripts/disp index f4ac8d4..e9a7af9 100755 --- a/scripts/disp +++ b/scripts/disp @@ -7,23 +7,28 @@ exists() { # usual setup: thinkpad x220 on dock connected to external # monitor -[ $(exists "HDMI2") -gt 0 ] && \ - [ $(exists "LVDS1") -gt 0 ] && \ +[ $(exists "HDMI2") -eq 1 ] && \ + [ $(exists "LVDS1") -eq 1 ] && \ xrandr --output LVDS1 --below HDMI2 --auto && \ + bspc monitor LVDS1 I II III IV V && \ + bspc monitor HDMI2 VI VII VIII IX X && \ exit 0 || exit 1 # thinkpad x220 connected to display on local port -[ $(exists "HDMI1") -gt 0 ] && \ - [ $(exists "LVDS1") -gt 0 ] && \ +[ $(exists "HDMI1") -eq 1 ] && \ + [ $(exists "LVDS1") -eq 1 ] && \ xrandr --output LVDS1 --below HDMI1 --auto && \ + bspc monitor LVDS1 I II III IV V && \ + bspc monitor HDMI1 VI VII VIII IX X && \ exit 0 || exit 1 # only the thinkpad [ $(exists "HDMI2") -eq 0 ] && \ - [ $(exists "LVDS1") -gt 0 ] && \ + [ $(exists "LVDS1") -eq 1 ] && \ xrandr --output HDMI2 --off && \ + bspc monitor -d I II III IV V VI VII VIII IX X && \ exit 0 || exit 1 exit 1 From 4a26f5ef9fecaabd9443156dc1e367e05eb6326a Mon Sep 17 00:00:00 2001 From: randomuser Date: Mon, 26 Apr 2021 10:58:46 -0500 Subject: [PATCH 020/197] update makefile --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 658d78d..181e1e0 100644 --- a/Makefile +++ b/Makefile @@ -17,3 +17,5 @@ mkc: cc progs/scream.c -o progs/scream c: cp -f progs/scream $(DESTDIR)$(PREFIX)/bin +clean: + rm progs/scream From d821090612b9b0e8d1ed6387a5f5324dc425b0d7 Mon Sep 17 00:00:00 2001 From: randomuser Date: Mon, 26 Apr 2021 10:59:12 -0500 Subject: [PATCH 021/197] update yt --- scripts/yt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/yt b/scripts/yt index d334c10..be9c18d 100755 --- a/scripts/yt +++ b/scripts/yt @@ -2,7 +2,7 @@ [ -z "${YT_DATFILE}" ] && YT_DATFILE="${HOME}/.local/share/ytdat" [ -z "${YT_CACHEDIR}" ] && YT_CACHEDIR="${HOME}/.local/share/ytcache" -[ -z "${YT_TORIFY}" ] && YT_TORIFY="torify" +[ -z "${YT_TORIFY}" ] && YT_TORIFY="" ver=0.1 info () { @@ -14,6 +14,7 @@ yt - youtube tool => [d]el [id] - Remove a channel from the list => [h]elp - Show this help => [i]d [url] - Show internal channel id +=> [c]lear - Clear cache List file: export YT_DATFILE= Cache directory: export YT_CACHEDIR= @@ -63,6 +64,9 @@ del () { # $1: line number of channel id cache sed -i "${1}d" ${YT_DATFILE} } +cclear () { + rm -r ${YT_CACHEDIR} +} case $1 in "s"*) sync @@ -87,6 +91,10 @@ case $1 in err "two args required" exit 0 ;; + "c"*) + cclear + exit 0 + ;; *) display exit 0 From 2b715c69710ba67a1c0f9c82a9b5790327cae894 Mon Sep 17 00:00:00 2001 From: randomuser Date: Mon, 26 Apr 2021 10:59:31 -0500 Subject: [PATCH 022/197] update scream --- progs/scream | Bin 16256 -> 16256 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/progs/scream b/progs/scream index cd4cd03a1554352d23d753d4cf9b5cfbe45dcac9..08dff10bcb5cdea9a9c23091db8800565d501cd1 100755 GIT binary patch delta 58 zcmZpuZ>ZnU!K_;@rIFTd;re-oMNV78a~^?8&iH;71_lNJAZ7$&cfU{|$-n>-W7)iw H`Ls0v5cCeJ delta 58 zcmZpuZ>ZnU!K}MJZOisje+|truVW4$7dpN8rXv28g@J)V0EiiZ*xfG_NHQ=m12NO) It<0yb0c;5n`2YX_ From 8ec60f87523e739772e328efbab96d347896763e Mon Sep 17 00:00:00 2001 From: randomuser Date: Mon, 26 Apr 2021 11:07:35 -0500 Subject: [PATCH 023/197] make the thing work for goodness sake --- scripts/disp | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/scripts/disp b/scripts/disp index e9a7af9..d8ef095 100755 --- a/scripts/disp +++ b/scripts/disp @@ -4,31 +4,19 @@ exists() { xrandr | grep ' connected' | grep "${1}" | wc -l } -# usual setup: thinkpad x220 on dock connected to external -# monitor +if [ $(exists "HDMI2") -eq 1 ] && [ $(exists "LVDS1") -eq 1 ]; then + xrandr --output LVDS1 --below HDMI2 --auto + bspc monitor LVDS1 I II III IV V + bspc monitor HDMI2 VI VII VIII IX + exit 0 +fi -[ $(exists "HDMI2") -eq 1 ] && \ - [ $(exists "LVDS1") -eq 1 ] && \ - xrandr --output LVDS1 --below HDMI2 --auto && \ - bspc monitor LVDS1 I II III IV V && \ - bspc monitor HDMI2 VI VII VIII IX X && \ - exit 0 || exit 1 +if [ $(exists "HDMI1") -eq 1 ] && [ $(exists "LVDS1") -eq 1 ]; then + xrandr --output LVDS1 --below HDMI1 --auto + bspc monitor LVDS1 I II III IV V + bspc monitor HDMI1 VI VII VIII IX + exit 0 +fi -# thinkpad x220 connected to display on local port - -[ $(exists "HDMI1") -eq 1 ] && \ - [ $(exists "LVDS1") -eq 1 ] && \ - xrandr --output LVDS1 --below HDMI1 --auto && \ - bspc monitor LVDS1 I II III IV V && \ - bspc monitor HDMI1 VI VII VIII IX X && \ - exit 0 || exit 1 - -# only the thinkpad - -[ $(exists "HDMI2") -eq 0 ] && \ - [ $(exists "LVDS1") -eq 1 ] && \ - xrandr --output HDMI2 --off && \ - bspc monitor -d I II III IV V VI VII VIII IX X && \ - exit 0 || exit 1 - -exit 1 +bspc monitor -d I II III IV V VI VII VIII IX X +exit 0 From dba873a10dcb86f8e13470522a25c0adcc8120a5 Mon Sep 17 00:00:00 2001 From: randomuser Date: Mon, 26 Apr 2021 11:08:40 -0500 Subject: [PATCH 024/197] add verbosity --- scripts/disp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/disp b/scripts/disp index d8ef095..23b039f 100755 --- a/scripts/disp +++ b/scripts/disp @@ -5,6 +5,7 @@ exists() { } if [ $(exists "HDMI2") -eq 1 ] && [ $(exists "LVDS1") -eq 1 ]; then + printf "HDMI2, LVDS1 exists\n" xrandr --output LVDS1 --below HDMI2 --auto bspc monitor LVDS1 I II III IV V bspc monitor HDMI2 VI VII VIII IX @@ -12,11 +13,13 @@ if [ $(exists "HDMI2") -eq 1 ] && [ $(exists "LVDS1") -eq 1 ]; then fi if [ $(exists "HDMI1") -eq 1 ] && [ $(exists "LVDS1") -eq 1 ]; then + printf "HDMI1, LVDS1 exists\n" xrandr --output LVDS1 --below HDMI1 --auto bspc monitor LVDS1 I II III IV V bspc monitor HDMI1 VI VII VIII IX exit 0 fi +printf "defaulting to default configuration\n" bspc monitor -d I II III IV V VI VII VIII IX X exit 0 From cbb66c88a87b9fab23f803d72687fbfc2fd9f833 Mon Sep 17 00:00:00 2001 From: randomuser Date: Mon, 10 May 2021 16:55:41 -0500 Subject: [PATCH 025/197] add urlhandler --- Makefile | 1 + scripts/urlhandle | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100755 scripts/urlhandle diff --git a/Makefile b/Makefile index 181e1e0..e3f316d 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,7 @@ sh: cp -f scripts/shime $(DESTDIR)$(PREFIX)/bin cp -f scripts/wall $(DESTDIR)$(PREFIX)/bin cp -f scripts/yt $(DESTDIR)$(PREFIX)/bin + cp -f scripts/urlhandle $(DESTDIR)$(PREFIX)/bin mkc: cc progs/scream.c -o progs/scream c: diff --git a/scripts/urlhandle b/scripts/urlhandle new file mode 100755 index 0000000..b8a3658 --- /dev/null +++ b/scripts/urlhandle @@ -0,0 +1,18 @@ +#!/bin/sh + +# access gemini and gopher urls within vimb with vulpes proxy + +# yes, this will result in urls like +# 'proto://host.tld/page?q="://" becoming +# 'proto/host.tld/page?q="/" +stripped_url=`printf "%s" $1 | sed 's|://|/|g'` + +# use xdotool to type the correct commands into the vimb +# window, assuming that the window is currently focused (which +# happens most of the time) +xdotool key Escape +xdotool key Escape +xdotool type "ohttp://proxy.vulpes.one/${stripped_url}" +xdotool key Return + +exit 0 From 215320b6324e265854372e7907f837e6c9df9ddd Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 11 May 2021 07:19:45 -0500 Subject: [PATCH 026/197] fix err() in yt --- scripts/yt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/yt b/scripts/yt index be9c18d..3be6e6f 100755 --- a/scripts/yt +++ b/scripts/yt @@ -27,7 +27,7 @@ cache () { } err () { printf "err: %s\n" ${1} - [ -z "${2}" ] 2=1 + [ -z "${2}" ] && 2=1 exit ${2} } sync () { From b2c8833a7f6a8e08ffb112ef24eee525f819a68a Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 11 May 2021 10:37:58 -0500 Subject: [PATCH 027/197] add connect script --- scripts/connect | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 scripts/connect diff --git a/scripts/connect b/scripts/connect new file mode 100755 index 0000000..778c174 --- /dev/null +++ b/scripts/connect @@ -0,0 +1,21 @@ +#!/bin/sh + +case $1 in + "c"*) + wpa_supplicant -iwlp3s0 -c/etc/wpa_supplicant/wpa_supplicant.conf -B + dhcpcd wlp3s0 + tor & disown + "d"*) + killall -15 wpa_supplicant dhcpcd tor + "r"*) + sh $0 d + sh $0 c + *) + printf "\ +simple wrapper for connecting to a network +${0} restart to restart wifi +${0} disconnect to disconnect +${0} connect to connect to network +" +easc +exit 0 From d379e34aefd5169ea5e67489f8451a49c632cda2 Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 11 May 2021 10:51:27 -0500 Subject: [PATCH 028/197] prelim script nws --- scripts/nws | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100755 scripts/nws diff --git a/scripts/nws b/scripts/nws new file mode 100755 index 0000000..a222b3d --- /dev/null +++ b/scripts/nws @@ -0,0 +1,88 @@ +#!/bin/sh + +set -x + +[ -z "${XDG_CONFIG_DIR}" ] && XDG_CONFIG_DIR="${HOME}/.config" +[ -z "${NWS_CONFIG}" ] && NWS_CONFIG="${XDG_CONFIG_DIR}/nws" +[ -n "${NWS_ZONE}" ] || \ + [ -e ${NWS_CONFIG} ] && NWS_ZONE=$(cat ${NWS_CONFIG}) || \ + NWS_ZONE="KGYX" +[ -z "${NWS_GIF}" ] && NWS_GIF="mpv --loop" +[ -z "${NWS_TORIFY}" ] && NWS_TORIFY="" + + +info () { + printf %s "\ +nws - wrapper for the National Weather Service's website + +=> [n]ational - View national weather mosaic +=> [l]ocal - View local weather mosaic +=> [r]ivers - View local river conditions +=> [w]eather - View local weather observations [!] +=> [m]osaic [id] - View a given area's weather mosaic [!] +=> [z]ones - List internal zone names [!] +=> [s]et [id] - Set local zone [!] +=> [o]bservations - View observations in specific catagories [!] + +Default zone: export NWS_ZONE= +GIF player: export NWS_GIF= +Configuration: export NWS_CONFIG= +Torify wrapper: export NWS_TORIFY= +" +} +err () { + printf "err: %s\n" ${1} + [ -z "${2}" ] && exit 1 + exit ${2} +} +national () { + ${NWS_GIF} 'https://radar.weather.gov/ridge/lite/CONUS-LARGE_loop.gif' +} +# name interestingly to avoid keyword collision +localradar () { + ${NWS_GIF} "https://radar.weather.gov/ridge/lite/${NWS_ZONE}_loop.gif" +} +setzone () { + printf "%s" "${1}" > ${NWS_CONFIG} +} +river () { + curl "https://forecast.weather.gov/product.php?site=NWS&issuedby=${NWS_ZONE}&product=RVA&format=TXT&version=1" | \ + sed -n '//,/<\/pre>/p' | \ + grep -v "a href" | \ + grep -v '' | \ + grep -v '<\/pre>' || \ + printf "river data not found for zone %s" ${NWS_ZONE} +} + +case $1 in + "n"*) + national + exit 0 + ;; + "l"*) + localradar + exit 0 + ;; + "r"*) + river + exit 0 + ;; + "w"*) + ;; + "m"*) + ;; + "z"*) + ;; + "s"*) + [ $# -eq 2 ] && setzone $2 || \ + err "two args required" + exit 0 + ;; + "o"*) + ;; + *) + info + exit 0 + ;; +esac +exit 0 From 2dc96260069e6f7e410b226f3eed330b33291411 Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 11 May 2021 11:03:20 -0500 Subject: [PATCH 029/197] add makefile --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index e3f316d..decd98f 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,8 @@ sh: cp -f scripts/shime $(DESTDIR)$(PREFIX)/bin cp -f scripts/wall $(DESTDIR)$(PREFIX)/bin cp -f scripts/yt $(DESTDIR)$(PREFIX)/bin + cp -f scripts/connect $(DESTDIR)$(PREFIX)/bin + cp -f scripts/nws $(DESTDIR)$(PREFIX)/bin cp -f scripts/urlhandle $(DESTDIR)$(PREFIX)/bin mkc: cc progs/scream.c -o progs/scream From 521ddd15ac285f700603821c164d41764a2631b1 Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 11 May 2021 11:06:16 -0500 Subject: [PATCH 030/197] add ;; to case --- scripts/connect | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/connect b/scripts/connect index 778c174..2d529cc 100755 --- a/scripts/connect +++ b/scripts/connect @@ -5,11 +5,14 @@ case $1 in wpa_supplicant -iwlp3s0 -c/etc/wpa_supplicant/wpa_supplicant.conf -B dhcpcd wlp3s0 tor & disown + ;; "d"*) killall -15 wpa_supplicant dhcpcd tor + ;; "r"*) sh $0 d sh $0 c + ;; *) printf "\ simple wrapper for connecting to a network From 751bf87e06491e5fa5c13b7bb4ff139cfa2fa024 Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 11 May 2021 11:12:23 -0500 Subject: [PATCH 031/197] fix 'connect' --- scripts/connect | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/connect b/scripts/connect index 2d529cc..4ffbee4 100755 --- a/scripts/connect +++ b/scripts/connect @@ -20,5 +20,6 @@ ${0} restart to restart wifi ${0} disconnect to disconnect ${0} connect to connect to network " -easc + ;; +esac exit 0 From e1b91a53e148cc7afad497e67693bbcd79d7cedb Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 11 May 2021 13:10:50 -0500 Subject: [PATCH 032/197] update nws --- scripts/nws | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/scripts/nws b/scripts/nws index a222b3d..96a6f54 100755 --- a/scripts/nws +++ b/scripts/nws @@ -1,7 +1,5 @@ #!/bin/sh -set -x - [ -z "${XDG_CONFIG_DIR}" ] && XDG_CONFIG_DIR="${HOME}/.config" [ -z "${NWS_CONFIG}" ] && NWS_CONFIG="${XDG_CONFIG_DIR}/nws" [ -n "${NWS_ZONE}" ] || \ @@ -18,11 +16,10 @@ nws - wrapper for the National Weather Service's website => [n]ational - View national weather mosaic => [l]ocal - View local weather mosaic => [r]ivers - View local river conditions -=> [w]eather - View local weather observations [!] -=> [m]osaic [id] - View a given area's weather mosaic [!] -=> [z]ones - List internal zone names [!] -=> [s]et [id] - Set local zone [!] -=> [o]bservations - View observations in specific catagories [!] +=> [w]eather - View local weather observations +=> [m]osaic [id] - View a given area's weather mosaic +=> [s]et [id] - Set local zone +=> [t]ext [id] - View text messages by catagory Default zone: export NWS_ZONE= GIF player: export NWS_GIF= @@ -35,23 +32,35 @@ err () { [ -z "${2}" ] && exit 1 exit ${2} } +kstrip () { + printf %s "$1" | sed 's/^K\(.*\)/\1/' +} national () { - ${NWS_GIF} 'https://radar.weather.gov/ridge/lite/CONUS-LARGE_loop.gif' + mosaic CONUS-LARGE } # name interestingly to avoid keyword collision localradar () { - ${NWS_GIF} "https://radar.weather.gov/ridge/lite/${NWS_ZONE}_loop.gif" + mosaic ${NWS_ZONE} +} +mosaic () { + ${NWS_GIF} "https://radar.weather.gov/ridge/lite/${1}_loop.gif" } setzone () { printf "%s" "${1}" > ${NWS_CONFIG} } river () { - curl "https://forecast.weather.gov/product.php?site=NWS&issuedby=${NWS_ZONE}&product=RVA&format=TXT&version=1" | \ + textmessage "RVA" +} +weather () { + textmessage "ZFP" +} +textmessage () { + curl --fail "https://forecast.weather.gov/product.php?site=NWS&issuedby=$(kstrip ${NWS_ZONE})&product=${1}&format=TXT&version=1" | \ sed -n '//,/<\/pre>/p' | \ grep -v "a href" | \ grep -v '' | \ grep -v '<\/pre>' || \ - printf "river data not found for zone %s" ${NWS_ZONE} + printf "${1} data not found for zone %s" ${NWS_ZONE} } case $1 in @@ -68,8 +77,12 @@ case $1 in exit 0 ;; "w"*) + weather + exit 0 ;; "m"*) + [ $# -eq 2 ] && mosaid $2 || \ + err "two args required" ;; "z"*) ;; @@ -78,7 +91,9 @@ case $1 in err "two args required" exit 0 ;; - "o"*) + "t"*) + [ $# -eq 2 ] && textmessage $2 || \ + err "two args required" ;; *) info From 714b3bd408ca54b4cca9e1cc86ec8bbbc884966c Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 11 May 2021 14:52:01 -0500 Subject: [PATCH 033/197] changes to nws --- scripts/nws | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/nws b/scripts/nws index 96a6f54..e2e9531 100755 --- a/scripts/nws +++ b/scripts/nws @@ -55,7 +55,7 @@ weather () { textmessage "ZFP" } textmessage () { - curl --fail "https://forecast.weather.gov/product.php?site=NWS&issuedby=$(kstrip ${NWS_ZONE})&product=${1}&format=TXT&version=1" | \ + curl --silent --fail "https://forecast.weather.gov/product.php?site=NWS&issuedby=$(kstrip ${NWS_ZONE})&product=${1}&format=TXT&version=1" | \ sed -n '//,/<\/pre>/p' | \ grep -v "a href" | \ grep -v '' | \ @@ -84,8 +84,6 @@ case $1 in [ $# -eq 2 ] && mosaid $2 || \ err "two args required" ;; - "z"*) - ;; "s"*) [ $# -eq 2 ] && setzone $2 || \ err "two args required" From b1b40869124886cc4db116c180d76df24bb045c1 Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 11 May 2021 20:54:47 -0500 Subject: [PATCH 034/197] fix yt --- scripts/yt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/yt b/scripts/yt index 3be6e6f..111af45 100755 --- a/scripts/yt +++ b/scripts/yt @@ -27,7 +27,7 @@ cache () { } err () { printf "err: %s\n" ${1} - [ -z "${2}" ] && 2=1 + [ -z "${2}" ] && exit 1 exit ${2} } sync () { From 667a3e72387751af4247a18ccff52f1a268a1fa8 Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 11 May 2021 21:39:39 -0500 Subject: [PATCH 035/197] add program indicate --- Makefile | 1 + scripts/disp | 14 ++++++++------ scripts/indicate | 5 +++++ 3 files changed, 14 insertions(+), 6 deletions(-) create mode 100755 scripts/indicate diff --git a/Makefile b/Makefile index decd98f..211872e 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,7 @@ sh: cp -f scripts/connect $(DESTDIR)$(PREFIX)/bin cp -f scripts/nws $(DESTDIR)$(PREFIX)/bin cp -f scripts/urlhandle $(DESTDIR)$(PREFIX)/bin + cp -f scripts/indicate $(DESTDIR)$(PREFIX)/bin mkc: cc progs/scream.c -o progs/scream c: diff --git a/scripts/disp b/scripts/disp index 23b039f..f0bcb4b 100755 --- a/scripts/disp +++ b/scripts/disp @@ -6,20 +6,22 @@ exists() { if [ $(exists "HDMI2") -eq 1 ] && [ $(exists "LVDS1") -eq 1 ]; then printf "HDMI2, LVDS1 exists\n" - xrandr --output LVDS1 --below HDMI2 --auto - bspc monitor LVDS1 I II III IV V - bspc monitor HDMI2 VI VII VIII IX + xrandr --output HDMI2 --above LVDS1 --auto + bspc monitor LVDS1 -a I II III IV V + bspc monitor HDMI2 -a VI VII VIII IX exit 0 fi if [ $(exists "HDMI1") -eq 1 ] && [ $(exists "LVDS1") -eq 1 ]; then printf "HDMI1, LVDS1 exists\n" - xrandr --output LVDS1 --below HDMI1 --auto - bspc monitor LVDS1 I II III IV V - bspc monitor HDMI1 VI VII VIII IX + xrandr --output HDMI1 --above LVDS1 --auto + bspc monitor LVDS1 -a I II III IV V + bspc monitor HDMI1 -a VI VII VIII IX exit 0 fi printf "defaulting to default configuration\n" +xrandr --output HDMI1 --off +xrandr --output HDMI2 --off bspc monitor -d I II III IV V VI VII VIII IX X exit 0 diff --git a/scripts/indicate b/scripts/indicate new file mode 100755 index 0000000..45e9b12 --- /dev/null +++ b/scripts/indicate @@ -0,0 +1,5 @@ +#!/bin/sh + +i=$(date '+%H:%M:%S %m/%d (%h)') +j=$(bat) +printf "%s | %s\n" "$i" "$j" | nenu From 3f3a08b8dd3137a58d6cd496cf044eedf664e14a Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 11 May 2021 21:53:13 -0500 Subject: [PATCH 036/197] add volume script --- Makefile | 1 + scripts/indicate | 3 ++- scripts/vol | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 scripts/vol diff --git a/Makefile b/Makefile index 211872e..134e615 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,7 @@ sh: cp -f scripts/nws $(DESTDIR)$(PREFIX)/bin cp -f scripts/urlhandle $(DESTDIR)$(PREFIX)/bin cp -f scripts/indicate $(DESTDIR)$(PREFIX)/bin + cp -f scripts/vol $(DESTDIR)$(PREFIX)/bin mkc: cc progs/scream.c -o progs/scream c: diff --git a/scripts/indicate b/scripts/indicate index 45e9b12..4c84c42 100755 --- a/scripts/indicate +++ b/scripts/indicate @@ -2,4 +2,5 @@ i=$(date '+%H:%M:%S %m/%d (%h)') j=$(bat) -printf "%s | %s\n" "$i" "$j" | nenu +k=$(vol) +printf "%s | %s\% | %s\n" "$i" "$j" "$k" | nenu diff --git a/scripts/vol b/scripts/vol new file mode 100644 index 0000000..1a71217 --- /dev/null +++ b/scripts/vol @@ -0,0 +1,3 @@ +#!/bin/sh + +amixer sset Master 0amixer sset Master 0%+ | tail -1 | awk -F'[' '{print }' | awk -F']' '{print }' From a64d04091b1e06d80763a0d7e085085f5ca80c73 Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 11 May 2021 21:57:23 -0500 Subject: [PATCH 037/197] really embarassing typo lol --- scripts/vol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 scripts/vol diff --git a/scripts/vol b/scripts/vol old mode 100644 new mode 100755 index 1a71217..3c74a30 --- a/scripts/vol +++ b/scripts/vol @@ -1,3 +1,3 @@ #!/bin/sh -amixer sset Master 0amixer sset Master 0%+ | tail -1 | awk -F'[' '{print }' | awk -F']' '{print }' +amixer sset Master 0amixer sset Master 0%+ | tail -1 | awk -F'[' '{print $2}' | awk -F']' '{print $1}' From 861a77b620b2ab8199650af2d57c67085f21dc60 Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 11 May 2021 21:58:16 -0500 Subject: [PATCH 038/197] commit trigger is rigged lol --- scripts/vol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/vol b/scripts/vol index 3c74a30..8da8183 100755 --- a/scripts/vol +++ b/scripts/vol @@ -1,3 +1,3 @@ #!/bin/sh -amixer sset Master 0amixer sset Master 0%+ | tail -1 | awk -F'[' '{print $2}' | awk -F']' '{print $1}' +amixer sset Master 0%+ | tail -1 | awk -F'[' '{print $2}' | awk -F']' '{print $1}' From aba8a7491042cadcf37a8618f9a225fd2295676c Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 11 May 2021 21:59:07 -0500 Subject: [PATCH 039/197] smh i should go to bed --- scripts/indicate | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/indicate b/scripts/indicate index 4c84c42..31c30e3 100755 --- a/scripts/indicate +++ b/scripts/indicate @@ -3,4 +3,4 @@ i=$(date '+%H:%M:%S %m/%d (%h)') j=$(bat) k=$(vol) -printf "%s | %s\% | %s\n" "$i" "$j" "$k" | nenu +printf "%s | %s | %s\n" "$i" "$j" "$k" | nenu From 6cc75335e60f78a22ba35680da7a66f3cbc4e94a Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 11 May 2021 22:02:41 -0500 Subject: [PATCH 040/197] add connect toggle --- scripts/connect | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/connect b/scripts/connect index 4ffbee4..24a719b 100755 --- a/scripts/connect +++ b/scripts/connect @@ -13,9 +13,14 @@ case $1 in sh $0 d sh $0 c ;; + "t"*) + [ $(ps aux | grep wpa_supplicant | wc -l) -eq 2 ] && sh $0 d && exit + sh $0 c + ;; *) printf "\ simple wrapper for connecting to a network +${0} toggle to toggle wifi connection ${0} restart to restart wifi ${0} disconnect to disconnect ${0} connect to connect to network From b3c3edc658436e6f63c595942f7bd0acf70c4eb5 Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 11 May 2021 22:13:03 -0500 Subject: [PATCH 041/197] whoops. no binaries in the tree! --- progs/scream | Bin 16256 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100755 progs/scream diff --git a/progs/scream b/progs/scream deleted file mode 100755 index 08dff10bcb5cdea9a9c23091db8800565d501cd1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16256 zcmeHOT}&L;6~4QG4Yk?Dza_R~Hjb_0RIKqIB29^BfyG0Fe`&Csnv%%ZIn9wk%^VmxTGnGEwrKzesRCA@7@80j8@7z0Q?hJR>d%qcOYw>zKf>V)rSYWBM!eSJzsOO9jil`Um zaNa2H6-$6FhC`uhCtmSd6^x~1R|JT1$1S_cQ z#1iTUBiHBJ3!oTMK%R5hi3X4u?K z_$g<;&4;MH#qL8T#h;PFE4IaBU3I&*#iKRxSRyl6Ggx0&Q@1OaP6l_#ma$*8aNwBQ zyT3zths6YPtoH~{UfD}!Fp&vuSHpo}NBzll)ji*?58wPzef-Su_2m^qW!f`ngV%vR z(FPN8cyPixKA8JY5H%|c7+>K1BRw=p!JYh7AA*)5j^J*gwYKlmqIyd2jin7e)xNJOo=oWNk*+v;>+Me_$eU)F7Bqyu z&l#maFMJOXyeW!A+Yq+Zbuc})D?;OF%q1_aV9y%(4l#Mdjb zI`@2Y`N|%P$7hI!ydeaDw6J+XG!#IGs<`C#UI19y}Lq;7d`7y$SbH*CzS`hQl zwK8+cUo{NA#Uvrv4@vvoDTJ+e)$FW#@!dV@#knHY^RoKtU1K#kC?N->=2VZrs(C?= z{TpuB4b>vEvqK$exQ1UkYW8iTTpev#3%t4JGEmdqa4|2JEC<4KY_cclulg2tLrnH8 zkpS(ym@6)g>3e zlX+?_l& z!I}T13CO*9$23R7^N>3aTsAyEeHECe!?%Y|-!?P9lRhumLMQJ7#w+w_+gQUBUlt;C zq&53`sG~J|E7Ts!&UdI|HElp2ZrgeX$LRC{@TXq9Q)E{_>*F)y& ztLn(4M}6>bnSbE;ed1W?Xy{nzcu2F~BWw>xHliH&xsi^S<|a1+ZUo#2xDjw8;6}iW zfExif0&WD{2>ky>0Dq72tS@>mGVw=jKgFqxL8q&q06ABN6gdobfi5FY%5;3s(Ippm#w39CF$ncK*0=a7p7FN&D!*G4_65d@!@lb8lr;Nl&n!`W z^&?C7`jmvPKIE$n`KlXzfkt0tqpzaTS1NzID~9Vm2Y&3om!V5Hxe;(9;6}iWfExif z0&WD{2)Ge&Bj85h^Nawm8{~C@@Tnq`Lb#le*CE5AM49Gj@#Q^K=Jkl{smyEi)=`<) zC2nxk-@0oik(!`IhWw3mq1ZCywS-et{{_-NOSp`%l5hZ=2Tj03}V~2U&T21EhyvKxLWZ44<#Ee4Oe(qH?a^ z();Is;&tWDmg{JNY75~JLbl^|rF)y2z7nX0)yZ1}+iQb6g0*b02x2^n#e1f+8podp zYQ`xb0Ww$%Sjhg~Mfhsqy}~EXI{J(M8$f=-!8Z`k&jl1^It*uzxJM|8Rp$GsNq%*1 z{jF6i#2Lt-|J-v%72lKgt8(jj+5S1me3t9_mGrYx9KDY{EMOr&zm?UiKGDxNq@Ojy zdEc**JwM;<{g%wE5XAvzEG&h9cmzB}N_BrTqje5I&W@+*%6Uja`i-!HDM27aa2FZeyiypB80(`)x z=j`*qukcn1eomO5KpulbB6|Ia-vf{Fd7Rd9pC`eeh##iLb>d$Gtbp;UDnt-u$-a}~ zzm53oz@xo0J~zpJGx?YQBLmGG@gGxv1r0v9L5>Gy1h|T%4ZVkftVIar6NO`o-k5Fq9+yU*R^P-zkdiMwvvWD z$umuNr}Rj_>}|`T(7v!1-ruajrht6QsL+}p-yho7+LT`-cO(D>FHkM4YL*AJ`H;}| zwjF2;wP^=hS`LTXwf0bBTNu5{eGJ{{jO;USf>3x5!>8_C(4!F}!fqC}L*zTq(8$`} zz}qVv2KoCRv}ii1^+gg<+#At)0F=>KLd&G}s7UB1yjzqiBDGutMRT+L1)g6W}tBhm$Eq%7>?Tr2_mI|f8h4!Yh%COD8v z4(KUk$VPQ#Vz3h^79}dw*jj_bGKl7Vk#wI3Mu!s6goQ@RsyU&j(y?SBub@F)N{>fS zK)HdqA%Ze0K|>#eJPt>wOUio{)ca@v_C-Oa{>g@VXGGP2Z2ZnsGo?ZUJq33xHBY(%Sy>t9N zPkO%3B0!dePJ1ph{+jgMO`az*Hj_IB)^YigL$3y`8pcWtjxF*1W9pBP@xeileQuu3 z`#qiZTxPrqTE9)t->~Q-$ujc)`Q`CPP|Cm_E_wfVZ(1i88 zPwxs%+^SJzORQ)72|%Bg*4KUtp}mn34n9eM28{XRwx>uJE@dl)@yZ2$lO From 26ea1e5c92abfb5d45fe45922ccbc2abe4c0e71d Mon Sep 17 00:00:00 2001 From: randomuser Date: Wed, 12 May 2021 06:46:35 -0500 Subject: [PATCH 042/197] change timer message --- scripts/shime | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/shime b/scripts/shime index da5fa4c..effebfb 100755 --- a/scripts/shime +++ b/scripts/shime @@ -3,7 +3,7 @@ case $0 in *"timer"*) [ $# -ne 2 ] && printf "specify minutes and \ - seconds\n" && exit 1 +seconds\n" && exit 1 sleep $(($1 * 60 + $2)) printf "your timer is done\a\n" exit 0 From 2ea5dbd49fe88f0a889cdbe345545ffc65415798 Mon Sep 17 00:00:00 2001 From: randomuser Date: Wed, 12 May 2021 12:51:06 -0500 Subject: [PATCH 043/197] scripts/timer updated to have a non-terrible help message --- scripts/timer | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/timer b/scripts/timer index da5fa4c..effebfb 100755 --- a/scripts/timer +++ b/scripts/timer @@ -3,7 +3,7 @@ case $0 in *"timer"*) [ $# -ne 2 ] && printf "specify minutes and \ - seconds\n" && exit 1 +seconds\n" && exit 1 sleep $(($1 * 60 + $2)) printf "your timer is done\a\n" exit 0 From 8d22255c0e9dbb2506ab57e53a7c8db14ccd3f6e Mon Sep 17 00:00:00 2001 From: randomuser Date: Sat, 15 May 2021 21:10:31 -0500 Subject: [PATCH 044/197] add simple xkcd comic browser --- scripts/xkcd | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 scripts/xkcd diff --git a/scripts/xkcd b/scripts/xkcd new file mode 100755 index 0000000..c48302c --- /dev/null +++ b/scripts/xkcd @@ -0,0 +1,40 @@ +#!/bin/sh + +set -x +err () { + printf "err: %s\n" ${1} + [ -z "${2}" ] && exit 1 + exit ${2} +} +getImageForComic() { + [ -z ${1} ] && a="" || a="$1/" + curl --silent https://xkcd.com/${a} | grep 'imgs.xkcd.com/comics/' | sed 1q | grep -o 'https://imgs\.xkcd\.com/comics/.*\....' +} +viewImage() { + a=$(mktemp) + curl --silent $(getImageForComic ${1}) -o $a + feh $a +} +proghelp() { + printf "\ +xkcd - view xkcd comics + +=> [v]iew [id] - View comic with id [id] +=> [g]et [id] - Get url for comic [id] +" +} +case $1 in + 'v'*) + viewImage $2 + exit 0 + ;; + 'g'*) + getImageForComic $2 + exit 0 + ;; + *) + proghelp + exit 0 + ;; +esac +exit 0 From ed580c2b4a57118c9b68a90e7a18d758fb5bd998 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sat, 15 May 2021 21:12:11 -0500 Subject: [PATCH 045/197] append .gitignore to ignore progs/scream --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index fb1aaf1..2d03a57 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.swp *.tmp +progs/scream From e46db5d4afb3fdec28ac8a1a02570c4be0aadd87 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 6 Jun 2021 11:29:48 -0500 Subject: [PATCH 046/197] whoops, actually add in timer application lol --- Makefile | 6 ++++++ scripts/timer | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 134e615..616a993 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,12 @@ sh: cp -f scripts/urlhandle $(DESTDIR)$(PREFIX)/bin cp -f scripts/indicate $(DESTDIR)$(PREFIX)/bin cp -f scripts/vol $(DESTDIR)$(PREFIX)/bin + cp -f scripts/timer $(DESTDIR)$(PREFIX)/bin + ln -sf $(DESTDIR)$(PREFIX)/bin/timer $(DESTDIR)$(PREFIX)/bin/alarm + ln -sf $(DESTDIR)$(PREFIX)/bin/timer $(DESTDIR)$(PREFIX)/bin/tomato + ln -sf $(DESTDIR)$(PREFIX)/bin/timer $(DESTDIR)$(PREFIX)/bin/stopwatch + ln -sf $(DESTDIR)$(PREFIX)/bin/timer $(DESTDIR)$(PREFIX)/bin/verbosewatch + mkc: cc progs/scream.c -o progs/scream c: diff --git a/scripts/timer b/scripts/timer index effebfb..8731fbc 100755 --- a/scripts/timer +++ b/scripts/timer @@ -15,7 +15,7 @@ seconds\n" && exit 1 printf "your alarm is done\a\n" exit 0 ;; - *"tomato"*) + *"tomato"*) [ $# -ne 2 ] && \ printf "specify work and rest time\n" && exit 1 counter=0 From 6f3a0f2851816a87306271e4e092c7c20340c061 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 6 Jun 2021 22:07:13 -0500 Subject: [PATCH 047/197] avoid conflict with 'wall' --- scripts/{wall => wal} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename scripts/{wall => wal} (100%) diff --git a/scripts/wall b/scripts/wal similarity index 100% rename from scripts/wall rename to scripts/wal From 51f01f8eec4ebf60eb827f61a5ee68b13d66709d Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 6 Jun 2021 22:07:45 -0500 Subject: [PATCH 048/197] change the makefile, too --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 616a993..73d2032 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ sh: cp -f scripts/bat $(DESTDIR)$(PREFIX)/bin cp -f scripts/disp $(DESTDIR)$(PREFIX)/bin cp -f scripts/shime $(DESTDIR)$(PREFIX)/bin - cp -f scripts/wall $(DESTDIR)$(PREFIX)/bin + cp -f scripts/wal $(DESTDIR)$(PREFIX)/bin cp -f scripts/yt $(DESTDIR)$(PREFIX)/bin cp -f scripts/connect $(DESTDIR)$(PREFIX)/bin cp -f scripts/nws $(DESTDIR)$(PREFIX)/bin From 7a654466db3ca5b5f2867dcf91c8f5b95e5da381 Mon Sep 17 00:00:00 2001 From: randomuser Date: Thu, 10 Jun 2021 23:10:47 -0500 Subject: [PATCH 049/197] add timer application --- .gitignore | 1 + Makefile | 4 +- rndutils.1 => man/rndutils.1 | 0 progs/timer.c | 164 +++++++++++++++++++++++++++++++++++ 4 files changed, 168 insertions(+), 1 deletion(-) rename rndutils.1 => man/rndutils.1 (100%) create mode 100644 progs/timer.c diff --git a/.gitignore b/.gitignore index 2d03a57..573e5d5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.swp *.tmp progs/scream +progs/timer diff --git a/Makefile b/Makefile index 73d2032..fc04124 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ install: man sh mkc c man: mkdir -p $(DESTDIR)$(PREFIX)/man1 - cp -f *.1 $(DESTDIR)$(PREFIX)/man1 + cp -f man/* $(DESTDIR)$(PREFIX)/man1 sh: mkdir -p $(DESTDIR)$(PREFIX)/bin cp -f scripts/paste $(DESTDIR)$(PREFIX)/bin @@ -26,7 +26,9 @@ sh: mkc: cc progs/scream.c -o progs/scream + cc progs/timer.c -o progs/timer c: cp -f progs/scream $(DESTDIR)$(PREFIX)/bin + cp -f progs/timer $(DESTDIR)$(PREFIX)/bin clean: rm progs/scream diff --git a/rndutils.1 b/man/rndutils.1 similarity index 100% rename from rndutils.1 rename to man/rndutils.1 diff --git a/progs/timer.c b/progs/timer.c new file mode 100644 index 0000000..9a6297b --- /dev/null +++ b/progs/timer.c @@ -0,0 +1,164 @@ +#include +#include +#include +#include +#include + +struct timer { + int m; + int s; + void (*u)(struct timer *t); + int (*c)(struct timer *t); +}; + +struct settings { + int e:1; /* use escape (v assumed) */ + int v:1; /* verbose */ + int d:1; /* count down/up (1/0) */ + int b:1; /* ascii bel when done */ + int f:1; /* display hours */ + int m; /* minutes */ + int s; /* seconds */ +} settings = { + .e = 0, + .v = 0, + .d = 0, + .b = 0, + .f = 0, + .m = 0, + .s = 0 +}; + +void timerdec(struct timer *t) { + if(t->s > 0) t->s--; + else if(t->s == 0) { + t->s = 59; + t->m--; + } +} + +void timerinc(struct timer *t) { + if(t->s < 59) t->s++; + else if(t->s == 59) { + t->s = 0; + t->m++; + } +} + +void timerupdate(struct timer *t) { + if(t->u != NULL) t->u(t); +} + +int timerstate(struct timer *t) { + if(t->c != NULL) { + if(t->c(t)) return 1; + else return 0; + } + return 0; +} + +int timerzero(struct timer *t) { + if(t->m == 0 && t->s == 0) return 1; + return 0; +} + +int timerissettings(struct timer *t) { + if(t->m == 0 && t->s == 0) return 0; + if(t->m == settings.m && + t->s == settings.s) return 1; + return 0; +} + +char *timerdisp(struct timer *t) { + char *str = malloc(20); + if(settings.f) snprintf(str, 20, "%02i:%02i:%02i", + (t->m / 60), (t->m % 60), t->s); + else snprintf(str, 20, "%02i:%02i", t->m, t->s); + return str; +} + +struct timer *timerinit(void) { + struct timer *t = malloc(sizeof t); + t->m = 0; + t->s = 0; + t->u = NULL; + t->c = NULL; + return t; +} + +void timerloop() { + struct timer *t = timerinit(); + if(settings.d) { + t->u = timerdec; + t->m = settings.m; + t->s = settings.s; + t->c = timerzero; + } else { + t->u = timerinc; + t->c = timerissettings; + } + char *c; + struct pollfd *p = malloc(sizeof p); + p->fd = STDIN_FILENO; + p->events = POLLIN; + for(;;) { + poll(p, 1, 60); + if(p->revents == POLLIN) { + /* TODO: make this nicer */ + getchar(); + if(settings.e) { + c = timerdisp(t); + printf("\r\e[1A* %s", c); + } + getchar(); + /* TODO: stop relying on hard assumptions */ + if(settings.e) printf("\r\e[1A \r", c); + } + c = timerdisp(t); + if(settings.e) { + printf("%s\r", c); + fflush(stdout); + } + else if(settings.v) printf("%s\n", c); + if(timerstate(t)) break; + timerupdate(t); + sleep(1); + } + if(settings.b) putchar('\a'); +} + +int main(int argc, char **argv) { + char c; + while((c = getopt (argc, argv, "evdbfm:s:")) != -1) { + switch(c) { + case 'e': + settings.e = 1; + break; + case 'v': + settings.v = 1; + break; + case 'd': + settings.d = 1; + break; + case 'b': + settings.b = 1; + break; + case 'f': + settings.f = 1; + break; + case 'm': + settings.m = atoi(optarg); + break; + case 's': + settings.s = atoi(optarg); + break; + case '?': + return 1; + default: + abort(); + break; + } + } + timerloop(); + return 0; +} From 6d6eec17c7ff54b49025b32047dd97ea39954747 Mon Sep 17 00:00:00 2001 From: randomuser Date: Thu, 10 Jun 2021 23:14:14 -0500 Subject: [PATCH 050/197] get timer to shime, really where it should be --- Makefile | 11 ++++++----- scripts/timer | 52 --------------------------------------------------- 2 files changed, 6 insertions(+), 57 deletions(-) delete mode 100755 scripts/timer diff --git a/Makefile b/Makefile index fc04124..80672b5 100644 --- a/Makefile +++ b/Makefile @@ -18,11 +18,12 @@ sh: cp -f scripts/urlhandle $(DESTDIR)$(PREFIX)/bin cp -f scripts/indicate $(DESTDIR)$(PREFIX)/bin cp -f scripts/vol $(DESTDIR)$(PREFIX)/bin - cp -f scripts/timer $(DESTDIR)$(PREFIX)/bin - ln -sf $(DESTDIR)$(PREFIX)/bin/timer $(DESTDIR)$(PREFIX)/bin/alarm - ln -sf $(DESTDIR)$(PREFIX)/bin/timer $(DESTDIR)$(PREFIX)/bin/tomato - ln -sf $(DESTDIR)$(PREFIX)/bin/timer $(DESTDIR)$(PREFIX)/bin/stopwatch - ln -sf $(DESTDIR)$(PREFIX)/bin/timer $(DESTDIR)$(PREFIX)/bin/verbosewatch + cp -f scripts/shime $(DESTDIR)$(PREFIX)/bin + ln -sf $(DESTDIR)$(PREFIX)/bin/shime $(DESTDIR)$(PREFIX)/bin/timer + ln -sf $(DESTDIR)$(PREFIX)/bin/shime $(DESTDIR)$(PREFIX)/bin/alarm + ln -sf $(DESTDIR)$(PREFIX)/bin/shime $(DESTDIR)$(PREFIX)/bin/tomato + ln -sf $(DESTDIR)$(PREFIX)/bin/shime $(DESTDIR)$(PREFIX)/bin/stopwatch + ln -sf $(DESTDIR)$(PREFIX)/bin/shime $(DESTDIR)$(PREFIX)/bin/verbosewatch mkc: cc progs/scream.c -o progs/scream diff --git a/scripts/timer b/scripts/timer deleted file mode 100755 index 8731fbc..0000000 --- a/scripts/timer +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/sh - -case $0 in - *"timer"*) - [ $# -ne 2 ] && printf "specify minutes and \ -seconds\n" && exit 1 - sleep $(($1 * 60 + $2)) - printf "your timer is done\a\n" - exit 0 - ;; - *"alarm"*) - [ $# -ne 1 ] && printf "specify time\n" && exit 1 - ttw=$(($(date +%s --date="$1 tomorrow") - $(date +%s))) - sleep $ttw - printf "your alarm is done\a\n" - exit 0 - ;; - *"tomato"*) - [ $# -ne 2 ] && \ - printf "specify work and rest time\n" && exit 1 - counter=0 - while true; do - printf "start work cycle %s\a\n" $(($counter + 1)) - sleep $(($1 * 60)) - printf "start rest cycle %s\a\n" $(($counter + 1)) - sleep $(($2 * 60)) - counter=$(($counter + 1)) - done - exit 0 - ;; - *"stopwatch"*) - now=$(date +%s) - read var - printf "%s\n" $(($(date +%s) - $now)) - exit 0 - ;; - *"verbosewatch"*) - min=0 - sec=0 - while true; do - printf "%02d:%02d\r" $min $sec - sleep 1 - sec=$(($sec + 1)) - [ $sec -eq 60 ] && min=$(($min + 1)) && sec=0 - done - exit 0 - ;; - *) - printf "unknown invocation\n" - exit 2 - ;; -esac From 85f3d82f15bfd491e120c185180410ef44a0373f Mon Sep 17 00:00:00 2001 From: randomuser Date: Thu, 10 Jun 2021 23:18:17 -0500 Subject: [PATCH 051/197] add generalized timer functions to timerlib.h --- progs/timer.c | 49 +----------------------------------------------- progs/timerlib.h | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 48 deletions(-) create mode 100644 progs/timerlib.h diff --git a/progs/timer.c b/progs/timer.c index 9a6297b..b97f4de 100644 --- a/progs/timer.c +++ b/progs/timer.c @@ -4,12 +4,7 @@ #include #include -struct timer { - int m; - int s; - void (*u)(struct timer *t); - int (*c)(struct timer *t); -}; +#include "timerlib.h" struct settings { int e:1; /* use escape (v assumed) */ @@ -29,39 +24,6 @@ struct settings { .s = 0 }; -void timerdec(struct timer *t) { - if(t->s > 0) t->s--; - else if(t->s == 0) { - t->s = 59; - t->m--; - } -} - -void timerinc(struct timer *t) { - if(t->s < 59) t->s++; - else if(t->s == 59) { - t->s = 0; - t->m++; - } -} - -void timerupdate(struct timer *t) { - if(t->u != NULL) t->u(t); -} - -int timerstate(struct timer *t) { - if(t->c != NULL) { - if(t->c(t)) return 1; - else return 0; - } - return 0; -} - -int timerzero(struct timer *t) { - if(t->m == 0 && t->s == 0) return 1; - return 0; -} - int timerissettings(struct timer *t) { if(t->m == 0 && t->s == 0) return 0; if(t->m == settings.m && @@ -77,15 +39,6 @@ char *timerdisp(struct timer *t) { return str; } -struct timer *timerinit(void) { - struct timer *t = malloc(sizeof t); - t->m = 0; - t->s = 0; - t->u = NULL; - t->c = NULL; - return t; -} - void timerloop() { struct timer *t = timerinit(); if(settings.d) { diff --git a/progs/timerlib.h b/progs/timerlib.h new file mode 100644 index 0000000..df5aeb3 --- /dev/null +++ b/progs/timerlib.h @@ -0,0 +1,48 @@ +struct timer { + int m; + int s; + void (*u)(struct timer *t); + int (*c)(struct timer *t); +}; + +void timerdec(struct timer *t) { + if(t->s > 0) t->s--; + else if(t->s == 0) { + t->s = 59; + t->m--; + } +} + +void timerinc(struct timer *t) { + if(t->s < 59) t->s++; + else if(t->s == 59) { + t->s = 0; + t->m++; + } +} + +void timerupdate(struct timer *t) { + if(t->u != NULL) t->u(t); +} + +int timerstate(struct timer *t) { + if(t->c != NULL) { + if(t->c(t)) return 1; + else return 0; + } + return 0; +} + +int timerzero(struct timer *t) { + if(t->m == 0 && t->s == 0) return 1; + return 0; +} + +struct timer *timerinit(void) { + struct timer *t = malloc(sizeof t); + t->m = 0; + t->s = 0; + t->u = NULL; + t->c = NULL; + return t; +} From b700a35ded7bee6ee540bc82fd08c076dbb7ae73 Mon Sep 17 00:00:00 2001 From: randomuser Date: Thu, 10 Jun 2021 23:23:06 -0500 Subject: [PATCH 052/197] adopt shorter switch(...) { case ... } convention --- progs/timer.c | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/progs/timer.c b/progs/timer.c index b97f4de..bcef269 100644 --- a/progs/timer.c +++ b/progs/timer.c @@ -84,32 +84,15 @@ int main(int argc, char **argv) { char c; while((c = getopt (argc, argv, "evdbfm:s:")) != -1) { switch(c) { - case 'e': - settings.e = 1; - break; - case 'v': - settings.v = 1; - break; - case 'd': - settings.d = 1; - break; - case 'b': - settings.b = 1; - break; - case 'f': - settings.f = 1; - break; - case 'm': - settings.m = atoi(optarg); - break; - case 's': - settings.s = atoi(optarg); - break; - case '?': - return 1; - default: - abort(); - break; + break; case 'e': settings.e = 1; + break; case 'v': settings.v = 1; + break; case 'd': settings.d = 1; + break; case 'b': settings.b = 1; + break; case 'f': settings.f = 1; + break; case 'm': settings.m = atoi(optarg); + break; case 's': settings.s = atoi(optarg); + break; case '?': return 1; + break; default: abort(); } } timerloop(); From 3ad300298594cbe93cc3636b54f2ebbc4c943ee2 Mon Sep 17 00:00:00 2001 From: randomuser Date: Fri, 11 Jun 2021 00:06:29 -0500 Subject: [PATCH 053/197] move timerlib.h -> timerlib.c, also slight update --- progs/timer.c | 12 +++++------- progs/{timerlib.h => timerlib.c} | 28 ++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 15 deletions(-) rename progs/{timerlib.h => timerlib.c} (50%) diff --git a/progs/timer.c b/progs/timer.c index bcef269..f5ba88e 100644 --- a/progs/timer.c +++ b/progs/timer.c @@ -4,7 +4,7 @@ #include #include -#include "timerlib.h" +#include "timerlib.c" struct settings { int e:1; /* use escape (v assumed) */ @@ -51,12 +51,10 @@ void timerloop() { t->c = timerissettings; } char *c; - struct pollfd *p = malloc(sizeof p); - p->fd = STDIN_FILENO; - p->events = POLLIN; + struct pollfd p = { .fd = STDIN_FILENO, .events = POLLIN }; for(;;) { - poll(p, 1, 60); - if(p->revents == POLLIN) { + poll(&p, 1, 60); + if(p.revents == POLLIN) { /* TODO: make this nicer */ getchar(); if(settings.e) { @@ -73,7 +71,7 @@ void timerloop() { fflush(stdout); } else if(settings.v) printf("%s\n", c); - if(timerstate(t)) break; + if(timerstop(t)) break; timerupdate(t); sleep(1); } diff --git a/progs/timerlib.h b/progs/timerlib.c similarity index 50% rename from progs/timerlib.h rename to progs/timerlib.c index df5aeb3..f0ea3c3 100644 --- a/progs/timerlib.h +++ b/progs/timerlib.c @@ -1,8 +1,10 @@ struct timer { - int m; - int s; - void (*u)(struct timer *t); - int (*c)(struct timer *t); + int m; /* minutes */ + int s; /* seconds */ + int d; /* data storage */ + void (*u)(struct timer *t); /* update function */ + int (*c)(struct timer *t); /* stop check function */ + int (*p)(struct timer *t); /* pause check function */ }; void timerdec(struct timer *t) { @@ -25,24 +27,34 @@ void timerupdate(struct timer *t) { if(t->u != NULL) t->u(t); } -int timerstate(struct timer *t) { - if(t->c != NULL) { - if(t->c(t)) return 1; +int timerstate(int (*f)(struct timer *t), struct timer *t) { + if(f != NULL) { + if(f(t)) return 1; else return 0; } return 0; } +int timerstop(struct timer *t) { + return timerstate(t->c, t); +} + +int timerpause(struct timer *t) { + return timerstate(t->p, t); +} + int timerzero(struct timer *t) { if(t->m == 0 && t->s == 0) return 1; return 0; } struct timer *timerinit(void) { - struct timer *t = malloc(sizeof t); + struct timer *t = malloc(sizeof *t); t->m = 0; t->s = 0; + t->d = 0; t->u = NULL; t->c = NULL; + t->p = NULL; return t; } From dcc2e07295225a8b1269b459b5f57647d9f2fcf4 Mon Sep 17 00:00:00 2001 From: randomuser Date: Fri, 11 Jun 2021 00:26:49 -0500 Subject: [PATCH 054/197] change timer to deal only in seconds --- progs/timer.c | 15 ++++++++------- progs/timerlib.c | 16 +++------------- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/progs/timer.c b/progs/timer.c index f5ba88e..b1b6896 100644 --- a/progs/timer.c +++ b/progs/timer.c @@ -25,17 +25,16 @@ struct settings { }; int timerissettings(struct timer *t) { - if(t->m == 0 && t->s == 0) return 0; - if(t->m == settings.m && - t->s == settings.s) return 1; + if(t->s == 0) return 0; + if(settings.m * 60 + settings.s == t->s) return 1; return 0; } char *timerdisp(struct timer *t) { char *str = malloc(20); if(settings.f) snprintf(str, 20, "%02i:%02i:%02i", - (t->m / 60), (t->m % 60), t->s); - else snprintf(str, 20, "%02i:%02i", t->m, t->s); + ((t->s / 60) / 60), (t->s / 60) % 60, t->s % 60); + else snprintf(str, 20, "%02i:%02i", t->s / 60, t->s % 60); return str; } @@ -43,8 +42,7 @@ void timerloop() { struct timer *t = timerinit(); if(settings.d) { t->u = timerdec; - t->m = settings.m; - t->s = settings.s; + t->s = settings.s + (settings.m * 60); t->c = timerzero; } else { t->u = timerinc; @@ -72,10 +70,13 @@ void timerloop() { } else if(settings.v) printf("%s\n", c); if(timerstop(t)) break; + free(c); timerupdate(t); sleep(1); } if(settings.b) putchar('\a'); + free(t); + free(c); } int main(int argc, char **argv) { diff --git a/progs/timerlib.c b/progs/timerlib.c index f0ea3c3..6d02d66 100644 --- a/progs/timerlib.c +++ b/progs/timerlib.c @@ -1,5 +1,4 @@ struct timer { - int m; /* minutes */ int s; /* seconds */ int d; /* data storage */ void (*u)(struct timer *t); /* update function */ @@ -8,19 +7,11 @@ struct timer { }; void timerdec(struct timer *t) { - if(t->s > 0) t->s--; - else if(t->s == 0) { - t->s = 59; - t->m--; - } + if (t->s != 0) t->s--; } void timerinc(struct timer *t) { - if(t->s < 59) t->s++; - else if(t->s == 59) { - t->s = 0; - t->m++; - } + t->s++; } void timerupdate(struct timer *t) { @@ -44,13 +35,12 @@ int timerpause(struct timer *t) { } int timerzero(struct timer *t) { - if(t->m == 0 && t->s == 0) return 1; + if(t->s == 0) return 1; return 0; } struct timer *timerinit(void) { struct timer *t = malloc(sizeof *t); - t->m = 0; t->s = 0; t->d = 0; t->u = NULL; From 99988c922fe1c0a175ad43bb3e41e4931599ec79 Mon Sep 17 00:00:00 2001 From: randomuser Date: Fri, 11 Jun 2021 00:29:37 -0500 Subject: [PATCH 055/197] rename settings struct s --- progs/timer.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/progs/timer.c b/progs/timer.c index b1b6896..e79508e 100644 --- a/progs/timer.c +++ b/progs/timer.c @@ -14,7 +14,7 @@ struct settings { int f:1; /* display hours */ int m; /* minutes */ int s; /* seconds */ -} settings = { +} s = { .e = 0, .v = 0, .d = 0, @@ -26,13 +26,13 @@ struct settings { int timerissettings(struct timer *t) { if(t->s == 0) return 0; - if(settings.m * 60 + settings.s == t->s) return 1; + if(s.m * 60 + s.s == t->s) return 1; return 0; } char *timerdisp(struct timer *t) { char *str = malloc(20); - if(settings.f) snprintf(str, 20, "%02i:%02i:%02i", + if(s.f) snprintf(str, 20, "%02i:%02i:%02i", ((t->s / 60) / 60), (t->s / 60) % 60, t->s % 60); else snprintf(str, 20, "%02i:%02i", t->s / 60, t->s % 60); return str; @@ -40,9 +40,9 @@ char *timerdisp(struct timer *t) { void timerloop() { struct timer *t = timerinit(); - if(settings.d) { + if(s.d) { t->u = timerdec; - t->s = settings.s + (settings.m * 60); + t->s = s.s + (s.m * 60); t->c = timerzero; } else { t->u = timerinc; @@ -55,26 +55,26 @@ void timerloop() { if(p.revents == POLLIN) { /* TODO: make this nicer */ getchar(); - if(settings.e) { + if(s.e) { c = timerdisp(t); printf("\r\e[1A* %s", c); } getchar(); /* TODO: stop relying on hard assumptions */ - if(settings.e) printf("\r\e[1A \r", c); + if(s.e) printf("\r\e[1A \r", c); } c = timerdisp(t); - if(settings.e) { + if(s.e) { printf("%s\r", c); fflush(stdout); } - else if(settings.v) printf("%s\n", c); + else if(s.v) printf("%s\n", c); if(timerstop(t)) break; free(c); timerupdate(t); sleep(1); } - if(settings.b) putchar('\a'); + if(s.b) putchar('\a'); free(t); free(c); } @@ -83,13 +83,13 @@ int main(int argc, char **argv) { char c; while((c = getopt (argc, argv, "evdbfm:s:")) != -1) { switch(c) { - break; case 'e': settings.e = 1; - break; case 'v': settings.v = 1; - break; case 'd': settings.d = 1; - break; case 'b': settings.b = 1; - break; case 'f': settings.f = 1; - break; case 'm': settings.m = atoi(optarg); - break; case 's': settings.s = atoi(optarg); + break; case 'e': s.e = 1; + break; case 'v': s.v = 1; + break; case 'd': s.d = 1; + break; case 'b': s.b = 1; + break; case 'f': s.f = 1; + break; case 'm': s.m = atoi(optarg); + break; case 's': s.s = atoi(optarg); break; case '?': return 1; break; default: abort(); } From 850cdcc525c1edab18849ea9085aa00f500f1a78 Mon Sep 17 00:00:00 2001 From: randomuser Date: Fri, 11 Jun 2021 00:32:02 -0500 Subject: [PATCH 056/197] remove unnecessary argument to printf (line 64) --- progs/timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/progs/timer.c b/progs/timer.c index e79508e..be7bd23 100644 --- a/progs/timer.c +++ b/progs/timer.c @@ -61,7 +61,7 @@ void timerloop() { } getchar(); /* TODO: stop relying on hard assumptions */ - if(s.e) printf("\r\e[1A \r", c); + if(s.e) printf("\r\e[1A \r"); } c = timerdisp(t); if(s.e) { From b2ede86e69a566d860de6a8287834e8b93eb5d38 Mon Sep 17 00:00:00 2001 From: randomuser Date: Fri, 11 Jun 2021 00:49:03 -0500 Subject: [PATCH 057/197] settings struct now only uses seconds --- progs/timer.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/progs/timer.c b/progs/timer.c index be7bd23..78bf949 100644 --- a/progs/timer.c +++ b/progs/timer.c @@ -12,7 +12,6 @@ struct settings { int d:1; /* count down/up (1/0) */ int b:1; /* ascii bel when done */ int f:1; /* display hours */ - int m; /* minutes */ int s; /* seconds */ } s = { .e = 0, @@ -20,13 +19,12 @@ struct settings { .d = 0, .b = 0, .f = 0, - .m = 0, .s = 0 }; int timerissettings(struct timer *t) { if(t->s == 0) return 0; - if(s.m * 60 + s.s == t->s) return 1; + if(s.s == t->s) return 1; return 0; } @@ -42,7 +40,7 @@ void timerloop() { struct timer *t = timerinit(); if(s.d) { t->u = timerdec; - t->s = s.s + (s.m * 60); + t->s = s.s; t->c = timerzero; } else { t->u = timerinc; @@ -88,8 +86,8 @@ int main(int argc, char **argv) { break; case 'd': s.d = 1; break; case 'b': s.b = 1; break; case 'f': s.f = 1; - break; case 'm': s.m = atoi(optarg); - break; case 's': s.s = atoi(optarg); + break; case 'm': s.s = s.s + (atoi(optarg) * 60); + break; case 's': s.s = s.s + atoi(optarg); break; case '?': return 1; break; default: abort(); } From f8d95fd733ebeacab9b2f31d21ecd56db3153004 Mon Sep 17 00:00:00 2001 From: randomuser Date: Fri, 11 Jun 2021 00:58:16 -0500 Subject: [PATCH 058/197] dedicated functions for calculating hours, minutes, seconds --- progs/timer.c | 5 +++-- progs/timerlib.c | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/progs/timer.c b/progs/timer.c index 78bf949..3ad9967 100644 --- a/progs/timer.c +++ b/progs/timer.c @@ -31,8 +31,9 @@ int timerissettings(struct timer *t) { char *timerdisp(struct timer *t) { char *str = malloc(20); if(s.f) snprintf(str, 20, "%02i:%02i:%02i", - ((t->s / 60) / 60), (t->s / 60) % 60, t->s % 60); - else snprintf(str, 20, "%02i:%02i", t->s / 60, t->s % 60); + hours(t->s), minutes(t->s), seconds(t->s)); + /* TODO: give minute(...) and minutes(...) better names */ + else snprintf(str, 20, "%02i:%02i", minute(t->s), seconds(t->s)); return str; } diff --git a/progs/timerlib.c b/progs/timerlib.c index 6d02d66..3e8e39c 100644 --- a/progs/timerlib.c +++ b/progs/timerlib.c @@ -39,6 +39,22 @@ int timerzero(struct timer *t) { return 0; } +int seconds(int t) { + return t % 60; +} + +int minutes(int t) { + return (t / 60) % 60; +} + +int minute(int t) { + return t / 60; +} + +int hours(int t) { + return (t / 60) / 60; +} + struct timer *timerinit(void) { struct timer *t = malloc(sizeof *t); t->s = 0; From 113b75c415c86385ec7c81da233d14d4fd1c9d68 Mon Sep 17 00:00:00 2001 From: randomuser Date: Fri, 11 Jun 2021 00:59:07 -0500 Subject: [PATCH 059/197] remove space between getopt and args --- progs/timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/progs/timer.c b/progs/timer.c index 3ad9967..be76125 100644 --- a/progs/timer.c +++ b/progs/timer.c @@ -80,7 +80,7 @@ void timerloop() { int main(int argc, char **argv) { char c; - while((c = getopt (argc, argv, "evdbfm:s:")) != -1) { + while((c = getopt(argc, argv, "evdbfm:s:")) != -1) { switch(c) { break; case 'e': s.e = 1; break; case 'v': s.v = 1; From f8245cef5838ff6dc978143a89345048665b9738 Mon Sep 17 00:00:00 2001 From: randomuser Date: Fri, 11 Jun 2021 00:59:40 -0500 Subject: [PATCH 060/197] add hour argument --- progs/timer.c | 1 + 1 file changed, 1 insertion(+) diff --git a/progs/timer.c b/progs/timer.c index be76125..676a4a8 100644 --- a/progs/timer.c +++ b/progs/timer.c @@ -87,6 +87,7 @@ int main(int argc, char **argv) { break; case 'd': s.d = 1; break; case 'b': s.b = 1; break; case 'f': s.f = 1; + break; case 'h': s.s = s.s + (atoi(optarg) * 3600); break; case 'm': s.s = s.s + (atoi(optarg) * 60); break; case 's': s.s = s.s + atoi(optarg); break; case '?': return 1; From 2e11fc96013be32c8a2f3da07cc02a8dfb17e2f5 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 13 Jun 2021 00:44:13 -0500 Subject: [PATCH 061/197] update gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 573e5d5..c03b80f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *.tmp progs/scream progs/timer +progs/a.out From 0a3422c695112e27ee14af100e96a66e433f0adc Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 13 Jun 2021 00:44:35 -0500 Subject: [PATCH 062/197] add script josm_launch so I can use josm --- Makefile | 1 + scripts/josm_launch | 6 ++++++ 2 files changed, 7 insertions(+) create mode 100755 scripts/josm_launch diff --git a/Makefile b/Makefile index 80672b5..3eb425d 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,7 @@ sh: cp -f scripts/indicate $(DESTDIR)$(PREFIX)/bin cp -f scripts/vol $(DESTDIR)$(PREFIX)/bin cp -f scripts/shime $(DESTDIR)$(PREFIX)/bin + cp -f scripts/josm_launch $(DESTDIR)$(PREFIX)/bin ln -sf $(DESTDIR)$(PREFIX)/bin/shime $(DESTDIR)$(PREFIX)/bin/timer ln -sf $(DESTDIR)$(PREFIX)/bin/shime $(DESTDIR)$(PREFIX)/bin/alarm ln -sf $(DESTDIR)$(PREFIX)/bin/shime $(DESTDIR)$(PREFIX)/bin/tomato diff --git a/scripts/josm_launch b/scripts/josm_launch new file mode 100755 index 0000000..c333857 --- /dev/null +++ b/scripts/josm_launch @@ -0,0 +1,6 @@ +#!/bin/sh + +wmname LG3D +export _JAVA_AWT_WM_NONREPARENTING=1 + +josm From 78a407a07e04aec7bcf9d83fd43b26e285a7908a Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 13 Jun 2021 22:39:06 -0500 Subject: [PATCH 063/197] finally add hours argument --- progs/timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/progs/timer.c b/progs/timer.c index 676a4a8..71d59b7 100644 --- a/progs/timer.c +++ b/progs/timer.c @@ -80,7 +80,7 @@ void timerloop() { int main(int argc, char **argv) { char c; - while((c = getopt(argc, argv, "evdbfm:s:")) != -1) { + while((c = getopt(argc, argv, "evdbfh:m:s:")) != -1) { switch(c) { break; case 'e': s.e = 1; break; case 'v': s.v = 1; From e94b2ae59dac024d9ca224c4726afc46b1f550a0 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 13 Jun 2021 23:23:24 -0500 Subject: [PATCH 064/197] add tomato timer --- progs/timer.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/progs/timer.c b/progs/timer.c index 71d59b7..eab8457 100644 --- a/progs/timer.c +++ b/progs/timer.c @@ -12,6 +12,7 @@ struct settings { int d:1; /* count down/up (1/0) */ int b:1; /* ascii bel when done */ int f:1; /* display hours */ + int t:1; /* tomato timer */ int s; /* seconds */ } s = { .e = 0, @@ -19,6 +20,7 @@ struct settings { .d = 0, .b = 0, .f = 0, + .t = 0, .s = 0 }; @@ -28,6 +30,14 @@ int timerissettings(struct timer *t) { return 0; } +int tomatotimer(struct timer *t) { + if(t->s != 0) return 0; + if(t->d % 2) t->s = s.s / 2; + else t->s = s.s; + t->d++; + return 1; +} + char *timerdisp(struct timer *t) { char *str = malloc(20); if(s.f) snprintf(str, 20, "%02i:%02i:%02i", @@ -47,16 +57,27 @@ void timerloop() { t->u = timerinc; t->c = timerissettings; } + if(s.t) { + t->u = timerdec; + if(s.s == 0) s.s = 20 * 60; + t->s = s.s; + t->d = 1; + t->p = tomatotimer; + t->c = NULL; + } + char *c; + int e; struct pollfd p = { .fd = STDIN_FILENO, .events = POLLIN }; for(;;) { poll(&p, 1, 60); - if(p.revents == POLLIN) { + if((e = (p.revents == POLLIN)) || timerpause(t)) { /* TODO: make this nicer */ - getchar(); + if(e) getchar(); if(s.e) { c = timerdisp(t); - printf("\r\e[1A* %s", c); + if(e) printf("\r\e[1A* %s", c); + else printf("\r* %s", c); } getchar(); /* TODO: stop relying on hard assumptions */ @@ -80,13 +101,14 @@ void timerloop() { int main(int argc, char **argv) { char c; - while((c = getopt(argc, argv, "evdbfh:m:s:")) != -1) { + while((c = getopt(argc, argv, "evdbfth:m:s:")) != -1) { switch(c) { break; case 'e': s.e = 1; break; case 'v': s.v = 1; break; case 'd': s.d = 1; break; case 'b': s.b = 1; break; case 'f': s.f = 1; + break; case 't': s.t = 1; break; case 'h': s.s = s.s + (atoi(optarg) * 3600); break; case 'm': s.s = s.s + (atoi(optarg) * 60); break; case 's': s.s = s.s + atoi(optarg); From 7cd334163c9de64936ed680f02c428619f7070f0 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 13 Jun 2021 23:24:22 -0500 Subject: [PATCH 065/197] correct makefile --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index 3eb425d..bb406b9 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,6 @@ sh: cp -f scripts/paste $(DESTDIR)$(PREFIX)/bin cp -f scripts/bat $(DESTDIR)$(PREFIX)/bin cp -f scripts/disp $(DESTDIR)$(PREFIX)/bin - cp -f scripts/shime $(DESTDIR)$(PREFIX)/bin cp -f scripts/wal $(DESTDIR)$(PREFIX)/bin cp -f scripts/yt $(DESTDIR)$(PREFIX)/bin cp -f scripts/connect $(DESTDIR)$(PREFIX)/bin From d65a1246265ae11579fc03cff02e53ccff05ec1c Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 13 Jun 2021 23:25:19 -0500 Subject: [PATCH 066/197] remove shime as it is at feature parity with 'timer' --- Makefile | 6 ------ scripts/shime | 52 --------------------------------------------------- 2 files changed, 58 deletions(-) delete mode 100755 scripts/shime diff --git a/Makefile b/Makefile index bb406b9..f8b3cc1 100644 --- a/Makefile +++ b/Makefile @@ -17,13 +17,7 @@ sh: cp -f scripts/urlhandle $(DESTDIR)$(PREFIX)/bin cp -f scripts/indicate $(DESTDIR)$(PREFIX)/bin cp -f scripts/vol $(DESTDIR)$(PREFIX)/bin - cp -f scripts/shime $(DESTDIR)$(PREFIX)/bin cp -f scripts/josm_launch $(DESTDIR)$(PREFIX)/bin - ln -sf $(DESTDIR)$(PREFIX)/bin/shime $(DESTDIR)$(PREFIX)/bin/timer - ln -sf $(DESTDIR)$(PREFIX)/bin/shime $(DESTDIR)$(PREFIX)/bin/alarm - ln -sf $(DESTDIR)$(PREFIX)/bin/shime $(DESTDIR)$(PREFIX)/bin/tomato - ln -sf $(DESTDIR)$(PREFIX)/bin/shime $(DESTDIR)$(PREFIX)/bin/stopwatch - ln -sf $(DESTDIR)$(PREFIX)/bin/shime $(DESTDIR)$(PREFIX)/bin/verbosewatch mkc: cc progs/scream.c -o progs/scream diff --git a/scripts/shime b/scripts/shime deleted file mode 100755 index effebfb..0000000 --- a/scripts/shime +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/sh - -case $0 in - *"timer"*) - [ $# -ne 2 ] && printf "specify minutes and \ -seconds\n" && exit 1 - sleep $(($1 * 60 + $2)) - printf "your timer is done\a\n" - exit 0 - ;; - *"alarm"*) - [ $# -ne 1 ] && printf "specify time\n" && exit 1 - ttw=$(($(date +%s --date="$1 tomorrow") - $(date +%s))) - sleep $ttw - printf "your alarm is done\a\n" - exit 0 - ;; - *"tomato"*) - [ $# -ne 2 ] && \ - printf "specify work and rest time\n" && exit 1 - counter=0 - while true; do - printf "start work cycle %s\a\n" $(($counter + 1)) - sleep $(($1 * 60)) - printf "start rest cycle %s\a\n" $(($counter + 1)) - sleep $(($2 * 60)) - counter=$(($counter + 1)) - done - exit 0 - ;; - *"stopwatch"*) - now=$(date +%s) - read var - printf "%s\n" $(($(date +%s) - $now)) - exit 0 - ;; - *"verbosewatch"*) - min=0 - sec=0 - while true; do - printf "%02d:%02d\r" $min $sec - sleep 1 - sec=$(($sec + 1)) - [ $sec -eq 60 ] && min=$(($min + 1)) && sec=0 - done - exit 0 - ;; - *) - printf "unknown invocation\n" - exit 2 - ;; -esac From d986e7ec25d7b7b651590ca2e3423c677fe89ae4 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 13 Jun 2021 23:27:38 -0500 Subject: [PATCH 067/197] simplify functions that ought to be one-liners --- progs/timerlib.c | 42 +++++++++--------------------------------- 1 file changed, 9 insertions(+), 33 deletions(-) diff --git a/progs/timerlib.c b/progs/timerlib.c index 3e8e39c..92c48d2 100644 --- a/progs/timerlib.c +++ b/progs/timerlib.c @@ -6,17 +6,9 @@ struct timer { int (*p)(struct timer *t); /* pause check function */ }; -void timerdec(struct timer *t) { - if (t->s != 0) t->s--; -} - -void timerinc(struct timer *t) { - t->s++; -} - -void timerupdate(struct timer *t) { - if(t->u != NULL) t->u(t); -} +void timerdec(struct timer *t) { if (t->s != 0) t->s--; } +void timerinc(struct timer *t) { t->s++; } +void timerupdate(struct timer *t) { if(t->u != NULL) t->u(t); } int timerstate(int (*f)(struct timer *t), struct timer *t) { if(f != NULL) { @@ -26,34 +18,18 @@ int timerstate(int (*f)(struct timer *t), struct timer *t) { return 0; } -int timerstop(struct timer *t) { - return timerstate(t->c, t); -} - -int timerpause(struct timer *t) { - return timerstate(t->p, t); -} +int timerstop(struct timer *t) { return timerstate(t->c, t); } +int timerpause(struct timer *t) { return timerstate(t->p, t); } int timerzero(struct timer *t) { if(t->s == 0) return 1; return 0; } -int seconds(int t) { - return t % 60; -} - -int minutes(int t) { - return (t / 60) % 60; -} - -int minute(int t) { - return t / 60; -} - -int hours(int t) { - return (t / 60) / 60; -} +int seconds(int t) { return t % 60; } +int minutes(int t) { return (t / 60) % 60; } +int minute(int t) { return t / 60; } +int hours(int t) { return (t / 60) / 60; } struct timer *timerinit(void) { struct timer *t = malloc(sizeof *t); From 0f463c757fe5068e4ec457d36362d0f95b7ab515 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 13 Jun 2021 23:33:08 -0500 Subject: [PATCH 068/197] make proper directories --- {progs => c}/scream.c | 0 {progs => c}/timer.c | 0 {progs => c}/timerlib.c | 0 {scripts => sh}/bat | 0 {scripts => sh}/connect | 0 {scripts => sh}/disp | 0 {scripts => sh}/indicate | 0 {scripts => sh}/josm_launch | 0 {scripts => sh}/nws | 0 {scripts => sh}/paste | 0 {scripts => sh}/urlhandle | 0 {scripts => sh}/vol | 0 {scripts => sh}/wal | 0 {scripts => sh}/xkcd | 0 {scripts => sh}/yt | 0 15 files changed, 0 insertions(+), 0 deletions(-) rename {progs => c}/scream.c (100%) rename {progs => c}/timer.c (100%) rename {progs => c}/timerlib.c (100%) rename {scripts => sh}/bat (100%) rename {scripts => sh}/connect (100%) rename {scripts => sh}/disp (100%) rename {scripts => sh}/indicate (100%) rename {scripts => sh}/josm_launch (100%) rename {scripts => sh}/nws (100%) rename {scripts => sh}/paste (100%) rename {scripts => sh}/urlhandle (100%) rename {scripts => sh}/vol (100%) rename {scripts => sh}/wal (100%) rename {scripts => sh}/xkcd (100%) rename {scripts => sh}/yt (100%) diff --git a/progs/scream.c b/c/scream.c similarity index 100% rename from progs/scream.c rename to c/scream.c diff --git a/progs/timer.c b/c/timer.c similarity index 100% rename from progs/timer.c rename to c/timer.c diff --git a/progs/timerlib.c b/c/timerlib.c similarity index 100% rename from progs/timerlib.c rename to c/timerlib.c diff --git a/scripts/bat b/sh/bat similarity index 100% rename from scripts/bat rename to sh/bat diff --git a/scripts/connect b/sh/connect similarity index 100% rename from scripts/connect rename to sh/connect diff --git a/scripts/disp b/sh/disp similarity index 100% rename from scripts/disp rename to sh/disp diff --git a/scripts/indicate b/sh/indicate similarity index 100% rename from scripts/indicate rename to sh/indicate diff --git a/scripts/josm_launch b/sh/josm_launch similarity index 100% rename from scripts/josm_launch rename to sh/josm_launch diff --git a/scripts/nws b/sh/nws similarity index 100% rename from scripts/nws rename to sh/nws diff --git a/scripts/paste b/sh/paste similarity index 100% rename from scripts/paste rename to sh/paste diff --git a/scripts/urlhandle b/sh/urlhandle similarity index 100% rename from scripts/urlhandle rename to sh/urlhandle diff --git a/scripts/vol b/sh/vol similarity index 100% rename from scripts/vol rename to sh/vol diff --git a/scripts/wal b/sh/wal similarity index 100% rename from scripts/wal rename to sh/wal diff --git a/scripts/xkcd b/sh/xkcd similarity index 100% rename from scripts/xkcd rename to sh/xkcd diff --git a/scripts/yt b/sh/yt similarity index 100% rename from scripts/yt rename to sh/yt From 2ed83fc6ff13bc890e78f72238b336f93333bd29 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 13 Jun 2021 23:34:05 -0500 Subject: [PATCH 069/197] renaming part two --- .gitignore | 6 +++--- Makefile | 32 ++++++++++++++++---------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index c03b80f..d29796a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ *.swp *.tmp -progs/scream -progs/timer -progs/a.out +c/scream +c/timer +c/a.out diff --git a/Makefile b/Makefile index f8b3cc1..a513e45 100644 --- a/Makefile +++ b/Makefile @@ -7,23 +7,23 @@ man: cp -f man/* $(DESTDIR)$(PREFIX)/man1 sh: mkdir -p $(DESTDIR)$(PREFIX)/bin - cp -f scripts/paste $(DESTDIR)$(PREFIX)/bin - cp -f scripts/bat $(DESTDIR)$(PREFIX)/bin - cp -f scripts/disp $(DESTDIR)$(PREFIX)/bin - cp -f scripts/wal $(DESTDIR)$(PREFIX)/bin - cp -f scripts/yt $(DESTDIR)$(PREFIX)/bin - cp -f scripts/connect $(DESTDIR)$(PREFIX)/bin - cp -f scripts/nws $(DESTDIR)$(PREFIX)/bin - cp -f scripts/urlhandle $(DESTDIR)$(PREFIX)/bin - cp -f scripts/indicate $(DESTDIR)$(PREFIX)/bin - cp -f scripts/vol $(DESTDIR)$(PREFIX)/bin - cp -f scripts/josm_launch $(DESTDIR)$(PREFIX)/bin + cp -f sh/paste $(DESTDIR)$(PREFIX)/bin + cp -f sh/bat $(DESTDIR)$(PREFIX)/bin + cp -f sh/disp $(DESTDIR)$(PREFIX)/bin + cp -f sh/wal $(DESTDIR)$(PREFIX)/bin + cp -f sh/yt $(DESTDIR)$(PREFIX)/bin + cp -f sh/connect $(DESTDIR)$(PREFIX)/bin + cp -f sh/nws $(DESTDIR)$(PREFIX)/bin + cp -f sh/urlhandle $(DESTDIR)$(PREFIX)/bin + cp -f sh/indicate $(DESTDIR)$(PREFIX)/bin + cp -f sh/vol $(DESTDIR)$(PREFIX)/bin + cp -f sh/josm_launch $(DESTDIR)$(PREFIX)/bin mkc: - cc progs/scream.c -o progs/scream - cc progs/timer.c -o progs/timer + cc c/scream.c -o progs/scream + cc c/timer.c -o progs/timer c: - cp -f progs/scream $(DESTDIR)$(PREFIX)/bin - cp -f progs/timer $(DESTDIR)$(PREFIX)/bin + cp -f c/scream $(DESTDIR)$(PREFIX)/bin + cp -f c/timer $(DESTDIR)$(PREFIX)/bin clean: - rm progs/scream + rm c/scream From a7449c3f5ef66c8149c71fe3d16e5e5997ef354b Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 13 Jun 2021 23:34:53 -0500 Subject: [PATCH 070/197] merge timerlib.c and timer.c into one file --- c/timer.c | 43 ++++++++++++++++++++++++++++++++++++++++++- c/timerlib.c | 42 ------------------------------------------ 2 files changed, 42 insertions(+), 43 deletions(-) delete mode 100644 c/timerlib.c diff --git a/c/timer.c b/c/timer.c index eab8457..b2c45e5 100644 --- a/c/timer.c +++ b/c/timer.c @@ -4,7 +4,48 @@ #include #include -#include "timerlib.c" +struct timer { + int s; /* seconds */ + int d; /* data storage */ + void (*u)(struct timer *t); /* update function */ + int (*c)(struct timer *t); /* stop check function */ + int (*p)(struct timer *t); /* pause check function */ +}; + +void timerdec(struct timer *t) { if (t->s != 0) t->s--; } +void timerinc(struct timer *t) { t->s++; } +void timerupdate(struct timer *t) { if(t->u != NULL) t->u(t); } + +int timerstate(int (*f)(struct timer *t), struct timer *t) { + if(f != NULL) { + if(f(t)) return 1; + else return 0; + } + return 0; +} + +int timerstop(struct timer *t) { return timerstate(t->c, t); } +int timerpause(struct timer *t) { return timerstate(t->p, t); } + +int timerzero(struct timer *t) { + if(t->s == 0) return 1; + return 0; +} + +int seconds(int t) { return t % 60; } +int minutes(int t) { return (t / 60) % 60; } +int minute(int t) { return t / 60; } +int hours(int t) { return (t / 60) / 60; } + +struct timer *timerinit(void) { + struct timer *t = malloc(sizeof *t); + t->s = 0; + t->d = 0; + t->u = NULL; + t->c = NULL; + t->p = NULL; + return t; +} struct settings { int e:1; /* use escape (v assumed) */ diff --git a/c/timerlib.c b/c/timerlib.c deleted file mode 100644 index 92c48d2..0000000 --- a/c/timerlib.c +++ /dev/null @@ -1,42 +0,0 @@ -struct timer { - int s; /* seconds */ - int d; /* data storage */ - void (*u)(struct timer *t); /* update function */ - int (*c)(struct timer *t); /* stop check function */ - int (*p)(struct timer *t); /* pause check function */ -}; - -void timerdec(struct timer *t) { if (t->s != 0) t->s--; } -void timerinc(struct timer *t) { t->s++; } -void timerupdate(struct timer *t) { if(t->u != NULL) t->u(t); } - -int timerstate(int (*f)(struct timer *t), struct timer *t) { - if(f != NULL) { - if(f(t)) return 1; - else return 0; - } - return 0; -} - -int timerstop(struct timer *t) { return timerstate(t->c, t); } -int timerpause(struct timer *t) { return timerstate(t->p, t); } - -int timerzero(struct timer *t) { - if(t->s == 0) return 1; - return 0; -} - -int seconds(int t) { return t % 60; } -int minutes(int t) { return (t / 60) % 60; } -int minute(int t) { return t / 60; } -int hours(int t) { return (t / 60) / 60; } - -struct timer *timerinit(void) { - struct timer *t = malloc(sizeof *t); - t->s = 0; - t->d = 0; - t->u = NULL; - t->c = NULL; - t->p = NULL; - return t; -} From a65b1517e63557247e11a8bc2ba8f563aab304c8 Mon Sep 17 00:00:00 2001 From: randomuser Date: Mon, 14 Jun 2021 00:11:42 -0500 Subject: [PATCH 071/197] it's finally fixed --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index a513e45..cdb97b3 100644 --- a/Makefile +++ b/Makefile @@ -20,8 +20,8 @@ sh: cp -f sh/josm_launch $(DESTDIR)$(PREFIX)/bin mkc: - cc c/scream.c -o progs/scream - cc c/timer.c -o progs/timer + cc c/scream.c -o c/scream + cc c/timer.c -o c/timer c: cp -f c/scream $(DESTDIR)$(PREFIX)/bin cp -f c/timer $(DESTDIR)$(PREFIX)/bin From 0b0f63595741d205c803813577fddc3fc95ed6df Mon Sep 17 00:00:00 2001 From: randomuser Date: Mon, 14 Jun 2021 00:12:51 -0500 Subject: [PATCH 072/197] add timer manual page --- man/timer.1 | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 man/timer.1 diff --git a/man/timer.1 b/man/timer.1 new file mode 100644 index 0000000..abd6815 --- /dev/null +++ b/man/timer.1 @@ -0,0 +1,81 @@ +.TH TIMER 1 timer +.SH NAME +timer \- simple command line timer program +.SH SYNOPSIS +.B timer [-evdbft] [-h int] [-m int] [-s int] +.SH OPTIONS +.TP +.B -e +enable usage of vt100 escape sequences for timer rendering (overrides -v) +.TP +.B -v +enable printing of timer status +.TP +.B -d +count down; when timer reaches 00:00, finish (use -h, -m, -s to set ending time) +.TP +.B -b +ASCII BEL when timer finish state reached +.TP +.B -f +timer display contains hour slot +.TP +.B -t +use a tomato timer (use -h, -m, -s to set work cycle time, rest cycle time is assumed to be half of the working time) +.TP +.B "-h int" +specify number of hours for timer parameters +.TP +.B "-m int" +specify number of minutes for timer parameters +.TP +.B "-s int" +specify number of seconds for timer parameters +.SH INTERACTIVE USAGE +.TP +.B pausing +a timer is paused when an astrisk prefixes the display (with -e) and/or when the timer ceases to update, e.g. count up or down. you can use the enter key to pause/unpause it (refer to the below example) +.nf +$ timer -e +* 05:45 +.fi +.TP +.B stopping a timer +should you wish to stop a timer prematurely, or a timer which has no specified end condition, you may press the key combination that sends a killing signal to the program (e.g. a la SIGTERM) in your shell, which is usually ^C. the timer has no major places to clean up. however, memory leaks might occur on some operating systems due to no free()ing of resources. +.SH EXIT CODES/TERMINATION SIGNALS +.TP +.B 0 +timer finished successfully +.TP +.B 1 / SIGABRT +error parsing arguments +.SH EXAMPLES +.B start a ten minute timer, counting up: +.nf +$ timer -m 10 +.fi +.B show the vt100 interface, too: +.nf +$ timer -em 10 +.fi +.B start a one hour sixty-two minute fourty-nine second timer counting down (with vt100 interface): +.nf +$ timer -edh 1 -m 62 -s 49 +.fi +.B start a tomato timer with a work interval of fourty minutes and a rest interval of twenty minutes: +.nf +$ timer -etm 40 +.fi +.SH REQUIRED HEADERS +.nf +#include +#include +#include +#include +#include +.fi +.SH BUGS +send email to random user at-sign tilde dot club +.SH AUTHOR +randomuser + From 0dc73354c9220d16e3dd3dc9be35dd65db1b2f06 Mon Sep 17 00:00:00 2001 From: randomuser Date: Mon, 14 Jun 2021 12:51:16 -0500 Subject: [PATCH 073/197] move 'settings' struct --- c/timer.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/c/timer.c b/c/timer.c index b2c45e5..87178d2 100644 --- a/c/timer.c +++ b/c/timer.c @@ -12,6 +12,24 @@ struct timer { int (*p)(struct timer *t); /* pause check function */ }; +struct settings { + int e:1; /* use escape (v assumed) */ + int v:1; /* verbose */ + int d:1; /* count down/up (1/0) */ + int b:1; /* ascii bel when done */ + int f:1; /* display hours */ + int t:1; /* tomato timer */ + int s; /* seconds */ +} s = { + .e = 0, + .v = 0, + .d = 0, + .b = 0, + .f = 0, + .t = 0, + .s = 0 +}; + void timerdec(struct timer *t) { if (t->s != 0) t->s--; } void timerinc(struct timer *t) { t->s++; } void timerupdate(struct timer *t) { if(t->u != NULL) t->u(t); } @@ -47,24 +65,6 @@ struct timer *timerinit(void) { return t; } -struct settings { - int e:1; /* use escape (v assumed) */ - int v:1; /* verbose */ - int d:1; /* count down/up (1/0) */ - int b:1; /* ascii bel when done */ - int f:1; /* display hours */ - int t:1; /* tomato timer */ - int s; /* seconds */ -} s = { - .e = 0, - .v = 0, - .d = 0, - .b = 0, - .f = 0, - .t = 0, - .s = 0 -}; - int timerissettings(struct timer *t) { if(t->s == 0) return 0; if(s.s == t->s) return 1; From 2b8da849ab2fb133379e1e78c01d1aa8f4bf0ffc Mon Sep 17 00:00:00 2001 From: randomuser Date: Mon, 14 Jun 2021 13:02:19 -0500 Subject: [PATCH 074/197] add a feature --- c/timer.c | 7 ++++++- man/timer.1 | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/c/timer.c b/c/timer.c index 87178d2..b6ff204 100644 --- a/c/timer.c +++ b/c/timer.c @@ -19,6 +19,7 @@ struct settings { int b:1; /* ascii bel when done */ int f:1; /* display hours */ int t:1; /* tomato timer */ + int p:1; /* stop after tomato timer cycle finished */ int s; /* seconds */ } s = { .e = 0, @@ -27,6 +28,7 @@ struct settings { .b = 0, .f = 0, .t = 0, + .p = 0, .s = 0 }; @@ -76,6 +78,8 @@ int tomatotimer(struct timer *t) { if(t->d % 2) t->s = s.s / 2; else t->s = s.s; t->d++; + if(s.b) putchar('\a'); + if(s.p) return 0; return 1; } @@ -142,7 +146,7 @@ void timerloop() { int main(int argc, char **argv) { char c; - while((c = getopt(argc, argv, "evdbfth:m:s:")) != -1) { + while((c = getopt(argc, argv, "evdbftph:m:s:")) != -1) { switch(c) { break; case 'e': s.e = 1; break; case 'v': s.v = 1; @@ -150,6 +154,7 @@ int main(int argc, char **argv) { break; case 'b': s.b = 1; break; case 'f': s.f = 1; break; case 't': s.t = 1; + break; case 'p': s.p = 1; break; case 'h': s.s = s.s + (atoi(optarg) * 3600); break; case 'm': s.s = s.s + (atoi(optarg) * 60); break; case 's': s.s = s.s + atoi(optarg); diff --git a/man/timer.1 b/man/timer.1 index abd6815..f24e6be 100644 --- a/man/timer.1 +++ b/man/timer.1 @@ -23,6 +23,9 @@ timer display contains hour slot .B -t use a tomato timer (use -h, -m, -s to set work cycle time, rest cycle time is assumed to be half of the working time) .TP +.B -p +disable pausing after finishing tomato timer cycle (required -t to work) +.TP .B "-h int" specify number of hours for timer parameters .TP @@ -75,7 +78,7 @@ $ timer -etm 40 #include .fi .SH BUGS +- when passing -p each tomato timer cycle is cut short one second send email to random user at-sign tilde dot club .SH AUTHOR randomuser - From fc8a2e665e9a78bfaeddede57451268e11b99ebb Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 20 Jun 2021 10:33:49 -0500 Subject: [PATCH 075/197] destroy ~/.fehbg --- sh/wal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sh/wal b/sh/wal index 2dbf520..83fe25d 100755 --- a/sh/wal +++ b/sh/wal @@ -2,7 +2,7 @@ WALLDIR="${HOME}/.local/share/wallpapers" TEEFILE="${WALLDIR}/.hist" -BASECMD="feh --bg-fill" +BASECMD="feh --no-fehbg --bg-fill" generate_wall () { GENWALL=$( \ From 1ce81cb3e7d38bb135555aa1ddaaa5baedf90e75 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 20 Jun 2021 10:46:29 -0500 Subject: [PATCH 076/197] update makefile to actually install manual pages --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index cdb97b3..ee194f9 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,8 @@ install: man sh mkc c .PHONY: man sh mkc c man: - mkdir -p $(DESTDIR)$(PREFIX)/man1 - cp -f man/* $(DESTDIR)$(PREFIX)/man1 + mkdir -p /usr/local/man/man1 + cp -f man/* /usr/local/man/man1 sh: mkdir -p $(DESTDIR)$(PREFIX)/bin cp -f sh/paste $(DESTDIR)$(PREFIX)/bin From 34d673bf72462643e09f8286533d4d2b2ba3302c Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 20 Jun 2021 10:46:53 -0500 Subject: [PATCH 077/197] add "default settings" feature --- c/timer.c | 9 ++++++++- man/timer.1 | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/c/timer.c b/c/timer.c index b6ff204..2ab5ebc 100644 --- a/c/timer.c +++ b/c/timer.c @@ -92,6 +92,12 @@ char *timerdisp(struct timer *t) { return str; } +void defaultSettings(struct settings s) { + s.e = 1; + s.b = 1; + s.f = 1; +} + void timerloop() { struct timer *t = timerinit(); if(s.d) { @@ -146,7 +152,7 @@ void timerloop() { int main(int argc, char **argv) { char c; - while((c = getopt(argc, argv, "evdbftph:m:s:")) != -1) { + while((c = getopt(argc, argv, "evdbftpzh:m:s:")) != -1) { switch(c) { break; case 'e': s.e = 1; break; case 'v': s.v = 1; @@ -155,6 +161,7 @@ int main(int argc, char **argv) { break; case 'f': s.f = 1; break; case 't': s.t = 1; break; case 'p': s.p = 1; + break; case 'z': s.e = 1; s.b = 1; s.f = 1; break; case 'h': s.s = s.s + (atoi(optarg) * 3600); break; case 'm': s.s = s.s + (atoi(optarg) * 60); break; case 's': s.s = s.s + atoi(optarg); diff --git a/man/timer.1 b/man/timer.1 index f24e6be..e06fcf4 100644 --- a/man/timer.1 +++ b/man/timer.1 @@ -26,6 +26,9 @@ use a tomato timer (use -h, -m, -s to set work cycle time, rest cycle time is as .B -p disable pausing after finishing tomato timer cycle (required -t to work) .TP +.B -z +enable build-specific runtime settings (default -ebf) +.TP .B "-h int" specify number of hours for timer parameters .TP From 719bc1ada1d0d3707a0ce601d0562995dbaa611d Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 20 Jun 2021 17:15:09 -0500 Subject: [PATCH 078/197] add ssid list to connect --- sh/connect | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sh/connect b/sh/connect index 24a719b..c529955 100755 --- a/sh/connect +++ b/sh/connect @@ -17,6 +17,13 @@ case $1 in [ $(ps aux | grep wpa_supplicant | wc -l) -eq 2 ] && sh $0 d && exit sh $0 c ;; + "l"*) + iw dev wlp3s0 scan | \ + grep 'SSID\|signal' | \ + grep -v '* SSID List' | \ + awk -F': ' '{print $2}' | \ + sed 'N;s/\n/ /' | \ + grep -v '\x00' *) printf "\ simple wrapper for connecting to a network @@ -24,6 +31,7 @@ ${0} toggle to toggle wifi connection ${0} restart to restart wifi ${0} disconnect to disconnect ${0} connect to connect to network +${0} list to list networks " ;; esac From f59c0a356e91c84486869580ff051cbc1bea95de Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 20 Jun 2021 17:21:49 -0500 Subject: [PATCH 079/197] i can code, trust me --- sh/connect | 1 + 1 file changed, 1 insertion(+) diff --git a/sh/connect b/sh/connect index c529955..cc8084a 100755 --- a/sh/connect +++ b/sh/connect @@ -24,6 +24,7 @@ case $1 in awk -F': ' '{print $2}' | \ sed 'N;s/\n/ /' | \ grep -v '\x00' + ;; *) printf "\ simple wrapper for connecting to a network From 16a8e285156c77c1adc0c64d8ed3b1801459bce6 Mon Sep 17 00:00:00 2001 From: randomuser Date: Wed, 23 Jun 2021 22:58:24 -0500 Subject: [PATCH 080/197] add ftp handler --- sh/ftphandle | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100755 sh/ftphandle diff --git a/sh/ftphandle b/sh/ftphandle new file mode 100755 index 0000000..8a53335 --- /dev/null +++ b/sh/ftphandle @@ -0,0 +1,6 @@ +#!/bin/sh + +# This one is relatively simple. Relay the first argument to +# ncftp and then you're done. + +ncftp $1 From 6399938d71b3c290e13b65979c6ecf2cd35f5b57 Mon Sep 17 00:00:00 2001 From: randomuser Date: Wed, 23 Jun 2021 23:00:55 -0500 Subject: [PATCH 081/197] not quite done yet --- sh/ftphandle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sh/ftphandle b/sh/ftphandle index 8a53335..b541c40 100755 --- a/sh/ftphandle +++ b/sh/ftphandle @@ -3,4 +3,4 @@ # This one is relatively simple. Relay the first argument to # ncftp and then you're done. -ncftp $1 +st -e ncftp $1 From e6262a7305b84769a95eecaf3374276b31dbc79f Mon Sep 17 00:00:00 2001 From: randomuser Date: Wed, 23 Jun 2021 23:02:21 -0500 Subject: [PATCH 082/197] now it's done (hopefully) --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index ee194f9..b53e103 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ sh: cp -f sh/connect $(DESTDIR)$(PREFIX)/bin cp -f sh/nws $(DESTDIR)$(PREFIX)/bin cp -f sh/urlhandle $(DESTDIR)$(PREFIX)/bin + cp -f sh/ftphandle $(DESTDIR)$(PREFIX)/bin cp -f sh/indicate $(DESTDIR)$(PREFIX)/bin cp -f sh/vol $(DESTDIR)$(PREFIX)/bin cp -f sh/josm_launch $(DESTDIR)$(PREFIX)/bin From 8d18178c34ec1acba2b819c625c82a36b094460a Mon Sep 17 00:00:00 2001 From: randomuser Date: Thu, 1 Jul 2021 22:28:40 -0500 Subject: [PATCH 083/197] add a little tiny bit of documentation --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index b53e103..855da61 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,8 @@ install: man sh mkc c .PHONY: man sh mkc c man: + # this used to be {command} $(DESTDIR)$(PREFIX)/man/man1 + # this did not work on my computer, but might be needed in other computers mkdir -p /usr/local/man/man1 cp -f man/* /usr/local/man/man1 sh: From c91325de0345598cae874804a71238a1031096d0 Mon Sep 17 00:00:00 2001 From: randomuser Date: Thu, 1 Jul 2021 22:36:24 -0500 Subject: [PATCH 084/197] add an extra flag to the xkcd program --- sh/xkcd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sh/xkcd b/sh/xkcd index c48302c..dc8179c 100755 --- a/sh/xkcd +++ b/sh/xkcd @@ -1,6 +1,6 @@ #!/bin/sh -set -x +[ -z $XKCD_DBG ] || set -x err () { printf "err: %s\n" ${1} [ -z "${2}" ] && exit 1 From a4beb9173db8d170498c67182d30c107e5f9c138 Mon Sep 17 00:00:00 2001 From: randomuser Date: Wed, 7 Jul 2021 16:05:52 -0500 Subject: [PATCH 085/197] add unsigned prefix --- c/timer.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/c/timer.c b/c/timer.c index 2ab5ebc..3f19fd0 100644 --- a/c/timer.c +++ b/c/timer.c @@ -13,13 +13,13 @@ struct timer { }; struct settings { - int e:1; /* use escape (v assumed) */ - int v:1; /* verbose */ - int d:1; /* count down/up (1/0) */ - int b:1; /* ascii bel when done */ - int f:1; /* display hours */ - int t:1; /* tomato timer */ - int p:1; /* stop after tomato timer cycle finished */ + unsigned int e:1; /* use escape (v assumed) */ + unsigned int v:1; /* verbose */ + unsigned int d:1; /* count down/up (1/0) */ + unsigned int b:1; /* ascii bel when done */ + unsigned int f:1; /* display hours */ + unsigned int t:1; /* tomato timer */ + unsigned int p:1; /* stop after tomato timer cycle finished */ int s; /* seconds */ } s = { .e = 0, From dc65460b08b52f53a7b5841aa2d14dc5794722a3 Mon Sep 17 00:00:00 2001 From: randomuser Date: Fri, 16 Jul 2021 15:42:14 -0500 Subject: [PATCH 086/197] add new monitor configuration to disp --- sh/disp | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/sh/disp b/sh/disp index f0bcb4b..2da6d1c 100755 --- a/sh/disp +++ b/sh/disp @@ -4,24 +4,33 @@ exists() { xrandr | grep ' connected' | grep "${1}" | wc -l } -if [ $(exists "HDMI2") -eq 1 ] && [ $(exists "LVDS1") -eq 1 ]; then - printf "HDMI2, LVDS1 exists\n" - xrandr --output HDMI2 --above LVDS1 --auto - bspc monitor LVDS1 -a I II III IV V - bspc monitor HDMI2 -a VI VII VIII IX +if [ $(exists "HDMI-2") -eq 1 ] && [ $(exists "VGA-1") -eq 1 ]; then + printf "HDMI-2, VGA-1 exists\n" + xrandr --output HDMI-2 --right-of VGA-1 --auto + xrandr --output LVDS-1 --off --auto + bspc monitor HDMI-2 -a I II III IV V + bspc monitor VGA-1 -a VI VII VIII IX exit 0 fi -if [ $(exists "HDMI1") -eq 1 ] && [ $(exists "LVDS1") -eq 1 ]; then - printf "HDMI1, LVDS1 exists\n" - xrandr --output HDMI1 --above LVDS1 --auto - bspc monitor LVDS1 -a I II III IV V - bspc monitor HDMI1 -a VI VII VIII IX +if [ $(exists "HDMI-2") -eq 1 ] && [ $(exists "LVDS-1") -eq 1 ]; then + printf "HDMI-2, LVDS-1 exists\n" + xrandr --output HDMI-2 --above LVDS-1 --auto + bspc monitor LVDS-1 -a I II III IV V + bspc monitor HDMI-2 -a VI VII VIII IX + exit 0 +fi + +if [ $(exists "HDMI-1") -eq 1 ] && [ $(exists "LVDS-1") -eq 1 ]; then + printf "HDMI-1, LVDS-1 exists\n" + xrandr --output HDMI-1 --above LVDS-1 --auto + bspc monitor LVDS-1 -a I II III IV V + bspc monitor HDMI-1 -a VI VII VIII IX exit 0 fi printf "defaulting to default configuration\n" -xrandr --output HDMI1 --off -xrandr --output HDMI2 --off +xrandr --output HDMI-1 --off +xrandr --output HDMI-2 --off bspc monitor -d I II III IV V VI VII VIII IX X exit 0 From 5763f619a61aa6eb64841b17b6f3c7e1cd8e1f62 Mon Sep 17 00:00:00 2001 From: randomuser Date: Fri, 16 Jul 2021 15:45:53 -0500 Subject: [PATCH 087/197] add pashmenu --- Makefile | 1 + sh/pashmenu | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100755 sh/pashmenu diff --git a/Makefile b/Makefile index 855da61..7a55928 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,7 @@ sh: cp -f sh/yt $(DESTDIR)$(PREFIX)/bin cp -f sh/connect $(DESTDIR)$(PREFIX)/bin cp -f sh/nws $(DESTDIR)$(PREFIX)/bin + cp -f sh/pashmenu $(DESTDIR)$(PREFIX)/bin cp -f sh/urlhandle $(DESTDIR)$(PREFIX)/bin cp -f sh/ftphandle $(DESTDIR)$(PREFIX)/bin cp -f sh/indicate $(DESTDIR)$(PREFIX)/bin diff --git a/sh/pashmenu b/sh/pashmenu new file mode 100755 index 0000000..f6a1ce6 --- /dev/null +++ b/sh/pashmenu @@ -0,0 +1,8 @@ +#!/bin/sh + +# this is pashmenu. this program will only work if gpg's +# gui password dialog is enabled. i'm not why it's enabled, +# but it's required for this to work. + +choice=$(pash l | nenu) +pash c $choice From 444fe4a6ec74a160f21063b3d655d3a5e0d75d17 Mon Sep 17 00:00:00 2001 From: randomuser Date: Fri, 16 Jul 2021 16:28:09 -0500 Subject: [PATCH 088/197] make scream smaller --- c/scream.c | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/c/scream.c b/c/scream.c index eacf2a9..981f687 100644 --- a/c/scream.c +++ b/c/scream.c @@ -5,30 +5,18 @@ * good night and good riddance */ char newchar(char c, int i) { - switch(i) { - case 0: - if(isupper(c)) return c + 32; - if(c == 33) return -2; - else return c; - case 1: - if(islower(c)) return c - 32; - if(c == 33) return -2; - else return c; - default: return -1; - } -} -int advi(int i) { - switch(i) { - case 0: return 1; - case 1: return 0; - default: return -1; - } + if(i % 2) { + if(islower(c)) return c - 32; + } else if(isupper(c)) return c + 32; + if(c == 33) return -2; + return c; } int main(void) { char c; - int i = 0; + int i; + i = 0; while((c = getchar()) != EOF) { putchar(newchar(c, i)); - i = advi(i); + i++; } } From 621366fa3ebadd81442557b519562f33b425a51f Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 27 Jul 2021 11:49:28 -0500 Subject: [PATCH 089/197] add start --- sh/start | 3 +++ 1 file changed, 3 insertions(+) create mode 100755 sh/start diff --git a/sh/start b/sh/start new file mode 100755 index 0000000..48f86a5 --- /dev/null +++ b/sh/start @@ -0,0 +1,3 @@ +#!/bin/sh + +sudo connect c && sx From 81088a44c21f5bf9b0ecdf1ea2a3212aa42c2b2a Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 1 Aug 2021 10:47:04 -0500 Subject: [PATCH 090/197] add start program --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 7a55928..7136ed1 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,7 @@ sh: cp -f sh/indicate $(DESTDIR)$(PREFIX)/bin cp -f sh/vol $(DESTDIR)$(PREFIX)/bin cp -f sh/josm_launch $(DESTDIR)$(PREFIX)/bin + cp -f sh/start $(DESTDIR)$(PREFIX)/bin mkc: cc c/scream.c -o c/scream From 1e8c7be1a4c9b0b5ae14a275801b138a4f002571 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sat, 16 Oct 2021 16:35:51 -0500 Subject: [PATCH 091/197] added a simple boid program: will clean up later --- .gitignore | 1 + Makefile | 1 + c/boid.c | 224 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 226 insertions(+) create mode 100644 c/boid.c diff --git a/.gitignore b/.gitignore index d29796a..5c031a7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ *.tmp c/scream c/timer +c/boid c/a.out diff --git a/Makefile b/Makefile index 7136ed1..4a6be77 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,7 @@ sh: mkc: cc c/scream.c -o c/scream cc c/timer.c -o c/timer + cc c/boid.c -o c/boid -lm -lX11 c: cp -f c/scream $(DESTDIR)$(PREFIX)/bin cp -f c/timer $(DESTDIR)$(PREFIX)/bin diff --git a/c/boid.c b/c/boid.c new file mode 100644 index 0000000..7c659e0 --- /dev/null +++ b/c/boid.c @@ -0,0 +1,224 @@ +#include +#include +#include +#include +#include +#include + +#include + +#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y)) + +const double sprite[][2] = { + {0, 1}, + {-0.5, -1}, + {0, -0.5}, + {0.5, -1}, +}; +#define SIZE sizeof sprite / sizeof sprite[0] + +double buffer[SIZE][2]; +int boidcounter = 0; + +Display *d; +Window w; +XEvent e; +int s; +GC gc; + +typedef struct point { + double x; + double y; +} point; + +typedef struct boid { + int id; + point *p; + double rot; + struct boid *next; +} boid; + +void xinit(void) { + d = XOpenDisplay(NULL); + s = DefaultScreen(d); + w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 100, 100, 1, + BlackPixel(d, s), WhitePixel(d, s)); + XSelectInput(d, w, ExposureMask | KeyPressMask | PointerMotionMask); + XMapWindow(d, w); + gc = XCreateGC(d, w, 0, NULL); +} + +int sign(double x) { + return (x > 0) - (x < 0); +} + +point *rotate(double x, double y, double rot) { + point *ret = malloc(sizeof ret); + double rad = rot * M_PI/180; + + ret->x = x * cos(rad) - y * sin(rad); + ret->y = x * sin(rad) + y * cos(rad); + + return ret; +} + +double distance(point *a, point *b) { + return sqrt(pow(a->x - b->x, 2) + pow(a->y - b->y, 2)); +} + +void calculateRender( + double x, + double y, + double rot, + int scale +) { + memcpy(&buffer, &sprite, SIZE); + + for(int i = 0; i < SIZE; i++) { + point *p = rotate(sprite[i][0], sprite[i][1], rot); + + buffer[i][0] = p->x * scale + x; + buffer[i][1] = p->y * scale + y; + + free(p); + } +} + +void renderBuffer(void) { + for(int i = 0; i < SIZE - 1; i++) { + XDrawLine(d, w, gc, + buffer[i][0], buffer[i][1], + buffer[i + 1][0], buffer[i + 1][1]); + } + XDrawLine(d, w, gc, + buffer[0][0], buffer[0][1], + buffer[SIZE - 1][0], buffer[SIZE - 1][1]); +} + +void renderBoid(boid *boid) { + calculateRender( + boid->p->x, + boid->p->y, + boid->rot, + 5 + ); + renderBuffer(); +} + +boid *mkBoid(double x, double y, double rot) { + boid *b = malloc(sizeof b); + point *p = malloc(sizeof p); + b->p = p; + + b->p->x = x; + b->p->y = y; + b->rot = rot; + b->next = NULL; + b->id = boidcounter++; + + return b; +} + +void appendBoid(boid *destination, boid *source) { + destination->next = source; +} + +double averageHeading(boid *b) { + boid *c = b; + double sum; + int count; + while(c) { + sum += c->rot; + count++; + c = c->next; + } + return sum / count; +} + +void randomBoids(boid *b, int num) { + srand(time(0)); + boid *ptr = b; + for(int i = 0; i < num; i++) { + int w = rand() % DisplayWidth(d, s) + 1; + int h = rand() % DisplayHeight(d, s) + 1; + int deg = rand() % 360; + appendBoid(ptr, mkBoid(w, h, deg)); + ptr = ptr->next; + } +} + +void updateBoid(boid *b, boid *chain, int id, double average) { + point *p = rotate(5, 0, b->rot + 90); + b->p->x = b->p->x + p->x; + b->p->y = b->p->y + p->y; + double toTurn = 0; + + boid *c = chain; + while(c) { + if(c->id != id) { +// printf("boid %i is being pinged by boid %i\n", c->id, b->id); +// printf("boid %i is %f units away from boid %i\n", c->id, +// distance(c->p, b->p), b->id); + int dist = distance(c->p, b->p); + if(dist < 50) toTurn += dist / 75; + } + int w = DisplayWidth(d, s); + int h = DisplayHeight(d, s); + int centerw = w / 2 - b->p->x; + int centerh = h / 2 - b->p->y; + double deg = atan((double)centerh / (double)centerw) * 180/M_PI; +// printf("%f %i %i %i: degrees\n", deg, centerw, centerh, sign(deg)); + toTurn += sign(deg) * 0.5; + toTurn += (average - c->rot) * 0.4; + if(b->p->x > w) b->p->x = 0; + else if(b->p->x < 0) b->p->x = w; + if(b->p->y > h) b->p->y = 0; + else if(b->p->y < 0) b->p->y = h; + + toTurn = MIN(toTurn / 4, 30); + + b->rot += toTurn; + c = c->next; + } + + free(p); +} + +int main() { + xinit(); + boid *b = mkBoid(100, 100, 0); + randomBoids(b, 100); + while(1) { +/* + while(XPending(d)) { + XNextEvent(d, &e); + if(e.type == MotionNotify) { + XClearWindow(d, w); + boid *ptr = b; + while(ptr) { + updateBoid(ptr, b, ptr->id, averageHeading(b)); + renderBoid(ptr); + ptr = ptr->next; + } + } + } +*/ + XClearWindow(d, w); + boid *ptr = b; + while(ptr) { + updateBoid(ptr, b, ptr->id, averageHeading(b)); + renderBoid(ptr); + XFlush(d); + ptr = ptr->next; + } + while(XPending(d)) { + XNextEvent(d, &e); + switch(e.type) { + case KeyPress: + break; + } + } + usleep(50000); + } + return 0; +} From 8a6d333cd2ff9b0e43cb209901d0b48311597f00 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 17 Oct 2021 20:56:06 -0500 Subject: [PATCH 092/197] add pseudo-working anaconda program and intersect() function --- c/anaconda.c | 156 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 c/anaconda.c diff --git a/c/anaconda.c b/c/anaconda.c new file mode 100644 index 0000000..892116f --- /dev/null +++ b/c/anaconda.c @@ -0,0 +1,156 @@ +#include +#include +#include +#include +#include +#include + +#include + +typedef struct point { + double x; + double y; + struct point *next; +} point; + +typedef struct anaconda { + int score; + double rot; + struct point *chain; +} anaconda; + +Display *d; +Window w; +XEvent e; +int s; +GC gc; + +void xinit(void) { + d = XOpenDisplay(NULL); + s = DefaultScreen(d); + w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 100, 100, 1, + BlackPixel(d, s), WhitePixel(d, s)); + XSelectInput(d, w, ExposureMask | KeyPressMask | PointerMotionMask); + XMapWindow(d, w); + gc = XCreateGC(d, w, 0, NULL); +} + +/* thanks to + * https://stackoverflow.com/questions/3838329/how-can-i-check-if-two-segments-intersect/9997374#9997374 + * for functions ccw and intersect +*/ + +int ccw(point *a, point *b, point *c) { + return (c->y - a->y) * (b->x - a->x) > + (b->y - a->y) * (c->x - a->x); +} + +int intersect(point *a, point *b, point *c, point *d) { + return (ccw(a, c, d) != ccw(b, c, d)) && (ccw(a, b, c) != ccw(a, b, d)); +} + +point *mkPoint(double x, double y) { + point *ret = malloc(sizeof ret); + + ret->x = x; + ret->y = y; + ret->next = NULL; + + return ret; +} + +point *rotate(point *p, double rot) { + double rad = rot * M_PI/180; + + return mkPoint( + p->x * cos(rad) - p->y * sin(rad), + p->x * sin(rad) + p->y * cos(rad) + ); +} + +void appendPoint(point *dest, point *origin) { + while(dest->next) dest = dest->next; + dest->next = origin; +} + +void updateAnaconda(anaconda *anaconda) { + point *prev = anaconda->chain; + point *temp = rotate(mkPoint(10, 0), anaconda->rot); + point *new = mkPoint( + prev->x + temp->x, + prev->y + temp->y + ); + new->next = prev; + anaconda->chain = new; + + free(temp); + + point *traverser = new; + + while(1) { + if(traverser->next) { + if(traverser->next->next) { + traverser = traverser->next; + } else break; + } else break; + } + free(traverser->next); + traverser->next = NULL; +} + +point *generateChain(int length) { + point *ret = mkPoint(100, 100); + point *head = ret; + + for(int i = 1; i < length - 1; i++) { + ret->next = mkPoint( + 10 * i + 100, + 5 * i + 100 + ); + ret = ret->next; + } + + return head; +} + +anaconda *mkAnaconda(point *point, double rot) { + anaconda *ret = malloc(sizeof ret); + + ret->chain = point; + ret->rot = rot; + ret->score = 0; + + return ret; +} + +int main(void) { + anaconda *anaconda = mkAnaconda(generateChain(10), 0); + xinit(); + while(1) { + updateAnaconda(anaconda); + XClearWindow(d, w); + point *ptr = anaconda->chain; + while(ptr->next) { + XDrawLine(d, w, gc, ptr->x, ptr->y, ptr->next->x, ptr->next->y); + ptr = ptr->next; + } + while(XPending(d)) { + XNextEvent(d, &e); + switch(e.type) { + case KeyPress: + switch(e.xkey.keycode) { + case 113: /* left arrow key */ + anaconda->rot += 10; + break; + case 114: /* right arrow key */ + anaconda->rot -= 10; + break; + } + break; + } + } + usleep(100000); + } + + return 0; +} From 5905f78b17e13c8333c13ed59622ea669a5c9ce6 Mon Sep 17 00:00:00 2001 From: randomuser Date: Mon, 18 Oct 2021 18:52:33 -0500 Subject: [PATCH 093/197] complete collision detection --- c/anaconda.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/c/anaconda.c b/c/anaconda.c index 892116f..051eb6d 100644 --- a/c/anaconda.c +++ b/c/anaconda.c @@ -73,7 +73,7 @@ void appendPoint(point *dest, point *origin) { dest->next = origin; } -void updateAnaconda(anaconda *anaconda) { +int updateAnaconda(anaconda *anaconda) { point *prev = anaconda->chain; point *temp = rotate(mkPoint(10, 0), anaconda->rot); point *new = mkPoint( @@ -96,6 +96,19 @@ void updateAnaconda(anaconda *anaconda) { } free(traverser->next); traverser->next = NULL; + + point *top = anaconda->chain; + point *ptr = top; + for(int i = 0; i < 3; i++) { + if(ptr->next) ptr = ptr->next; + else return 1; /* we're fine, the snake is too short to intersect itself */ + } + + while(ptr->next) { + if(intersect(top, top->next, ptr, ptr->next)) return 0; + ptr = ptr->next; + } + return 1; } point *generateChain(int length) { @@ -124,10 +137,12 @@ anaconda *mkAnaconda(point *point, double rot) { } int main(void) { - anaconda *anaconda = mkAnaconda(generateChain(10), 0); + anaconda *anaconda = mkAnaconda(generateChain(30), 0); xinit(); while(1) { - updateAnaconda(anaconda); + if(!updateAnaconda(anaconda)) { + return 0; + } XClearWindow(d, w); point *ptr = anaconda->chain; while(ptr->next) { From c7b2d654a2b79e5eef162087d6509dfac4c37ade Mon Sep 17 00:00:00 2001 From: randomuser Date: Mon, 18 Oct 2021 18:53:47 -0500 Subject: [PATCH 094/197] add compile rule for anaconda --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 4a6be77..1c0f566 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,7 @@ mkc: cc c/scream.c -o c/scream cc c/timer.c -o c/timer cc c/boid.c -o c/boid -lm -lX11 + cc c/anaconda.c -o c/anaconda -lm -lX11 c: cp -f c/scream $(DESTDIR)$(PREFIX)/bin cp -f c/timer $(DESTDIR)$(PREFIX)/bin From 201e606e3366077ebad661b36898d41c2620ffcd Mon Sep 17 00:00:00 2001 From: randomuser Date: Mon, 18 Oct 2021 18:54:57 -0500 Subject: [PATCH 095/197] add install rule for anaconda and boids --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 1c0f566..c60007c 100644 --- a/Makefile +++ b/Makefile @@ -32,5 +32,7 @@ mkc: c: cp -f c/scream $(DESTDIR)$(PREFIX)/bin cp -f c/timer $(DESTDIR)$(PREFIX)/bin + cp -f c/boid $(DESTDIR)$(PREFIX)/bin + cp -f c/anaconda $(DESTDIR)$(PREFIX)/bin clean: rm c/scream From 78fc5a3a0e779d2f895a8c7db1f45b4e2c311e8b Mon Sep 17 00:00:00 2001 From: randomuser Date: Mon, 18 Oct 2021 20:03:02 -0500 Subject: [PATCH 096/197] add display border collision detection, fix malloc bug, add some apples --- c/anaconda.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/c/anaconda.c b/c/anaconda.c index 051eb6d..02b83f1 100644 --- a/c/anaconda.c +++ b/c/anaconda.c @@ -49,8 +49,16 @@ int intersect(point *a, point *b, point *c, point *d) { return (ccw(a, c, d) != ccw(b, c, d)) && (ccw(a, b, c) != ccw(a, b, d)); } +int randrange(int b, int s) { + return rand() % (b - s + 1) + s; +} + +int eucliddist(point *a, point *b) { + return sqrt(pow(a->x - b->x, 2) + pow(a->y - b->y, 2)); +} + point *mkPoint(double x, double y) { - point *ret = malloc(sizeof ret); + point *ret = malloc(sizeof *ret); ret->x = x; ret->y = y; @@ -73,7 +81,7 @@ void appendPoint(point *dest, point *origin) { dest->next = origin; } -int updateAnaconda(anaconda *anaconda) { +int updateAnaconda(anaconda *anaconda, int w, int h, point *apple) { point *prev = anaconda->chain; point *temp = rotate(mkPoint(10, 0), anaconda->rot); point *new = mkPoint( @@ -108,6 +116,18 @@ int updateAnaconda(anaconda *anaconda) { if(intersect(top, top->next, ptr, ptr->next)) return 0; ptr = ptr->next; } + + if( + new->x >= w || new->x <= 0 || + new->y >= h || new->y <= 0 + ) return 0; + + if(eucliddist(new, apple) <= 30) { + anaconda->score += 30; + apple->x = randrange(20, w); + apple->y = randrange(20, h); + } + return 1; } @@ -127,7 +147,7 @@ point *generateChain(int length) { } anaconda *mkAnaconda(point *point, double rot) { - anaconda *ret = malloc(sizeof ret); + anaconda *ret = malloc(sizeof *ret); ret->chain = point; ret->rot = rot; @@ -139,8 +159,12 @@ anaconda *mkAnaconda(point *point, double rot) { int main(void) { anaconda *anaconda = mkAnaconda(generateChain(30), 0); xinit(); + int width = DisplayWidth(d, s); + int height = DisplayHeight(d, s); + point *apple = mkPoint(randrange(20, width), randrange(20, height)); + srand(time(0)); while(1) { - if(!updateAnaconda(anaconda)) { + if(!updateAnaconda(anaconda, width, height, apple)) { return 0; } XClearWindow(d, w); @@ -149,6 +173,7 @@ int main(void) { XDrawLine(d, w, gc, ptr->x, ptr->y, ptr->next->x, ptr->next->y); ptr = ptr->next; } + XDrawArc(d, w, gc, apple->x - (5/2), apple->y - (5/2), 5, 5, 0, 360*64); while(XPending(d)) { XNextEvent(d, &e); switch(e.type) { From 5ffac9f8ce0c7c3fd05508105f81d0ab35b4e0fc Mon Sep 17 00:00:00 2001 From: randomuser Date: Mon, 18 Oct 2021 20:13:49 -0500 Subject: [PATCH 097/197] fix the apples and make them increase snake length --- c/anaconda.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/c/anaconda.c b/c/anaconda.c index 02b83f1..2c76f7f 100644 --- a/c/anaconda.c +++ b/c/anaconda.c @@ -93,17 +93,23 @@ int updateAnaconda(anaconda *anaconda, int w, int h, point *apple) { free(temp); - point *traverser = new; + if(eucliddist(new, apple) <= 30) { + anaconda->score += 30; + apple->x = randrange(20, w / 2); + apple->y = randrange(20, h / 2); + } else { + point *traverser = new; - while(1) { - if(traverser->next) { - if(traverser->next->next) { - traverser = traverser->next; + while(1) { + if(traverser->next) { + if(traverser->next->next) { + traverser = traverser->next; + } else break; } else break; - } else break; + } + free(traverser->next); + traverser->next = NULL; } - free(traverser->next); - traverser->next = NULL; point *top = anaconda->chain; point *ptr = top; @@ -124,8 +130,8 @@ int updateAnaconda(anaconda *anaconda, int w, int h, point *apple) { if(eucliddist(new, apple) <= 30) { anaconda->score += 30; - apple->x = randrange(20, w); - apple->y = randrange(20, h); + apple->x = randrange(20, w / 2); + apple->y = randrange(20, h / 2); } return 1; @@ -159,10 +165,10 @@ anaconda *mkAnaconda(point *point, double rot) { int main(void) { anaconda *anaconda = mkAnaconda(generateChain(30), 0); xinit(); + srand(time(0)); int width = DisplayWidth(d, s); int height = DisplayHeight(d, s); - point *apple = mkPoint(randrange(20, width), randrange(20, height)); - srand(time(0)); + point *apple = mkPoint(randrange(20, width / 2 - 20), randrange(20, height / 2 - 20)); while(1) { if(!updateAnaconda(anaconda, width, height, apple)) { return 0; @@ -173,6 +179,7 @@ int main(void) { XDrawLine(d, w, gc, ptr->x, ptr->y, ptr->next->x, ptr->next->y); ptr = ptr->next; } + printf("%f %f\n", apple->x, apple->y); XDrawArc(d, w, gc, apple->x - (5/2), apple->y - (5/2), 5, 5, 0, 360*64); while(XPending(d)) { XNextEvent(d, &e); From fbe0be65af2d144d403b70017bd450742f1f15f7 Mon Sep 17 00:00:00 2001 From: randomuser Date: Mon, 18 Oct 2021 20:14:27 -0500 Subject: [PATCH 098/197] add anaconda to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 5c031a7..55f4176 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ c/scream c/timer c/boid c/a.out +c/anaconda From 7f7a69448659e2d8d62655f275f697dad19b6fe8 Mon Sep 17 00:00:00 2001 From: randomuser Date: Mon, 18 Oct 2021 20:15:59 -0500 Subject: [PATCH 099/197] remove comments from boid.c --- c/boid.c | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/c/boid.c b/c/boid.c index 7c659e0..629d3fc 100644 --- a/c/boid.c +++ b/c/boid.c @@ -156,9 +156,6 @@ void updateBoid(boid *b, boid *chain, int id, double average) { boid *c = chain; while(c) { if(c->id != id) { -// printf("boid %i is being pinged by boid %i\n", c->id, b->id); -// printf("boid %i is %f units away from boid %i\n", c->id, -// distance(c->p, b->p), b->id); int dist = distance(c->p, b->p); if(dist < 50) toTurn += dist / 75; } @@ -167,7 +164,6 @@ void updateBoid(boid *b, boid *chain, int id, double average) { int centerw = w / 2 - b->p->x; int centerh = h / 2 - b->p->y; double deg = atan((double)centerh / (double)centerw) * 180/M_PI; -// printf("%f %i %i %i: degrees\n", deg, centerw, centerh, sign(deg)); toTurn += sign(deg) * 0.5; toTurn += (average - c->rot) * 0.4; if(b->p->x > w) b->p->x = 0; @@ -189,20 +185,6 @@ int main() { boid *b = mkBoid(100, 100, 0); randomBoids(b, 100); while(1) { -/* - while(XPending(d)) { - XNextEvent(d, &e); - if(e.type == MotionNotify) { - XClearWindow(d, w); - boid *ptr = b; - while(ptr) { - updateBoid(ptr, b, ptr->id, averageHeading(b)); - renderBoid(ptr); - ptr = ptr->next; - } - } - } -*/ XClearWindow(d, w); boid *ptr = b; while(ptr) { From c1434abc40eb9d80c53a5f3312985610e7577674 Mon Sep 17 00:00:00 2001 From: randomuser Date: Mon, 18 Oct 2021 20:23:36 -0500 Subject: [PATCH 100/197] clean up updateAnaconda() --- c/anaconda.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/c/anaconda.c b/c/anaconda.c index 2c76f7f..fda09e7 100644 --- a/c/anaconda.c +++ b/c/anaconda.c @@ -82,13 +82,14 @@ void appendPoint(point *dest, point *origin) { } int updateAnaconda(anaconda *anaconda, int w, int h, point *apple) { - point *prev = anaconda->chain; - point *temp = rotate(mkPoint(10, 0), anaconda->rot); - point *new = mkPoint( - prev->x + temp->x, - prev->y + temp->y + point *temp, *new, *ptr; + new = anaconda->chain; + temp = rotate(mkPoint(10, 0), anaconda->rot); + new = mkPoint( + new->x + temp->x, + new->y + temp->y ); - new->next = prev; + new->next = anaconda->chain; anaconda->chain = new; free(temp); @@ -98,28 +99,26 @@ int updateAnaconda(anaconda *anaconda, int w, int h, point *apple) { apple->x = randrange(20, w / 2); apple->y = randrange(20, h / 2); } else { - point *traverser = new; + ptr = new; while(1) { - if(traverser->next) { - if(traverser->next->next) { - traverser = traverser->next; - } else break; + if(ptr->next) { + if(ptr->next->next) ptr = ptr->next; + else break; } else break; } - free(traverser->next); - traverser->next = NULL; + free(ptr->next); + ptr->next = NULL; } - point *top = anaconda->chain; - point *ptr = top; + ptr = anaconda->chain; for(int i = 0; i < 3; i++) { if(ptr->next) ptr = ptr->next; else return 1; /* we're fine, the snake is too short to intersect itself */ } while(ptr->next) { - if(intersect(top, top->next, ptr, ptr->next)) return 0; + if(intersect(new, new->next, ptr, ptr->next)) return 0; ptr = ptr->next; } From 2bde763903e702a2a1751ac8d4f34bd6da1227cd Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 23 Nov 2021 12:52:42 -0600 Subject: [PATCH 101/197] disp changes --- sh/disp | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/sh/disp b/sh/disp index 2da6d1c..784a7fd 100755 --- a/sh/disp +++ b/sh/disp @@ -4,33 +4,26 @@ exists() { xrandr | grep ' connected' | grep "${1}" | wc -l } -if [ $(exists "HDMI-2") -eq 1 ] && [ $(exists "VGA-1") -eq 1 ]; then - printf "HDMI-2, VGA-1 exists\n" - xrandr --output HDMI-2 --right-of VGA-1 --auto +if [ $(exists "HDMI-2") -eq 1 ]; then + printf "one" xrandr --output LVDS-1 --off --auto - bspc monitor HDMI-2 -a I II III IV V - bspc monitor VGA-1 -a VI VII VIII IX + xrandr --output VGA-1 --off --auto + bspc monitor -d I II III IV V VI VII VIII IX X + bspc monitor -g 1680x1050+0+0 + exit 0 +fi + +if [ $(exists "LVDS-1") -eq 1 ]; then + bspc monitor -d I II III IV V VI VII VIII IX X + bspc monitor LVDS-1 -a I II III IV V VI VII VIII IX exit 0 fi if [ $(exists "HDMI-2") -eq 1 ] && [ $(exists "LVDS-1") -eq 1 ]; then - printf "HDMI-2, LVDS-1 exists\n" + printf "two" xrandr --output HDMI-2 --above LVDS-1 --auto - bspc monitor LVDS-1 -a I II III IV V - bspc monitor HDMI-2 -a VI VII VIII IX + xrandr --output VGA-1 --off --auto + bspc monitor LVDS-1 -a I III V VII IX + bspc monitor HDMI-2 -a II IV VI VIII exit 0 fi - -if [ $(exists "HDMI-1") -eq 1 ] && [ $(exists "LVDS-1") -eq 1 ]; then - printf "HDMI-1, LVDS-1 exists\n" - xrandr --output HDMI-1 --above LVDS-1 --auto - bspc monitor LVDS-1 -a I II III IV V - bspc monitor HDMI-1 -a VI VII VIII IX - exit 0 -fi - -printf "defaulting to default configuration\n" -xrandr --output HDMI-1 --off -xrandr --output HDMI-2 --off -bspc monitor -d I II III IV V VI VII VIII IX X -exit 0 From c798d4ddb3723265e316715ea2e4fb7906aa72f9 Mon Sep 17 00:00:00 2001 From: randomuser Date: Fri, 7 Jan 2022 02:29:04 -0600 Subject: [PATCH 102/197] add simplestatus to utils --- .gitignore | 1 + Makefile | 2 + c/simplestatus.c | 328 +++++++++++++++++++++++++++++++++++++++++++++ man/simplestatus.1 | 87 ++++++++++++ 4 files changed, 418 insertions(+) create mode 100644 c/simplestatus.c create mode 100644 man/simplestatus.1 diff --git a/.gitignore b/.gitignore index 55f4176..13019a4 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ c/timer c/boid c/a.out c/anaconda +c/simplestatus diff --git a/Makefile b/Makefile index c60007c..08f856f 100644 --- a/Makefile +++ b/Makefile @@ -29,10 +29,12 @@ mkc: cc c/timer.c -o c/timer cc c/boid.c -o c/boid -lm -lX11 cc c/anaconda.c -o c/anaconda -lm -lX11 + cc c/simplestatus.c -o c/simplestatus c: cp -f c/scream $(DESTDIR)$(PREFIX)/bin cp -f c/timer $(DESTDIR)$(PREFIX)/bin cp -f c/boid $(DESTDIR)$(PREFIX)/bin cp -f c/anaconda $(DESTDIR)$(PREFIX)/bin + cp -f c/simplestatus $(DESTDIR)$(PREFIX)/bin clean: rm c/scream diff --git a/c/simplestatus.c b/c/simplestatus.c new file mode 100644 index 0000000..896db22 --- /dev/null +++ b/c/simplestatus.c @@ -0,0 +1,328 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define NAME "simplestatus" + +typedef struct module { + char *mod_name; + int refresh; + int signal; + struct module *next; +} module; + +typedef struct cache { + char *mod_name; + char *data; + struct cache *next; +} cache; + +const int alloc_inc = 30; +const char module_text[] = "module"; +const char order_text[] = "order"; +const char format_text[] = "format"; +char *format_string = NULL; +module *table = NULL; +cache *mcache = NULL; + +void llprintf(char *fmt) { + int length = strlen(fmt); + cache *ptr = mcache; + + ptr = mcache; + + for(int i = 0; i < length; i++) { + if(fmt[i] == '&') { + fprintf(stdout, "%s", ptr->data); + ptr = ptr->next; + } else { + fprintf(stdout, "%c", fmt[i]); + } + } + + fprintf(stdout, "\n"); + + fflush(stdout); +} + +char *get_conf_dir(void) { + /* check if $XDG_CONFIG_DIR is set */ + char *rootdir, *append; + if((rootdir = getenv("XDG_CONFIG_DIR"))) { + append = "/"NAME"/"; + } else if((rootdir = getenv("HOME"))) { + append = "/.config/"NAME"/"; + } else { + return NULL; + } + + char *buffer = malloc(strlen(rootdir) + strlen(append) + 1); + strcpy(buffer, rootdir); + strcat(buffer, append); + + return buffer; +} + +char *execstdout(char *file, char *arg[], char *env[]) { + int pfds[2]; + + if(pipe(pfds) == -1) { + perror("PIPE"); + fprintf(stderr, "pipe failed! aborting.\n"); + abort(); + } + + int pid = fork(); + + if(pid == -1) { + fprintf(stderr, "fork failed! aborting.\n"); + abort(); + } else if(pid == 0) { + if(close(1) == -1) exit(0); + if(dup(pfds[1]) == -1) exit(0); + if(close(pfds[0])) exit(0); + execlp(file, file, NULL); + } else { + wait(NULL); + + int bufsize = alloc_inc, total = 0; + char *buf = malloc(bufsize); + + if(!buf) { + fprintf(stderr, "malloc failed! aborting.\n"); + abort(); + } + + for(;;) { + int size = read(pfds[0], buf + total, alloc_inc); + + if(size == -1) { + if(errno == EINTR) { + continue; + } else { + free(buf); + return NULL; + } + } + + total += size; + + if(size == alloc_inc) { /* we need to reallocate */ + buf = realloc(buf, (bufsize *= 2)); + if(!buf) { + fprintf(stderr, "realloc failed! aborting.\n"); + abort(); + } + continue; + } + + buf[total] = '\0'; + buf = realloc(buf, strlen(buf)); + + return buf; + } + close(pfds[0]); + } +} + +char *read_line(FILE *fp) { + int size = 30; + int filled = 0; + int c; + char *buf = malloc(size); + + while(c = fgetc(fp)) { + if(c == EOF) { + if(filled == 0) { + free(buf); + return NULL; + } else { + break; + } + } + if(c == '\n') break; + if(size == filled) { + buf = realloc(buf, (size *= 2)); + } + buf[filled] = c; + filled++; + } + buf[filled] = '\0'; + + return buf; +} + +module *parse_file(char *file) { + FILE *fp = fopen(file, "r"); + char *cline; + module *current = NULL, *head = NULL; + int linenumber = 0; + while((cline = read_line(fp)) != NULL) { + linenumber++; + /* free the string up here */ + if(strlen(cline) == 0) { + free(cline); + continue; + } + if(cline[0] == '#') { + free(cline); + continue; + } + + char *command = strdup(strtok(cline, " ")); + if(!memcmp(command, module_text, sizeof module_text)) { + if(current == NULL) { + current = malloc(sizeof *current); + head = current; + current->next = NULL; + } else { + current->next = malloc(sizeof *current); + current = current->next; + current->next = NULL; + } + + /* get the module name */ + char *token = strtok(NULL, " "); + if(!token) { + fprintf(stderr, "syntax error at line %i: specify a module name!\n", linenumber); + return NULL; + } + current->mod_name = strdup(token); + + /* get the signal number */ + token = strtok(NULL, " "); + if(!token) { + fprintf(stderr, "syntax error at line %i: specify the signal number!\n", linenumber); + return NULL; + } + current->signal = atoi(token); + + /* get the refresh duration */ + token = strtok(NULL, " "); + if(!token) { + fprintf(stderr, "syntax error at line %i: specify the refresh duration!\n", linenumber); + return NULL; + } + current->refresh = atoi(token); + + free(cline); + continue; + } else if(!memcmp(command, order_text, sizeof order_text)) { + if(mcache) { + fprintf(stderr, "syntax error at line %i: you can't issue the order command twice\n", linenumber); + return NULL; + } + + char *token; + cache *ptr = mcache; + while(token = strtok(NULL, " ")) { + if(mcache) { + ptr->next = malloc(sizeof *mcache); + ptr = ptr->next; + } else { + mcache = malloc(sizeof mcache); + ptr = mcache; + } + ptr->mod_name = token; + ptr->data = NULL; + ptr->next = NULL; + } + } else if(!memcmp(command, format_text, sizeof format_text)) { + char *pattern = cline + sizeof format_text; + format_string = strdup(pattern); + } + } + + return head; +} + +int is_dir(char *dir) { + struct stat sb; + + if(stat(dir, &sb) == 0 && S_ISDIR(sb.st_mode)) { + return 1; + } else { + return 0; + } +} + +void sighandler(int sig) { + module *ptr = table; + char *mod = NULL; + while(ptr) { + if(ptr->signal == sig) { + mod = ptr->mod_name; + + char *path = malloc(strlen(mod) + 3); + strcpy(path, "./"); + strcat(path, mod); + + char *output = execstdout(path, NULL, NULL); + free(path); + + cache *ptr2 = mcache; + while(ptr2) { + if(!memcmp(mod, ptr2->mod_name, strlen(mod))) { + ptr2->data = output; + break; + } + ptr2 = ptr2->next; + } + } + ptr = ptr->next; + } +} + +void sighandler_w(int sig) { + sighandler(sig); + llprintf(format_string); +} + +void create_sighandle_from_table(void) { + module *ptr = table; + struct sigaction *action = malloc(sizeof *action); + action->sa_handler = sighandler_w; + sigemptyset(&(action->sa_mask)); + action->sa_flags = 0; + while(ptr) { + sigaction(ptr->signal, action, NULL); + sighandler(ptr->signal); /* force an update */ + ptr = ptr->next; + } +} + +int main(void) { + char *conf_dir = get_conf_dir(); + if(!is_dir(conf_dir)) { + fprintf(stderr, "create configuration at %s and try again\n", conf_dir); + exit(1); + } + chdir(conf_dir); + table = parse_file("config"); + create_sighandle_from_table(); + llprintf(format_string); + + int counter = 0; + + for(;;) { + module *ptr = table; + + counter++; + sleep(1); + + while(ptr) { + if(counter % ptr->refresh == 0) { + sighandler_w(ptr->signal); + } + ptr = ptr->next; + } + } + + return 0; +} diff --git a/man/simplestatus.1 b/man/simplestatus.1 new file mode 100644 index 0000000..7dcb8a1 --- /dev/null +++ b/man/simplestatus.1 @@ -0,0 +1,87 @@ +'\" t +.TH SIMPLESTATUS 1 simplestatus +.SH NAME +simplestatus \- simple, lightweight status bar content generator +.SH SYNOPSIS +.B simplestatus +.SH DESCRIPTION +simplestatus is a simple status bar content generator for statusbars which accept their input via standard input (such as lemonbar), or can be used in conjunction with other utilities to set their statusbars (e.g. dwm's statusbar). simplestatus is configured via a configuration file. + +simplestatus works on the premise of each component in the statusbar being a module; in this case, simplestatus represents them in shell scripts residing in the configuration directory. When a module needs to be updated, the cooresponding shell script is executed and its stdout read as the output of the module. Modules can be updated via signals send to the process or via timers, all specified in the configuration file. +.SH CONFIGURATION +The configuration file resides in the configuration directory. The configuration file location is determined via checking the following places: +.IP +o $XDG_CONFIG_DIR/simplestatus/config +.IP +o $HOME/.config/simplestatus/config +.P +If after these two steps the configuration cannot be found, simplestatus exits. + +Once the configuration file location is determined, the configuration file is read and parsed. There are three main directives in the configuration file: +.IP +o module +.IP +o order +.IP +o format +.SS module +This directive takes three arguments: the module name, the signal trigger number, and the timer trigger. For example +.IP +.B module power 7 30 +.P +defines a module named ``power'', which is updated when signal 7 is recieved (SIGBUS) or every thirty seconds. ``power'' must be an executable placed in the configuration directory (e.g. the directory in which the configuration file resides) and must have the executable flag set for the current user. Note that entering the signals' symbolic name (SIGBUS) instead of the number (7) is not supported at this time. +.SS order +The ``order'' directive specifies in what order the modules will be placed in the format string, defined by the directive ``format''. For example, +.IP +.B order power time date wm +.P +specifies the order in which the modules will be inserted in the format string, starting with ``power'' and ending with ``wm''. +.SS format +``format'' specifies the format string that the output of the modules will be inserted into. Below is an example command: +.IP +.B format %{l}&%{c}&%{r}& +.SH CONFIGURATION EXAMPLE +Assume we have the following modules, who output the following values: +.TS +tab(@) allbox; +l|l . +MODULE@EVALUATED VALUE +foo@bar +ping@pong +a@b +.TE +.P +and this configuration: +.IP +module foo 7 30 + +module ping 10 30 + +module a 12 120 + +order foo ping a + +format output of foo: &; output of ping: &; output of a: & +.P +we will get the output: +.IP +.B output of foo: bar; output of ping: pong; output of a: b +.P +Should you wish to make comments, prefix lines with ``#''. If you wish to make spaces between instructions, make an empty line. +.SH COMMON PITFALLS +.IP +o Don't assign SIGINT (2) to a module unless you want it to update when you ^C! +.SH PLANNED FEATURES +.IP +o If the configuration file is marked +x, execute and read contents from the script's stdout to be parsed. +o free(...) memory when finished. +o Add ability to export environment variables to scripts via configuration file. +o Add signal to force re-parsing of configuration file. +.SH KNOWN BUGS +o Lack of use of free(...), causing potential for memory leaks. +.SH SEE ALSO +.BR lemonbar (1), +.BR slstatus (1) + +.SH AUTHOR +randomuser From 0dda1750947f9ede4b48a92bd11d0d70590f2ee1 Mon Sep 17 00:00:00 2001 From: randomuser Date: Fri, 7 Jan 2022 02:30:04 -0600 Subject: [PATCH 103/197] Makefile maintance --- Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 08f856f..3dd08b2 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ install: man sh mkc c man: # this used to be {command} $(DESTDIR)$(PREFIX)/man/man1 - # this did not work on my computer, but might be needed in other computers + # this did not work on my computer, but might be needed on other installations mkdir -p /usr/local/man/man1 cp -f man/* /usr/local/man/man1 sh: @@ -38,3 +38,7 @@ c: cp -f c/simplestatus $(DESTDIR)$(PREFIX)/bin clean: rm c/scream + rm c/timer + rm c/boid + rm c/anaconda + rm c/simplestatus From dc2969a5f8f438b2722dccff0be98b34556f9b13 Mon Sep 17 00:00:00 2001 From: randomuser Date: Fri, 7 Jan 2022 02:36:48 -0600 Subject: [PATCH 104/197] add more file closing to negate pipe(...) error --- c/simplestatus.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/c/simplestatus.c b/c/simplestatus.c index 896db22..7e00d02 100644 --- a/c/simplestatus.c +++ b/c/simplestatus.c @@ -128,6 +128,7 @@ char *execstdout(char *file, char *arg[], char *env[]) { return buf; } close(pfds[0]); + close(pfds[1]); } } @@ -239,6 +240,8 @@ module *parse_file(char *file) { } } + fclose(fp); + return head; } From 44a0d2a9d3ba5bff1ca86fadb13e64d0153ba0e1 Mon Sep 17 00:00:00 2001 From: randomuser Date: Fri, 7 Jan 2022 15:45:58 -0600 Subject: [PATCH 105/197] actually close the fds --- c/simplestatus.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/c/simplestatus.c b/c/simplestatus.c index 7e00d02..9866bd8 100644 --- a/c/simplestatus.c +++ b/c/simplestatus.c @@ -107,6 +107,8 @@ char *execstdout(char *file, char *arg[], char *env[]) { continue; } else { free(buf); + close(pfds[0]); + close(pfds[1]); return NULL; } } @@ -125,10 +127,10 @@ char *execstdout(char *file, char *arg[], char *env[]) { buf[total] = '\0'; buf = realloc(buf, strlen(buf)); + close(pfds[0]); + close(pfds[1]); return buf; } - close(pfds[0]); - close(pfds[1]); } } From f21c709e4a7638dbdca73a019c253127f151e1d5 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sat, 5 Feb 2022 18:50:00 -0600 Subject: [PATCH 106/197] add proxtest, software for testing public proxy lists --- Makefile | 2 ++ sh/proxtest | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100755 sh/proxtest diff --git a/Makefile b/Makefile index 3dd08b2..b3c37d2 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,7 @@ sh: cp -f sh/vol $(DESTDIR)$(PREFIX)/bin cp -f sh/josm_launch $(DESTDIR)$(PREFIX)/bin cp -f sh/start $(DESTDIR)$(PREFIX)/bin + cp -f sh/proxtest $(DESTDIR)$(PREFIX)/bin mkc: cc c/scream.c -o c/scream @@ -30,6 +31,7 @@ mkc: cc c/boid.c -o c/boid -lm -lX11 cc c/anaconda.c -o c/anaconda -lm -lX11 cc c/simplestatus.c -o c/simplestatus + c: cp -f c/scream $(DESTDIR)$(PREFIX)/bin cp -f c/timer $(DESTDIR)$(PREFIX)/bin diff --git a/sh/proxtest b/sh/proxtest new file mode 100755 index 0000000..6769690 --- /dev/null +++ b/sh/proxtest @@ -0,0 +1,79 @@ +#!/bin/sh + +output_as_proxychains=1 +randomize=1 +choose=0 +outputted_proxies="" +temp_output=$(mktemp) +while getopts ":pt:rc:" options; do + case $options in + p) + output_as_proxychains=0 + ;; + t) + temp_output=$OPTARG + ;; + r) + randomize=0 + ;; + c) + choose=$OPTARG + ;; + :) + printf "specify argument\n" + exit + ;; + *) + printf "what has happened\n" + exit + ;; + esac +done + +# get the tor port number using this lsof incantination +torport=$(\ + sudo lsof -nP -iTCP -sTCP:LISTEN | \ + grep tor | \ + awk -F'[ :]+' 'NR = 1 {print $10}' +) + +curl --silent --preproxy socks5://127.0.0.1:$torport https://raw.githubusercontent.com/hookzof/socks5_list/master/proxy.txt -o $temp_output + +printf "estimated worsecase run time: %i seconds\n" $(wc -l $temp_output | awk -F' ' '{print $1}') 1>&2 + +looped=$(\ + cat $temp_output | \ + ( [ $randomize -eq 0 ] && shuf || cat ) | \ + ( [ $choose -ne 0 ] && head -n $choose || cat ) | \ + tr '\n' ' ' | \ + tr -d '\r' +) + +for i in $looped; do + ip=$(printf $i | awk -F':' '{print $1}') + port=$(printf $i | awk -F':' '{print $2}' | tr -d '\r') + + # TODO: timeout is a non-posix gnu extension, remove/replace it + timeout 2s nc -zv -x 127.0.0.1:$torport $ip $port 2>/dev/null 1>&2 && \ + outputted_proxies="$outputted_proxies $i" && \ + printf "success! %s\n" $i 1>&2 || \ + printf "failure! %s\n" $i 1>&2 +done + +if [ $output_as_proxychains -eq 0 ]; then + printf "# generated by proxtest.sh @ %s\n" "$(date)" + printf "random_chain\nproxy_dns\nchain_len = 5\n" + printf "tcp_read_time_out 15000\ntcp_connect_time_out 8000\n" + printf "[ProxyList]\n" + + # assumes all socks5 proxies, change this in future + for i in $outputted_proxies; do + printf "socks5 %s\n" "$(printf %s $i | tr ':' ' ')" + done + + printf "# finished!\n" +else + for i in $outputted_proxies; do + printf "%s\n" $i + done +fi From df43732aa8ab3b9e77211d82e81c5abeeaf024ed Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 22 Feb 2022 12:37:36 -0600 Subject: [PATCH 107/197] add program for planning center online --- Makefile | 1 + sh/pco | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100755 sh/pco diff --git a/Makefile b/Makefile index b3c37d2..3cc4aab 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,7 @@ sh: cp -f sh/josm_launch $(DESTDIR)$(PREFIX)/bin cp -f sh/start $(DESTDIR)$(PREFIX)/bin cp -f sh/proxtest $(DESTDIR)$(PREFIX)/bin + cp -f sh/pco $(DESTDIR)$(PREFIX)/bin mkc: cc c/scream.c -o c/scream diff --git a/sh/pco b/sh/pco new file mode 100755 index 0000000..9f92017 --- /dev/null +++ b/sh/pco @@ -0,0 +1,88 @@ +#!/bin/sh +# script for interfacing with planning center online + +appid=$(cat "$HOME/.local/share/pco/appid") +token=$(cat "$HOME/.local/share/pco/token") +userid=$(cat "$HOME/.local/share/pco/userid") + +get_blockouts_online () { +curl -su "$appid:$token" "https://api.planningcenteronline.com/services/v2/people/$userid/blockouts" | \ + jq .data[].attributes.ends_at | \ + awk -F'"|-|T' ' +function y(x) { + if (x == 1) return "Jan" + if (x == 2) return "Feb" + if (x == 3) return "Mar" + if (x == 4) return "Apr" + if (x == 5) return "May" + if (x == 6) return "Jun" + if (x == 7) return "Jul" + if (x == 8) return "Aug" + if (x == 9) return "Sep" + if (x == 10) return "Oct" + if (x == 11) return "Nov" + if (x == 12) return "Dec" + return "Unk" +} + +{print y($3) " " $4 " " $2}' | \ + tr '\n' '|' | \ + sed 's/.\{1\}$//' +} + +get_blockouts_local () { + grep "MSG Blockout date" "$DOTREMINDERS" | \ + awk -F' ' '{print $2 " " $3 " " $4}' +} + +get_blockouts () { + all_dates=$(get_blockouts_online) + OLDIFS="$IFS" + IFS="|" + for i in $all_dates; do + results=$(grep -c "^REM $i MSG Blockout date" "$DOTREMINDERS") + [ "$results" -eq 0 ] && \ + printf "REM %s MSG Blockout date\n" "$i" >> "$DOTREMINDERS" && \ + printf "added %s to calendar\n" "$i" || \ + printf "omitted %s from the calendar, it's already there\n" "$i" + done + IFS="$OLDIFS" +} + +push_blockouts () { + file=$(mktemp) + get_blockouts_online | tr '|' '\n' >> "$file" + local=$(get_blockouts_local) + + # don't mess with the spacing + OLDIFS=$IFS + IFS=" +" + printf "temp file: %s\n" "$file" + + for i in $local; do + count=$(grep -c "^$i$" "$file") + if [ "$count" -eq 0 ]; then + printf "push: %s\n" "$i" + stddate=$(date --date="$i" "+%Y-%m-%dT06:00:00Z") + curl -X POST -H "Content-Type: application/json" -d " + { + \"data\": { + \"attributes\": { + \"reason\": \"n/a\", + \"repeat_frequency\": \"no_repeat\", + \"starts_at\": \"$stddate\", + \"ends_at\": \"$stddate\" + } + } + }" -su "$appid:$token" "https://api.planningcenteronline.com/services/v2/people/$userid/blockouts" + fi + done + + IFS=$OLDIFS + + rm "$file" +} + +get_blockouts +push_blockouts From d9d7c028e96192a024327de35ca21d9f1ac3e9c3 Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 22 Feb 2022 12:38:53 -0600 Subject: [PATCH 108/197] move wal to wallpaper to avoid pywal collision --- Makefile | 2 +- sh/{wal => wallpaper} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename sh/{wal => wallpaper} (100%) diff --git a/Makefile b/Makefile index 3cc4aab..7a2d4cb 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ sh: cp -f sh/paste $(DESTDIR)$(PREFIX)/bin cp -f sh/bat $(DESTDIR)$(PREFIX)/bin cp -f sh/disp $(DESTDIR)$(PREFIX)/bin - cp -f sh/wal $(DESTDIR)$(PREFIX)/bin + cp -f sh/wallpaper $(DESTDIR)$(PREFIX)/bin cp -f sh/yt $(DESTDIR)$(PREFIX)/bin cp -f sh/connect $(DESTDIR)$(PREFIX)/bin cp -f sh/nws $(DESTDIR)$(PREFIX)/bin diff --git a/sh/wal b/sh/wallpaper similarity index 100% rename from sh/wal rename to sh/wallpaper From 9c9eae22bbd8058a8151a376b81d74b265317634 Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 22 Mar 2022 22:17:27 -0500 Subject: [PATCH 109/197] added git-survey, recurse over subdirs and check if there's anything to push --- Makefile | 1 + sh/git-survey | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100755 sh/git-survey diff --git a/Makefile b/Makefile index 7a2d4cb..49e39df 100644 --- a/Makefile +++ b/Makefile @@ -25,6 +25,7 @@ sh: cp -f sh/start $(DESTDIR)$(PREFIX)/bin cp -f sh/proxtest $(DESTDIR)$(PREFIX)/bin cp -f sh/pco $(DESTDIR)$(PREFIX)/bin + cp -f sh/git-survey $(DESTDIR)$(PREFIX)/bin mkc: cc c/scream.c -o c/scream diff --git a/sh/git-survey b/sh/git-survey new file mode 100755 index 0000000..2dac26c --- /dev/null +++ b/sh/git-survey @@ -0,0 +1,13 @@ +#!/bin/sh + +for i in $(ls); do + cd $i + exists=$( + git status |\ + grep 'Your branch is ahead of ' |\ + wc -l + ) + + [ "$exists" -eq 0 ] || printf "> %s\n" "$i" + cd .. +done From 7cd0e131ff0c75575165c6c2929b4e35fcbc108c Mon Sep 17 00:00:00 2001 From: randomuser Date: Wed, 8 Jun 2022 00:31:34 -0500 Subject: [PATCH 110/197] spring cleaning --- Makefile | 8 +------- sh/bat | 3 --- sh/ftphandle | 6 ------ sh/indicate | 6 ------ sh/josm_launch | 6 ------ sh/pashmenu | 8 -------- sh/start | 3 --- sh/urlhandle | 18 ------------------ sh/xkcd | 40 ---------------------------------------- 9 files changed, 1 insertion(+), 97 deletions(-) delete mode 100755 sh/bat delete mode 100755 sh/ftphandle delete mode 100755 sh/indicate delete mode 100755 sh/josm_launch delete mode 100755 sh/pashmenu delete mode 100755 sh/start delete mode 100755 sh/urlhandle delete mode 100755 sh/xkcd diff --git a/Makefile b/Makefile index 49e39df..6aea880 100644 --- a/Makefile +++ b/Makefile @@ -10,19 +10,12 @@ man: sh: mkdir -p $(DESTDIR)$(PREFIX)/bin cp -f sh/paste $(DESTDIR)$(PREFIX)/bin - cp -f sh/bat $(DESTDIR)$(PREFIX)/bin cp -f sh/disp $(DESTDIR)$(PREFIX)/bin cp -f sh/wallpaper $(DESTDIR)$(PREFIX)/bin cp -f sh/yt $(DESTDIR)$(PREFIX)/bin cp -f sh/connect $(DESTDIR)$(PREFIX)/bin cp -f sh/nws $(DESTDIR)$(PREFIX)/bin - cp -f sh/pashmenu $(DESTDIR)$(PREFIX)/bin - cp -f sh/urlhandle $(DESTDIR)$(PREFIX)/bin - cp -f sh/ftphandle $(DESTDIR)$(PREFIX)/bin - cp -f sh/indicate $(DESTDIR)$(PREFIX)/bin cp -f sh/vol $(DESTDIR)$(PREFIX)/bin - cp -f sh/josm_launch $(DESTDIR)$(PREFIX)/bin - cp -f sh/start $(DESTDIR)$(PREFIX)/bin cp -f sh/proxtest $(DESTDIR)$(PREFIX)/bin cp -f sh/pco $(DESTDIR)$(PREFIX)/bin cp -f sh/git-survey $(DESTDIR)$(PREFIX)/bin @@ -40,6 +33,7 @@ c: cp -f c/boid $(DESTDIR)$(PREFIX)/bin cp -f c/anaconda $(DESTDIR)$(PREFIX)/bin cp -f c/simplestatus $(DESTDIR)$(PREFIX)/bin + clean: rm c/scream rm c/timer diff --git a/sh/bat b/sh/bat deleted file mode 100755 index 88788aa..0000000 --- a/sh/bat +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -cat /sys/class/power_supply/BAT?/capacity diff --git a/sh/ftphandle b/sh/ftphandle deleted file mode 100755 index b541c40..0000000 --- a/sh/ftphandle +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -# This one is relatively simple. Relay the first argument to -# ncftp and then you're done. - -st -e ncftp $1 diff --git a/sh/indicate b/sh/indicate deleted file mode 100755 index 31c30e3..0000000 --- a/sh/indicate +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -i=$(date '+%H:%M:%S %m/%d (%h)') -j=$(bat) -k=$(vol) -printf "%s | %s | %s\n" "$i" "$j" "$k" | nenu diff --git a/sh/josm_launch b/sh/josm_launch deleted file mode 100755 index c333857..0000000 --- a/sh/josm_launch +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -wmname LG3D -export _JAVA_AWT_WM_NONREPARENTING=1 - -josm diff --git a/sh/pashmenu b/sh/pashmenu deleted file mode 100755 index f6a1ce6..0000000 --- a/sh/pashmenu +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -# this is pashmenu. this program will only work if gpg's -# gui password dialog is enabled. i'm not why it's enabled, -# but it's required for this to work. - -choice=$(pash l | nenu) -pash c $choice diff --git a/sh/start b/sh/start deleted file mode 100755 index 48f86a5..0000000 --- a/sh/start +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -sudo connect c && sx diff --git a/sh/urlhandle b/sh/urlhandle deleted file mode 100755 index b8a3658..0000000 --- a/sh/urlhandle +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh - -# access gemini and gopher urls within vimb with vulpes proxy - -# yes, this will result in urls like -# 'proto://host.tld/page?q="://" becoming -# 'proto/host.tld/page?q="/" -stripped_url=`printf "%s" $1 | sed 's|://|/|g'` - -# use xdotool to type the correct commands into the vimb -# window, assuming that the window is currently focused (which -# happens most of the time) -xdotool key Escape -xdotool key Escape -xdotool type "ohttp://proxy.vulpes.one/${stripped_url}" -xdotool key Return - -exit 0 diff --git a/sh/xkcd b/sh/xkcd deleted file mode 100755 index dc8179c..0000000 --- a/sh/xkcd +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/sh - -[ -z $XKCD_DBG ] || set -x -err () { - printf "err: %s\n" ${1} - [ -z "${2}" ] && exit 1 - exit ${2} -} -getImageForComic() { - [ -z ${1} ] && a="" || a="$1/" - curl --silent https://xkcd.com/${a} | grep 'imgs.xkcd.com/comics/' | sed 1q | grep -o 'https://imgs\.xkcd\.com/comics/.*\....' -} -viewImage() { - a=$(mktemp) - curl --silent $(getImageForComic ${1}) -o $a - feh $a -} -proghelp() { - printf "\ -xkcd - view xkcd comics - -=> [v]iew [id] - View comic with id [id] -=> [g]et [id] - Get url for comic [id] -" -} -case $1 in - 'v'*) - viewImage $2 - exit 0 - ;; - 'g'*) - getImageForComic $2 - exit 0 - ;; - *) - proghelp - exit 0 - ;; -esac -exit 0 From 3751a7d12509fabfdf8bd396573ac978b996e90a Mon Sep 17 00:00:00 2001 From: randomuser Date: Wed, 8 Jun 2022 00:31:52 -0500 Subject: [PATCH 111/197] add exception for systems using networkmanager --- sh/connect | 58 +++++++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/sh/connect b/sh/connect index cc8084a..d0e721f 100755 --- a/sh/connect +++ b/sh/connect @@ -1,32 +1,36 @@ #!/bin/sh +[ "$(ps -aux | grep -c NetworkManager)" -eq 2 ] && \ + printf "NetworkManager is already running!" && \ + exit + case $1 in - "c"*) - wpa_supplicant -iwlp3s0 -c/etc/wpa_supplicant/wpa_supplicant.conf -B - dhcpcd wlp3s0 - tor & disown - ;; - "d"*) - killall -15 wpa_supplicant dhcpcd tor - ;; - "r"*) - sh $0 d - sh $0 c - ;; - "t"*) - [ $(ps aux | grep wpa_supplicant | wc -l) -eq 2 ] && sh $0 d && exit - sh $0 c - ;; - "l"*) - iw dev wlp3s0 scan | \ - grep 'SSID\|signal' | \ - grep -v '* SSID List' | \ - awk -F': ' '{print $2}' | \ - sed 'N;s/\n/ /' | \ - grep -v '\x00' - ;; - *) - printf "\ + "c"*) + wpa_supplicant -iwlp3s0 -c/etc/wpa_supplicant/wpa_supplicant.conf -B + dhcpcd wlp3s0 + tor & disown + ;; + "d"*) + killall -15 wpa_supplicant dhcpcd tor + ;; + "r"*) + sh $0 d + sh $0 c + ;; + "t"*) + [ $(ps aux | grep wpa_supplicant | wc -l) -eq 2 ] && sh $0 d && exit + sh $0 c + ;; + "l"*) + iw dev wlp3s0 scan | \ + grep 'SSID\|signal' | \ + grep -v '* SSID List' | \ + awk -F': ' '{print $2}' | \ + sed 'N;s/\n/ /' | \ + grep -v '\x00' + ;; + *) + printf "\ simple wrapper for connecting to a network ${0} toggle to toggle wifi connection ${0} restart to restart wifi @@ -34,6 +38,6 @@ ${0} disconnect to disconnect ${0} connect to connect to network ${0} list to list networks " - ;; + ;; esac exit 0 From d8febccf823e43cf4d24d9d57f37e9e89083ea2b Mon Sep 17 00:00:00 2001 From: randomuser Date: Mon, 13 Jun 2022 16:39:17 -0500 Subject: [PATCH 112/197] updates to Makefile, vim-swap-handler, disp, and nws --- Makefile | 1 + sh/disp | 32 +++++++-------- sh/nws | 98 ++++++++++++++++++++++----------------------- sh/vim-swap-handler | 28 +++++++++++++ 4 files changed, 94 insertions(+), 65 deletions(-) create mode 100755 sh/vim-swap-handler diff --git a/Makefile b/Makefile index 6aea880..663ac4d 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,7 @@ sh: cp -f sh/proxtest $(DESTDIR)$(PREFIX)/bin cp -f sh/pco $(DESTDIR)$(PREFIX)/bin cp -f sh/git-survey $(DESTDIR)$(PREFIX)/bin + cp -f sh/vim-swap-handler $(DESTDIR)$(PREFIX)/bin mkc: cc c/scream.c -o c/scream diff --git a/sh/disp b/sh/disp index 784a7fd..9222e02 100755 --- a/sh/disp +++ b/sh/disp @@ -1,29 +1,29 @@ #!/bin/sh exists() { - xrandr | grep ' connected' | grep "${1}" | wc -l + xrandr | grep ' connected' | grep "${1}" | wc -l } if [ $(exists "HDMI-2") -eq 1 ]; then - printf "one" - xrandr --output LVDS-1 --off --auto - xrandr --output VGA-1 --off --auto - bspc monitor -d I II III IV V VI VII VIII IX X - bspc monitor -g 1680x1050+0+0 - exit 0 + printf "one" + xrandr --output LVDS-1 --off --auto + xrandr --output VGA-1 --off --auto + bspc monitor -d I II III IV V VI VII VIII IX X + bspc monitor -g 1680x1050+0+0 + exit 0 fi if [ $(exists "LVDS-1") -eq 1 ]; then - bspc monitor -d I II III IV V VI VII VIII IX X - bspc monitor LVDS-1 -a I II III IV V VI VII VIII IX - exit 0 + bspc monitor -d I II III IV V VI VII VIII IX X + bspc monitor LVDS-1 -a I II III IV V VI VII VIII IX + exit 0 fi if [ $(exists "HDMI-2") -eq 1 ] && [ $(exists "LVDS-1") -eq 1 ]; then - printf "two" - xrandr --output HDMI-2 --above LVDS-1 --auto - xrandr --output VGA-1 --off --auto - bspc monitor LVDS-1 -a I III V VII IX - bspc monitor HDMI-2 -a II IV VI VIII - exit 0 + printf "two" + xrandr --output HDMI-2 --above LVDS-1 --auto + xrandr --output VGA-1 --off --auto + bspc monitor LVDS-1 -a I III V VII IX + bspc monitor HDMI-2 -a II IV VI VIII + exit 0 fi diff --git a/sh/nws b/sh/nws index e2e9531..b0f415e 100755 --- a/sh/nws +++ b/sh/nws @@ -28,74 +28,74 @@ Torify wrapper: export NWS_TORIFY= " } err () { - printf "err: %s\n" ${1} - [ -z "${2}" ] && exit 1 - exit ${2} + printf "err: %s\n" ${1} + [ -z "${2}" ] && exit 1 + exit ${2} } kstrip () { - printf %s "$1" | sed 's/^K\(.*\)/\1/' + printf %s "$1" | sed 's/^K\(.*\)/\1/' } national () { - mosaic CONUS-LARGE + mosaic CONUS-LARGE } # name interestingly to avoid keyword collision localradar () { - mosaic ${NWS_ZONE} + mosaic ${NWS_ZONE} } mosaic () { - ${NWS_GIF} "https://radar.weather.gov/ridge/lite/${1}_loop.gif" + ${NWS_GIF} "https://radar.weather.gov/ridge/lite/${1}_loop.gif" } setzone () { - printf "%s" "${1}" > ${NWS_CONFIG} + printf "%s" "${1}" > ${NWS_CONFIG} } river () { - textmessage "RVA" + textmessage "RVA" } weather () { - textmessage "ZFP" + textmessage "ZFP" } textmessage () { - curl --silent --fail "https://forecast.weather.gov/product.php?site=NWS&issuedby=$(kstrip ${NWS_ZONE})&product=${1}&format=TXT&version=1" | \ - sed -n '//,/<\/pre>/p' | \ - grep -v "a href" | \ - grep -v '' | \ - grep -v '<\/pre>' || \ - printf "${1} data not found for zone %s" ${NWS_ZONE} + curl --silent --fail "https://forecast.weather.gov/product.php?site=NWS&issuedby=$(kstrip ${NWS_ZONE})&product=${1}&format=TXT&version=1" | \ + sed -n '//,/<\/pre>/p' | \ + grep -v "a href" | \ + grep -v '' | \ + grep -v '<\/pre>' || \ + printf "${1} data not found for zone %s" ${NWS_ZONE} } case $1 in - "n"*) - national - exit 0 - ;; - "l"*) - localradar - exit 0 - ;; - "r"*) - river - exit 0 - ;; - "w"*) - weather - exit 0 - ;; - "m"*) - [ $# -eq 2 ] && mosaid $2 || \ - err "two args required" - ;; - "s"*) - [ $# -eq 2 ] && setzone $2 || \ - err "two args required" - exit 0 - ;; - "t"*) - [ $# -eq 2 ] && textmessage $2 || \ - err "two args required" - ;; - *) - info - exit 0 - ;; + "n"*) + national + exit 0 + ;; + "l"*) + localradar + exit 0 + ;; + "r"*) + river + exit 0 + ;; + "w"*) + weather + exit 0 + ;; + "m"*) + [ $# -eq 2 ] && mosaid $2 || \ + err "two args required" + ;; + "s"*) + [ $# -eq 2 ] && setzone $2 || \ + err "two args required" + exit 0 + ;; + "t"*) + [ $# -eq 2 ] && textmessage $2 || \ + err "two args required" + ;; + *) + info + exit 0 + ;; esac exit 0 diff --git a/sh/vim-swap-handler b/sh/vim-swap-handler new file mode 100755 index 0000000..bf39d6c --- /dev/null +++ b/sh/vim-swap-handler @@ -0,0 +1,28 @@ +#!/bin/sh +# when the vim SwapExists autocommand is fired, this script is +# called with the path of the file in question. + +# mad props to daniel conway for having this big brain idea + +# note to self: protect $1 from expansion as it can contain a +# ~ + +[ "$#" -eq 0 ] && exit 2 + +window=$( + xdotool search --name "$1" | \ + sed 1q +) + +desk=$( + xdotool get_desktop_for_window "$window" 2>/dev/null || printf "none" +) + +[ "$desk" = "none" ] && exit 1 +desk=$(($desk + 1)) + +bspc desktop -f "^${desk}" +killall -10 simplestatus +xdotool set_window --urgency 1 "$window" + +exit 0 From ca75e5bb7938dddc6bd76234074c1b97977cde6f Mon Sep 17 00:00:00 2001 From: randomuser Date: Sat, 18 Jun 2022 15:28:59 -0500 Subject: [PATCH 113/197] status command --- Makefile | 1 + sh/status | 5 +++++ 2 files changed, 6 insertions(+) create mode 100755 sh/status diff --git a/Makefile b/Makefile index 663ac4d..57ce6c5 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,7 @@ sh: cp -f sh/pco $(DESTDIR)$(PREFIX)/bin cp -f sh/git-survey $(DESTDIR)$(PREFIX)/bin cp -f sh/vim-swap-handler $(DESTDIR)$(PREFIX)/bin + cp -f sh/status $(DESTDIR)$(PREFIX)/bin mkc: cc c/scream.c -o c/scream diff --git a/sh/status b/sh/status new file mode 100755 index 0000000..95b4ad1 --- /dev/null +++ b/sh/status @@ -0,0 +1,5 @@ +#!/bin/sh + +[ "$(ps aux | grep simplestatus | wc -l)" -eq 2 ] && killall simplestatus && killall lemonbar + +simplestatus | lemonbar -f 'Fantasque Sans Mono' -B "#161510" -F "#4c4635" From 55cb90505a6361e08f6d2c2a39368fea997d8385 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sat, 18 Jun 2022 16:34:35 -0500 Subject: [PATCH 114/197] modify volume script --- sh/vol | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/sh/vol b/sh/vol index 8da8183..fe2a790 100755 --- a/sh/vol +++ b/sh/vol @@ -1,3 +1,19 @@ #!/bin/sh -amixer sset Master 0%+ | tail -1 | awk -F'[' '{print $2}' | awk -F']' '{print $1}' +pulse=$(ps aux | grep pulseaudio | wc -l) + +[ "$1" = "inc" ] && sign="+" +[ "$1" = "dec" ] && sign="-" + +[ "$#" -eq 0 ] && exit 1 + +if [ "$pulse" -eq 2 ]; then + for SINK in `pacmd list-sinks | grep 'index:' | cut -b12-` + do + pactl set-sink-volume $SINK "${sign}5%" + done +else + amixer -c 0 set Master "5%${sign}" +fi + +killall -12 simplestatus From da50b8b12e18ca2c916ad342b41e69ca01e4f7f3 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sat, 18 Jun 2022 16:34:48 -0500 Subject: [PATCH 115/197] status fixes --- sh/status | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sh/status b/sh/status index 95b4ad1..77002c2 100755 --- a/sh/status +++ b/sh/status @@ -1,5 +1,5 @@ #!/bin/sh -[ "$(ps aux | grep simplestatus | wc -l)" -eq 2 ] && killall simplestatus && killall lemonbar +[ "$(ps aux | grep simplestatus | wc -l)" -eq 2 ] && killall simplestatus -simplestatus | lemonbar -f 'Fantasque Sans Mono' -B "#161510" -F "#4c4635" +simplestatus | lemonbar -f 'Fantasque Sans Mono' -B "#161510" -F "#4c4635" & From fe7c6e415f1ba5426beab6e7c1d357d1d859a2db Mon Sep 17 00:00:00 2001 From: randomuser Date: Sat, 18 Jun 2022 21:42:39 -0500 Subject: [PATCH 116/197] snownews-url-handler --- Makefile | 1 + sh/snownews-url-handler | 6 ++++++ 2 files changed, 7 insertions(+) create mode 100644 sh/snownews-url-handler diff --git a/Makefile b/Makefile index 57ce6c5..7168e46 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,7 @@ sh: cp -f sh/pco $(DESTDIR)$(PREFIX)/bin cp -f sh/git-survey $(DESTDIR)$(PREFIX)/bin cp -f sh/vim-swap-handler $(DESTDIR)$(PREFIX)/bin + cp -f sh/snownews-url-handler $(DESTDIR)$(PREFIX)/bin cp -f sh/status $(DESTDIR)$(PREFIX)/bin mkc: diff --git a/sh/snownews-url-handler b/sh/snownews-url-handler new file mode 100644 index 0000000..9053b84 --- /dev/null +++ b/sh/snownews-url-handler @@ -0,0 +1,6 @@ +#!/bin/sh + +tube="$(printf "%s\n" "$1" | grep "watch?v=" | wc -l)" +[ "$tube" -eq 1 ] && mpv "$1" && exit + +firefox -P $1 From d46bd12143eaa10b0468a6942ecd7badd89bd476 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sat, 18 Jun 2022 21:45:19 -0500 Subject: [PATCH 117/197] chmod +x snownews-url-handler --- sh/snownews-url-handler | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 sh/snownews-url-handler diff --git a/sh/snownews-url-handler b/sh/snownews-url-handler old mode 100644 new mode 100755 From 1be248b5ad4039c504c1979cfaf1176c67974755 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sat, 18 Jun 2022 21:50:35 -0500 Subject: [PATCH 118/197] it's 950 and i need to go to bed --- sh/snownews-url-handler | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sh/snownews-url-handler b/sh/snownews-url-handler index 9053b84..30dd2bc 100755 --- a/sh/snownews-url-handler +++ b/sh/snownews-url-handler @@ -3,4 +3,4 @@ tube="$(printf "%s\n" "$1" | grep "watch?v=" | wc -l)" [ "$tube" -eq 1 ] && mpv "$1" && exit -firefox -P $1 +firefox $1 From 837439c33c83a5f0fe28f342bab7e2bb15f9b410 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sat, 18 Jun 2022 22:28:58 -0500 Subject: [PATCH 119/197] aaaaaaaaa --- sh/snownews-url-handler | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sh/snownews-url-handler b/sh/snownews-url-handler index 30dd2bc..475c3e5 100755 --- a/sh/snownews-url-handler +++ b/sh/snownews-url-handler @@ -1,6 +1,9 @@ #!/bin/sh +printf "%s\n" "$1" >> /home/usr/aaaaaaaa + tube="$(printf "%s\n" "$1" | grep "watch?v=" | wc -l)" [ "$tube" -eq 1 ] && mpv "$1" && exit firefox $1 +killall -10 simplestatus From f190a3318a608a4a539163ec269943f14277470a Mon Sep 17 00:00:00 2001 From: randomuser Date: Sat, 18 Jun 2022 22:48:06 -0500 Subject: [PATCH 120/197] AAAAAAAAAAAAAAAAA --- sh/snownews-url-handler | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sh/snownews-url-handler b/sh/snownews-url-handler index 475c3e5..50bcff7 100755 --- a/sh/snownews-url-handler +++ b/sh/snownews-url-handler @@ -1,9 +1,7 @@ #!/bin/sh -printf "%s\n" "$1" >> /home/usr/aaaaaaaa - -tube="$(printf "%s\n" "$1" | grep "watch?v=" | wc -l)" -[ "$tube" -eq 1 ] && mpv "$1" && exit +# tube="$(printf "%s\n" "$1" | grep "watch?v=" | wc -l)" +# [ "$tube" -eq 1 ] && mpv -v --video-sync=display-resample "$1" && exit firefox $1 killall -10 simplestatus From f56c6214de2f18b483f86b33d077b63d2493600e Mon Sep 17 00:00:00 2001 From: randomuser Date: Wed, 22 Jun 2022 17:04:59 -0500 Subject: [PATCH 121/197] add new prog; some modifications --- c/colors.c | 184 +++++++++++++++++++++++++++++++++++++++++++++++ c/simplestatus.c | 11 +-- 2 files changed, 191 insertions(+), 4 deletions(-) create mode 100644 c/colors.c diff --git a/c/colors.c b/c/colors.c new file mode 100644 index 0000000..b48ba25 --- /dev/null +++ b/c/colors.c @@ -0,0 +1,184 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct color { + int r; + int g; + int b; +}; + +void exec_with_stdout(char *file, char *args[], char *buf, int length) { + int pfds[2]; + pipe(pfds); + int status = fork(); + + if(status == 0) { + close(1); + dup(pfds[1]); + close(pfds[0]); + + execvp(file, args); + } else { + if(!buf) return; /* don't read anything */ + int readin = read(pfds[0], buf, length - 1); + buf[readin] = '\0'; + } +} + +void imagemagick(char *filename, char *buffer, int size) { + char *execargs[] = { + "convert", + filename, + "-resize", + "25%", + "-colors", + "16", + "-unique-colors", + "-quiet", + "txt:-", + NULL + }; + char *name = "convert"; + + exec_with_stdout(name, execargs, buffer, size); +} + +struct color *get_raw_colors(char *image) { + char buf[2048]; + + imagemagick(image, (char *)&buf, 2048); + int hcount = 0; + char cbuf[3][3]; + static struct color colors[16]; + + for(int i = 0; (unsigned int)i < sizeof buf; i++) { + if(buf[i] == '#') { + hcount++; /* we have to ignore a comment, that's why there's a special case */ + if(hcount >= 2 && hcount - 2 < 16 && (unsigned int)(i + 6) < sizeof buf) { + memcpy((char *)&cbuf[0], buf + i + 1, 2); + memcpy((char *)&cbuf[1], buf + i + 3, 2); + memcpy((char *)&cbuf[2], buf + i + 5, 2); + cbuf[0][2] = '\0'; + cbuf[1][2] = '\0'; + cbuf[2][2] = '\0'; + colors[hcount - 2].r = (int)strtol((char *)&cbuf[0], NULL, 16); + colors[hcount - 2].g = (int)strtol((char *)&cbuf[1], NULL, 16); + colors[hcount - 2].b = (int)strtol((char *)&cbuf[2], NULL, 16); + } + } + } + + return (struct color *)&colors; +} + +void blend_color(struct color *a, struct color *b, struct color *c) { + c->r = (int)(0.5 * a->r + 0.5 * b->r); + c->g = (int)(0.5 * a->g + 0.5 * b->g); + c->b = (int)(0.5 * a->b + 0.5 * b->b); +} + +void darken_color(struct color *a, struct color *b, double percentage) { + b->r = (int)(a->r * (1 - percentage)); + b->g = (int)(a->g * (1 - percentage)); + b->b = (int)(a->b * (1 - percentage)); +} + +void adjust_colors(struct color *colors) { + /* #eeeeee */ + struct color e = {238, 238, 238}; + + /* if top digit != 0 */ + if(colors[0].r > 15) + darken_color(&colors[0], &colors[0], 0.40); + + blend_color(&colors[7], &e, &colors[7]); + darken_color(&colors[7], &colors[8], 0.30); + blend_color(&colors[15], &e, &colors[15]); +} + +struct color *get_colors(char *filename) { + /* check for permission */ + if(access(filename, F_OK | R_OK) != 0) { + errno = ENOENT; + return NULL; + } + + struct color *col = get_raw_colors(filename); + adjust_colors(col); + + return col; +} + +char *get_conf_file(char *file) { + static char buffer[128]; + int extension = 0; + char *path = getenv("XDG_CONFIG_HOME"); + if(!path) { + path = getenv("HOME"); + extension = 1; + } + if(!path) { + printf("do you have a $HOME?\n"); + exit(1); + } + + snprintf(buffer, 128, "%s%s/%s", path, extension ? "/.config/cwal" : "", file); + return buffer; +} + +void print_color(struct color *color) { + printf("#%x%x%x\n", color->r, color->g, color->b); +} + +void run_handler(struct color *colors) { + char chars[16][8]; + char *argv[18]; + + for(int i = 0; i < 16; i++) { + snprintf(&chars[i], 8, "#%x%x%x", colors[i].r, colors[i].g, colors[i].b); + } + for(int i = 0; i < 16; i++) { + argv[i + 1] = &chars[i]; + } + argv[17] = NULL; + + printf("envp[0] = %s\n", argv[1]); + char *conf = get_conf_file("handler"); + argv[0] = "handler"; + + if(access(conf, F_OK | R_OK | X_OK) != 0) { + printf("couldn't find %s!\n", conf); + return; + } + + exec_with_stdout(conf, argv, NULL, 0); +} + +struct settings { + int h:1; /* running hooks or not */ + int r:1; /* pick a random wallpaper */ +} settings = { + .h = 1, + .r = 1, +}; + +int main(void) { + struct color *colors = get_colors("/home/usr/.local/share/wallpapers/forest-steps.jpg"); + + for(int i = 0; i < 16; i++) { + print_color(&colors[i]); + } + + run_handler(colors); + + get_conf_file("hello"); + + return 0; +} diff --git a/c/simplestatus.c b/c/simplestatus.c index 9866bd8..dadc4fb 100644 --- a/c/simplestatus.c +++ b/c/simplestatus.c @@ -167,6 +167,7 @@ module *parse_file(char *file) { module *current = NULL, *head = NULL; int linenumber = 0; while((cline = read_line(fp)) != NULL) { + printf("debug: %s\n", cline); linenumber++; /* free the string up here */ if(strlen(cline) == 0) { @@ -178,8 +179,10 @@ module *parse_file(char *file) { continue; } - char *command = strdup(strtok(cline, " ")); - if(!memcmp(command, module_text, sizeof module_text)) { + char *res = strtok(cline, " "); + if(!res) printf("strtok returned NULL!\n"); + + if(!memcmp(res, module_text, sizeof module_text)) { if(current == NULL) { current = malloc(sizeof *current); head = current; @@ -216,7 +219,7 @@ module *parse_file(char *file) { free(cline); continue; - } else if(!memcmp(command, order_text, sizeof order_text)) { + } else if(!memcmp(res, order_text, sizeof order_text)) { if(mcache) { fprintf(stderr, "syntax error at line %i: you can't issue the order command twice\n", linenumber); return NULL; @@ -236,7 +239,7 @@ module *parse_file(char *file) { ptr->data = NULL; ptr->next = NULL; } - } else if(!memcmp(command, format_text, sizeof format_text)) { + } else if(!memcmp(res, format_text, sizeof format_text)) { char *pattern = cline + sizeof format_text; format_string = strdup(pattern); } From cba178e2a36ea1690a0f369a9ce004a6298fbf37 Mon Sep 17 00:00:00 2001 From: randomuser Date: Wed, 22 Jun 2022 17:06:24 -0500 Subject: [PATCH 122/197] todo list --- TODO | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 TODO diff --git a/TODO b/TODO new file mode 100644 index 0000000..9fa70a6 --- /dev/null +++ b/TODO @@ -0,0 +1,5 @@ +TODO LIST +--------- + +- change statusbar program so it uses static allocations instead of dynamic ones +- make the c programs less buggy and let them not suck as much From 34c0c6988d162fe7ad1c6bb9a34072b81f1f50f1 Mon Sep 17 00:00:00 2001 From: randomuser Date: Fri, 24 Jun 2022 02:23:34 -0500 Subject: [PATCH 123/197] some improvments and added features, needs polishing --- c/colors.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 73 insertions(+), 12 deletions(-) diff --git a/c/colors.c b/c/colors.c index b48ba25..12c2856 100644 --- a/c/colors.c +++ b/c/colors.c @@ -1,6 +1,8 @@ #include #include +#include #include +#include #include #include #include @@ -14,6 +16,14 @@ struct color { int b; }; +void init_random(void) { + srand(time(0)); +} + +int rand_range(int u, int l) { + return (rand() % (u - l + 1)) + l; +} + void exec_with_stdout(char *file, char *args[], char *buf, int length) { int pfds[2]; pipe(pfds); @@ -103,6 +113,15 @@ void adjust_colors(struct color *colors) { blend_color(&colors[15], &e, &colors[15]); } +int check_colors(struct color *colors) { + int j = 0; + for(int i = 0; i < 16; i++) { + if(colors[i].r == colors[i].g == colors[i].b) j++; + } + if(j > 0) return 0; + return 1; +} + struct color *get_colors(char *filename) { /* check for permission */ if(access(filename, F_OK | R_OK) != 0) { @@ -116,33 +135,70 @@ struct color *get_colors(char *filename) { return col; } -char *get_conf_file(char *file) { - static char buffer[128]; +/* generalized function , + * used by get_conf_file and get_wal_dir */ +char *get_file_gen(char *initvar, char *backvar, char *postfix, char *file) { + printf("%s %s %s %s\n", initvar, backvar, postfix, file); + static char buffer[256]; int extension = 0; - char *path = getenv("XDG_CONFIG_HOME"); + char *path = getenv(initvar); if(!path) { - path = getenv("HOME"); + path = getenv(backvar); extension = 1; } if(!path) { - printf("do you have a $HOME?\n"); + fprintf(stderr, "error: both initvar and backvar are undefined.\n"); exit(1); } - snprintf(buffer, 128, "%s%s/%s", path, extension ? "/.config/cwal" : "", file); + snprintf(buffer, 256, "%s%s/%s", path, extension ? postfix : "", file); return buffer; } -void print_color(struct color *color) { - printf("#%x%x%x\n", color->r, color->g, color->b); +char *get_conf_file(char *file) { + return get_file_gen("XDG_CONFIG_HOME", "HOME", "/.config/cwal", file); } -void run_handler(struct color *colors) { +/* pass NULL to get the base dir name, not specific file */ +char *get_wal_dir(char *file) { + if(!file) file = ""; + + return get_file_gen("XDG_DATA_HOME", "HOME", "/.local/share/wallpapers", file); +} + +char *select_random(void) { + printf("%s\n", get_wal_dir(NULL)); + DIR *dir = opendir(get_wal_dir(NULL)); + struct dirent *file; + /* probably should move hardcoded constants somewhere that makes sense */ + static char names[50][256]; + int i = 0, random; + + init_random(); + + while(file = readdir(dir)) { + if(i == 50) break; + if(file->d_type != DT_REG) continue; + + memcpy(&names[i], file->d_name, 256); + i++; + } + + random = rand_range(i - 1, 0); + + return names[random]; +} + +void print_color(struct color *color) { + printf("#%02x%02x%02x\n", color->r, color->g, color->b); +} + +void run_handler(struct color *colors, char *wal) { char chars[16][8]; char *argv[18]; for(int i = 0; i < 16; i++) { - snprintf(&chars[i], 8, "#%x%x%x", colors[i].r, colors[i].g, colors[i].b); + snprintf(&chars[i], 8, "#%02x%02x%02x", colors[i].r, colors[i].g, colors[i].b); } for(int i = 0; i < 16; i++) { argv[i + 1] = &chars[i]; @@ -170,13 +226,18 @@ struct settings { }; int main(void) { - struct color *colors = get_colors("/home/usr/.local/share/wallpapers/forest-steps.jpg"); + char *file = select_random(); + printf("%s\n", file); + file = get_wal_dir(file); + printf("%s\n", file); + struct color *colors = get_colors(file); + printf("%i\n", check_colors(colors)); for(int i = 0; i < 16; i++) { print_color(&colors[i]); } - run_handler(colors); + run_handler(colors, file); get_conf_file("hello"); From cacfd2e2444d2c8601a4ac656ae9dbafaae3c6c2 Mon Sep 17 00:00:00 2001 From: randomuser Date: Fri, 24 Jun 2022 02:57:34 -0500 Subject: [PATCH 124/197] some changes, still needs polish --- c/colors.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/c/colors.c b/c/colors.c index 12c2856..0b08b7e 100644 --- a/c/colors.c +++ b/c/colors.c @@ -116,7 +116,7 @@ void adjust_colors(struct color *colors) { int check_colors(struct color *colors) { int j = 0; for(int i = 0; i < 16; i++) { - if(colors[i].r == colors[i].g == colors[i].b) j++; + if(colors[i].r + colors[i].g + colors[i].b == 0) j++; } if(j > 0) return 0; return 1; @@ -138,7 +138,6 @@ struct color *get_colors(char *filename) { /* generalized function , * used by get_conf_file and get_wal_dir */ char *get_file_gen(char *initvar, char *backvar, char *postfix, char *file) { - printf("%s %s %s %s\n", initvar, backvar, postfix, file); static char buffer[256]; int extension = 0; char *path = getenv(initvar); @@ -166,8 +165,7 @@ char *get_wal_dir(char *file) { return get_file_gen("XDG_DATA_HOME", "HOME", "/.local/share/wallpapers", file); } -char *select_random(void) { - printf("%s\n", get_wal_dir(NULL)); +char *select_random_rel(void) { DIR *dir = opendir(get_wal_dir(NULL)); struct dirent *file; /* probably should move hardcoded constants somewhere that makes sense */ @@ -195,7 +193,7 @@ void print_color(struct color *color) { void run_handler(struct color *colors, char *wal) { char chars[16][8]; - char *argv[18]; + char *argv[19]; for(int i = 0; i < 16; i++) { snprintf(&chars[i], 8, "#%02x%02x%02x", colors[i].r, colors[i].g, colors[i].b); @@ -203,9 +201,9 @@ void run_handler(struct color *colors, char *wal) { for(int i = 0; i < 16; i++) { argv[i + 1] = &chars[i]; } - argv[17] = NULL; + argv[17] = wal; + argv[18] = NULL; - printf("envp[0] = %s\n", argv[1]); char *conf = get_conf_file("handler"); argv[0] = "handler"; @@ -225,11 +223,17 @@ struct settings { .r = 1, }; -int main(void) { - char *file = select_random(); - printf("%s\n", file); +char *select_random_file(void) { + char *file = select_random_rel(); + static char ret[256]; file = get_wal_dir(file); - printf("%s\n", file); + memcpy(&ret, file, 256); + + return ret; +} + +int main(void) { + char *file = select_random_file(); struct color *colors = get_colors(file); printf("%i\n", check_colors(colors)); From 873f62cfd1a65f06f39d1fd288f86a09046944e5 Mon Sep 17 00:00:00 2001 From: randomuser Date: Fri, 24 Jun 2022 17:02:38 -0500 Subject: [PATCH 125/197] add argument interface --- c/colors.c | 63 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 13 deletions(-) diff --git a/c/colors.c b/c/colors.c index 0b08b7e..3c6ea86 100644 --- a/c/colors.c +++ b/c/colors.c @@ -217,14 +217,20 @@ void run_handler(struct color *colors, char *wal) { struct settings { int h:1; /* running hooks or not */ - int r:1; /* pick a random wallpaper */ + int e:1; /* echo colors */ + int c:1; /* enable color check */ + int f:1; /* print filename used */ + char *wal; /* custom file if provided */ } settings = { .h = 1, - .r = 1, + .e = 0, + .c = 0, + .f = 0, + .wal = NULL, }; -char *select_random_file(void) { - char *file = select_random_rel(); +char *select_random_file(char *file) { + if(!file) file = select_random_rel(); static char ret[256]; file = get_wal_dir(file); memcpy(&ret, file, 256); @@ -232,18 +238,49 @@ char *select_random_file(void) { return ret; } -int main(void) { - char *file = select_random_file(); - struct color *colors = get_colors(file); - printf("%i\n", check_colors(colors)); - - for(int i = 0; i < 16; i++) { - print_color(&colors[i]); +int main(int argc, char **argv) { + int c; + while((c = getopt(argc, argv, "hefcw:")) != -1) { + switch(c) { + case 'h': + settings.h = 0; + break; + case 'w': + settings.wal = optarg; + break; + case 'e': + settings.e = 1; + break; + case 'c': + settings.c = 1; + break; + case 'f': + settings.f = 1; + break; + } } - run_handler(colors, file); + if(settings.h == 0) settings.e = 1; - get_conf_file("hello"); + char *file = select_random_file(settings.wal); + struct color *colors = get_colors(file); + + if(settings.f) printf("%s\n", file); + + if(settings.e) { + for(int i = 0; i < 16; i++) { + print_color(&colors[i]); + } + } + + if(settings.c) { + c = check_colors(colors); + if(c == 0) { + return 2; + } + } + + if(settings.h) run_handler(colors, file); return 0; } From 0458d16a1820d5165eb9a0ac2215c3052d682b56 Mon Sep 17 00:00:00 2001 From: randomuser Date: Fri, 24 Jun 2022 17:15:39 -0500 Subject: [PATCH 126/197] add small scream fix --- c/scream.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/c/scream.c b/c/scream.c index 981f687..fe00aa7 100644 --- a/c/scream.c +++ b/c/scream.c @@ -13,8 +13,7 @@ char newchar(char c, int i) { } int main(void) { char c; - int i; - i = 0; + int i = 0; while((c = getchar()) != EOF) { putchar(newchar(c, i)); i++; From eb2bbf704a884da1261dd72ed9df08e41e8c1dfd Mon Sep 17 00:00:00 2001 From: randomuser Date: Sat, 25 Jun 2022 23:30:58 -0500 Subject: [PATCH 127/197] cfg --- Makefile | 1 + sh/cfg | 6 ++++++ 2 files changed, 7 insertions(+) create mode 100755 sh/cfg diff --git a/Makefile b/Makefile index 7168e46..c3860dc 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,7 @@ sh: cp -f sh/vim-swap-handler $(DESTDIR)$(PREFIX)/bin cp -f sh/snownews-url-handler $(DESTDIR)$(PREFIX)/bin cp -f sh/status $(DESTDIR)$(PREFIX)/bin + cp -f sh/cfg $(DESTDIR)$(PREFIX)/bin mkc: cc c/scream.c -o c/scream diff --git a/sh/cfg b/sh/cfg new file mode 100755 index 0000000..58892df --- /dev/null +++ b/sh/cfg @@ -0,0 +1,6 @@ +#!/bin/sh + +sel="$(find -L ~/.config 2>/dev/null | fzy)" +[ "$?" -eq 1 ] && exit 1 + +nvim "$sel" From cc94ad678025047c8f3ed1044a38120fd6e40502 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sat, 25 Jun 2022 23:37:39 -0500 Subject: [PATCH 128/197] update makefile --- .gitignore | 1 + Makefile | 3 +++ 2 files changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 13019a4..f536d82 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ c/boid c/a.out c/anaconda c/simplestatus +c/colors diff --git a/Makefile b/Makefile index c3860dc..c4b1696 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,7 @@ man: # this did not work on my computer, but might be needed on other installations mkdir -p /usr/local/man/man1 cp -f man/* /usr/local/man/man1 + sh: mkdir -p $(DESTDIR)$(PREFIX)/bin cp -f sh/paste $(DESTDIR)$(PREFIX)/bin @@ -30,6 +31,7 @@ mkc: cc c/boid.c -o c/boid -lm -lX11 cc c/anaconda.c -o c/anaconda -lm -lX11 cc c/simplestatus.c -o c/simplestatus + cc c/colors.c -o c/colors c: cp -f c/scream $(DESTDIR)$(PREFIX)/bin @@ -37,6 +39,7 @@ c: cp -f c/boid $(DESTDIR)$(PREFIX)/bin cp -f c/anaconda $(DESTDIR)$(PREFIX)/bin cp -f c/simplestatus $(DESTDIR)$(PREFIX)/bin + cp -f c/colors $(DESTDIR)$(PREFIX)/bin clean: rm c/scream From 4509ac1b12898d8062d2909931c9499559cfc796 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sat, 25 Jun 2022 23:45:59 -0500 Subject: [PATCH 129/197] make makefile not suck --- Makefile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index c4b1696..e624995 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ all: mkc -install: man sh mkc c +install: man sh c all .PHONY: man sh mkc c man: @@ -25,13 +25,13 @@ sh: cp -f sh/status $(DESTDIR)$(PREFIX)/bin cp -f sh/cfg $(DESTDIR)$(PREFIX)/bin -mkc: - cc c/scream.c -o c/scream - cc c/timer.c -o c/timer +mkc: c/scream c/timer c/boid c/anaconda c/simplestatus c/colors + +c/boid: cc c/boid.c -o c/boid -lm -lX11 + +c/anaconda: cc c/anaconda.c -o c/anaconda -lm -lX11 - cc c/simplestatus.c -o c/simplestatus - cc c/colors.c -o c/colors c: cp -f c/scream $(DESTDIR)$(PREFIX)/bin From 1aa26fc6d331497fbe0d5edea8b47393524242fb Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 26 Jun 2022 00:09:58 -0500 Subject: [PATCH 130/197] add repos --- Makefile | 1 + sh/repos | 6 ++++++ 2 files changed, 7 insertions(+) create mode 100755 sh/repos diff --git a/Makefile b/Makefile index e624995..507e47f 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,7 @@ sh: cp -f sh/snownews-url-handler $(DESTDIR)$(PREFIX)/bin cp -f sh/status $(DESTDIR)$(PREFIX)/bin cp -f sh/cfg $(DESTDIR)$(PREFIX)/bin + cp -f sh/repos $(DESTDIR)$(PREFIX)/bin mkc: c/scream c/timer c/boid c/anaconda c/simplestatus c/colors diff --git a/sh/repos b/sh/repos new file mode 100755 index 0000000..6b5bad0 --- /dev/null +++ b/sh/repos @@ -0,0 +1,6 @@ +#!/bin/sh + +sel="$(ls ~/git | fzy)" +[ "$?" -eq 1 ] && exit 1 + +nvim ~/git/"$sel" From 4747fbc23786ef1ae80d97803e329121e394e893 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 26 Jun 2022 01:24:05 -0500 Subject: [PATCH 131/197] add manpage and adjust exitcode --- c/colors.c | 2 +- man/colors.1 | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 man/colors.1 diff --git a/c/colors.c b/c/colors.c index 3c6ea86..b6f52b5 100644 --- a/c/colors.c +++ b/c/colors.c @@ -276,7 +276,7 @@ int main(int argc, char **argv) { if(settings.c) { c = check_colors(colors); if(c == 0) { - return 2; + return 1; } } diff --git a/man/colors.1 b/man/colors.1 new file mode 100644 index 0000000..e25818a --- /dev/null +++ b/man/colors.1 @@ -0,0 +1,32 @@ +.TH COLORS 1 colors +.SH NAME +colors \- generate colorscheme and run hooks +.SH SYNOPSIS +.B colors [-hefc] [-w path] +.SH OPTIONS +.TP +.B -h +disable running hooks (implies -e) +.TP +.B -e +echo colors to stdout +.TP +.B -c +check colors using color checking algorithm +.TP +.B -f +print wallpaper filename to stdout +.TP +.B -w +provide wallpaper path +.SH HOOKS +When -h is not used, a program at ~/.config/cwal/handler is executed. The first sixteen arguments are the colors in the colorscheme, and the seventeenth argument is the filename. +.SH EXIT CODES +.TP +.B 0 +Normal exit code +.TP +.B 1 +check_colors(...) failed. +.SH AUTHOR +randomuser From 8a77baba44e8129e2c1346def58a6f3816bc63bf Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 26 Jun 2022 18:59:05 -0500 Subject: [PATCH 132/197] add firefox wrapper --- Makefile | 1 + sh/fire | 3 +++ 2 files changed, 4 insertions(+) create mode 100755 sh/fire diff --git a/Makefile b/Makefile index 507e47f..c250fe7 100644 --- a/Makefile +++ b/Makefile @@ -25,6 +25,7 @@ sh: cp -f sh/status $(DESTDIR)$(PREFIX)/bin cp -f sh/cfg $(DESTDIR)$(PREFIX)/bin cp -f sh/repos $(DESTDIR)$(PREFIX)/bin + cp -f sh/fire $(DESTDIR)$(PREFIX)/bin mkc: c/scream c/timer c/boid c/anaconda c/simplestatus c/colors diff --git a/sh/fire b/sh/fire new file mode 100755 index 0000000..60903bf --- /dev/null +++ b/sh/fire @@ -0,0 +1,3 @@ +#!/bin/sh + +HOME="/home/usr/.local/share/firefox" firefox $@ From 78faf3f35464dd54f4949bfc8734b3ab5a4c5165 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 26 Jun 2022 18:59:53 -0500 Subject: [PATCH 133/197] remove repos --- Makefile | 1 - sh/repos | 6 ------ 2 files changed, 7 deletions(-) delete mode 100755 sh/repos diff --git a/Makefile b/Makefile index c250fe7..ca545ac 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,6 @@ sh: cp -f sh/snownews-url-handler $(DESTDIR)$(PREFIX)/bin cp -f sh/status $(DESTDIR)$(PREFIX)/bin cp -f sh/cfg $(DESTDIR)$(PREFIX)/bin - cp -f sh/repos $(DESTDIR)$(PREFIX)/bin cp -f sh/fire $(DESTDIR)$(PREFIX)/bin mkc: c/scream c/timer c/boid c/anaconda c/simplestatus c/colors diff --git a/sh/repos b/sh/repos deleted file mode 100755 index 6b5bad0..0000000 --- a/sh/repos +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -sel="$(ls ~/git | fzy)" -[ "$?" -eq 1 ] && exit 1 - -nvim ~/git/"$sel" From 4a6e2551715fea47ebb6dc7cd4e4eefdaca907e5 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 26 Jun 2022 19:55:51 -0500 Subject: [PATCH 134/197] pash-dmenu --- Makefile | 1 + sh/pash-dmenu | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100755 sh/pash-dmenu diff --git a/Makefile b/Makefile index ca545ac..5062b62 100644 --- a/Makefile +++ b/Makefile @@ -25,6 +25,7 @@ sh: cp -f sh/status $(DESTDIR)$(PREFIX)/bin cp -f sh/cfg $(DESTDIR)$(PREFIX)/bin cp -f sh/fire $(DESTDIR)$(PREFIX)/bin + cp -f sh/pash-dmenu $(DESTDIR)$(PREFIX)/bin mkc: c/scream c/timer c/boid c/anaconda c/simplestatus c/colors diff --git a/sh/pash-dmenu b/sh/pash-dmenu new file mode 100755 index 0000000..26101e7 --- /dev/null +++ b/sh/pash-dmenu @@ -0,0 +1,7 @@ +#!/bin/sh + +sel="$(pash l | dmenu)" +[ "$?" -eq 1 ] && exit 0 + +# requires bspc rule -a st-gpg-menu state=floating +st -c st-gpg-menu -e pash c "$sel" From ca434c3e7a1fa10445745518ff7a92fbc78ab218 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 26 Jun 2022 20:24:41 -0500 Subject: [PATCH 135/197] improve pash-dmenu --- Makefile | 1 + sh/pash-dmenu | 2 +- sh/pash-dmenu-backend | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100755 sh/pash-dmenu-backend diff --git a/Makefile b/Makefile index 5062b62..fe7308e 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,7 @@ sh: cp -f sh/cfg $(DESTDIR)$(PREFIX)/bin cp -f sh/fire $(DESTDIR)$(PREFIX)/bin cp -f sh/pash-dmenu $(DESTDIR)$(PREFIX)/bin + cp -f sh/pash-dmenu-backend $(DESTDIR)$(PREFIX)/bin mkc: c/scream c/timer c/boid c/anaconda c/simplestatus c/colors diff --git a/sh/pash-dmenu b/sh/pash-dmenu index 26101e7..0499dcf 100755 --- a/sh/pash-dmenu +++ b/sh/pash-dmenu @@ -4,4 +4,4 @@ sel="$(pash l | dmenu)" [ "$?" -eq 1 ] && exit 0 # requires bspc rule -a st-gpg-menu state=floating -st -c st-gpg-menu -e pash c "$sel" +st -c st-gpg-menu -e pash-dmenu-backend $sel diff --git a/sh/pash-dmenu-backend b/sh/pash-dmenu-backend new file mode 100755 index 0000000..ab70c4f --- /dev/null +++ b/sh/pash-dmenu-backend @@ -0,0 +1,5 @@ +#!/bin/sh + +pash c "$1" +bspc node -d '^9' +sleep 15 From 779a510f9c10a6149cae0e70319c6fa9343c804d Mon Sep 17 00:00:00 2001 From: randomuser Date: Mon, 4 Jul 2022 02:00:59 -0500 Subject: [PATCH 136/197] transition from simplestatus to a small shell script --- .gitignore | 1 - Makefile | 4 +- c/simplestatus.c | 336 ----------------------------------------------- sh/status | 87 +++++++++++- sh/statusbar | 3 + sh/vol | 2 +- 6 files changed, 91 insertions(+), 342 deletions(-) delete mode 100644 c/simplestatus.c create mode 100755 sh/statusbar diff --git a/.gitignore b/.gitignore index f536d82..02a7574 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,4 @@ c/timer c/boid c/a.out c/anaconda -c/simplestatus c/colors diff --git a/Makefile b/Makefile index fe7308e..ea90499 100644 --- a/Makefile +++ b/Makefile @@ -23,12 +23,13 @@ sh: cp -f sh/vim-swap-handler $(DESTDIR)$(PREFIX)/bin cp -f sh/snownews-url-handler $(DESTDIR)$(PREFIX)/bin cp -f sh/status $(DESTDIR)$(PREFIX)/bin + cp -f sh/statusbar $(DESTDIR)$(PREFIX)/bin cp -f sh/cfg $(DESTDIR)$(PREFIX)/bin cp -f sh/fire $(DESTDIR)$(PREFIX)/bin cp -f sh/pash-dmenu $(DESTDIR)$(PREFIX)/bin cp -f sh/pash-dmenu-backend $(DESTDIR)$(PREFIX)/bin -mkc: c/scream c/timer c/boid c/anaconda c/simplestatus c/colors +mkc: c/scream c/timer c/boid c/anaconda c/colors c/boid: cc c/boid.c -o c/boid -lm -lX11 @@ -41,7 +42,6 @@ c: cp -f c/timer $(DESTDIR)$(PREFIX)/bin cp -f c/boid $(DESTDIR)$(PREFIX)/bin cp -f c/anaconda $(DESTDIR)$(PREFIX)/bin - cp -f c/simplestatus $(DESTDIR)$(PREFIX)/bin cp -f c/colors $(DESTDIR)$(PREFIX)/bin clean: diff --git a/c/simplestatus.c b/c/simplestatus.c deleted file mode 100644 index dadc4fb..0000000 --- a/c/simplestatus.c +++ /dev/null @@ -1,336 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define NAME "simplestatus" - -typedef struct module { - char *mod_name; - int refresh; - int signal; - struct module *next; -} module; - -typedef struct cache { - char *mod_name; - char *data; - struct cache *next; -} cache; - -const int alloc_inc = 30; -const char module_text[] = "module"; -const char order_text[] = "order"; -const char format_text[] = "format"; -char *format_string = NULL; -module *table = NULL; -cache *mcache = NULL; - -void llprintf(char *fmt) { - int length = strlen(fmt); - cache *ptr = mcache; - - ptr = mcache; - - for(int i = 0; i < length; i++) { - if(fmt[i] == '&') { - fprintf(stdout, "%s", ptr->data); - ptr = ptr->next; - } else { - fprintf(stdout, "%c", fmt[i]); - } - } - - fprintf(stdout, "\n"); - - fflush(stdout); -} - -char *get_conf_dir(void) { - /* check if $XDG_CONFIG_DIR is set */ - char *rootdir, *append; - if((rootdir = getenv("XDG_CONFIG_DIR"))) { - append = "/"NAME"/"; - } else if((rootdir = getenv("HOME"))) { - append = "/.config/"NAME"/"; - } else { - return NULL; - } - - char *buffer = malloc(strlen(rootdir) + strlen(append) + 1); - strcpy(buffer, rootdir); - strcat(buffer, append); - - return buffer; -} - -char *execstdout(char *file, char *arg[], char *env[]) { - int pfds[2]; - - if(pipe(pfds) == -1) { - perror("PIPE"); - fprintf(stderr, "pipe failed! aborting.\n"); - abort(); - } - - int pid = fork(); - - if(pid == -1) { - fprintf(stderr, "fork failed! aborting.\n"); - abort(); - } else if(pid == 0) { - if(close(1) == -1) exit(0); - if(dup(pfds[1]) == -1) exit(0); - if(close(pfds[0])) exit(0); - execlp(file, file, NULL); - } else { - wait(NULL); - - int bufsize = alloc_inc, total = 0; - char *buf = malloc(bufsize); - - if(!buf) { - fprintf(stderr, "malloc failed! aborting.\n"); - abort(); - } - - for(;;) { - int size = read(pfds[0], buf + total, alloc_inc); - - if(size == -1) { - if(errno == EINTR) { - continue; - } else { - free(buf); - close(pfds[0]); - close(pfds[1]); - return NULL; - } - } - - total += size; - - if(size == alloc_inc) { /* we need to reallocate */ - buf = realloc(buf, (bufsize *= 2)); - if(!buf) { - fprintf(stderr, "realloc failed! aborting.\n"); - abort(); - } - continue; - } - - buf[total] = '\0'; - buf = realloc(buf, strlen(buf)); - - close(pfds[0]); - close(pfds[1]); - return buf; - } - } -} - -char *read_line(FILE *fp) { - int size = 30; - int filled = 0; - int c; - char *buf = malloc(size); - - while(c = fgetc(fp)) { - if(c == EOF) { - if(filled == 0) { - free(buf); - return NULL; - } else { - break; - } - } - if(c == '\n') break; - if(size == filled) { - buf = realloc(buf, (size *= 2)); - } - buf[filled] = c; - filled++; - } - buf[filled] = '\0'; - - return buf; -} - -module *parse_file(char *file) { - FILE *fp = fopen(file, "r"); - char *cline; - module *current = NULL, *head = NULL; - int linenumber = 0; - while((cline = read_line(fp)) != NULL) { - printf("debug: %s\n", cline); - linenumber++; - /* free the string up here */ - if(strlen(cline) == 0) { - free(cline); - continue; - } - if(cline[0] == '#') { - free(cline); - continue; - } - - char *res = strtok(cline, " "); - if(!res) printf("strtok returned NULL!\n"); - - if(!memcmp(res, module_text, sizeof module_text)) { - if(current == NULL) { - current = malloc(sizeof *current); - head = current; - current->next = NULL; - } else { - current->next = malloc(sizeof *current); - current = current->next; - current->next = NULL; - } - - /* get the module name */ - char *token = strtok(NULL, " "); - if(!token) { - fprintf(stderr, "syntax error at line %i: specify a module name!\n", linenumber); - return NULL; - } - current->mod_name = strdup(token); - - /* get the signal number */ - token = strtok(NULL, " "); - if(!token) { - fprintf(stderr, "syntax error at line %i: specify the signal number!\n", linenumber); - return NULL; - } - current->signal = atoi(token); - - /* get the refresh duration */ - token = strtok(NULL, " "); - if(!token) { - fprintf(stderr, "syntax error at line %i: specify the refresh duration!\n", linenumber); - return NULL; - } - current->refresh = atoi(token); - - free(cline); - continue; - } else if(!memcmp(res, order_text, sizeof order_text)) { - if(mcache) { - fprintf(stderr, "syntax error at line %i: you can't issue the order command twice\n", linenumber); - return NULL; - } - - char *token; - cache *ptr = mcache; - while(token = strtok(NULL, " ")) { - if(mcache) { - ptr->next = malloc(sizeof *mcache); - ptr = ptr->next; - } else { - mcache = malloc(sizeof mcache); - ptr = mcache; - } - ptr->mod_name = token; - ptr->data = NULL; - ptr->next = NULL; - } - } else if(!memcmp(res, format_text, sizeof format_text)) { - char *pattern = cline + sizeof format_text; - format_string = strdup(pattern); - } - } - - fclose(fp); - - return head; -} - -int is_dir(char *dir) { - struct stat sb; - - if(stat(dir, &sb) == 0 && S_ISDIR(sb.st_mode)) { - return 1; - } else { - return 0; - } -} - -void sighandler(int sig) { - module *ptr = table; - char *mod = NULL; - while(ptr) { - if(ptr->signal == sig) { - mod = ptr->mod_name; - - char *path = malloc(strlen(mod) + 3); - strcpy(path, "./"); - strcat(path, mod); - - char *output = execstdout(path, NULL, NULL); - free(path); - - cache *ptr2 = mcache; - while(ptr2) { - if(!memcmp(mod, ptr2->mod_name, strlen(mod))) { - ptr2->data = output; - break; - } - ptr2 = ptr2->next; - } - } - ptr = ptr->next; - } -} - -void sighandler_w(int sig) { - sighandler(sig); - llprintf(format_string); -} - -void create_sighandle_from_table(void) { - module *ptr = table; - struct sigaction *action = malloc(sizeof *action); - action->sa_handler = sighandler_w; - sigemptyset(&(action->sa_mask)); - action->sa_flags = 0; - while(ptr) { - sigaction(ptr->signal, action, NULL); - sighandler(ptr->signal); /* force an update */ - ptr = ptr->next; - } -} - -int main(void) { - char *conf_dir = get_conf_dir(); - if(!is_dir(conf_dir)) { - fprintf(stderr, "create configuration at %s and try again\n", conf_dir); - exit(1); - } - chdir(conf_dir); - table = parse_file("config"); - create_sighandle_from_table(); - llprintf(format_string); - - int counter = 0; - - for(;;) { - module *ptr = table; - - counter++; - sleep(1); - - while(ptr) { - if(counter % ptr->refresh == 0) { - sighandler_w(ptr->signal); - } - ptr = ptr->next; - } - } - - return 0; -} diff --git a/sh/status b/sh/status index 77002c2..7a72474 100755 --- a/sh/status +++ b/sh/status @@ -1,5 +1,88 @@ #!/bin/sh -[ "$(ps aux | grep simplestatus | wc -l)" -eq 2 ] && killall simplestatus +power_prefix="/sys/class/power_supply/" +[ -d "${power_prefix}sbs-20-000b" ] && bat="sbs-20-000b" -simplestatus | lemonbar -f 'Fantasque Sans Mono' -B "#161510" -F "#4c4635" & +[ "$(ps aux | grep pulseaudio | wc -l)" -eq 2 ] && ss="pulse" || ss="alsa" + +mod_bspwm () { + used_desk=$(bspc query -D -d .occupied --names | tr '\n' ' ') + current_desk=$(bspc query -D -d .focused --names) + final_string="" + current_printed=0 + + for i in $used_desk; do + [ "$i" = "$current_desk" ] && \ + final_string=${final_string}"*$i " && \ + current_printed=1 || \ + final_string=${final_string}"$i " + done + + [ $current_printed -eq 0 ] && + final_string=${final_string}"*$current_desk " + + printf "%s" "$final_string" +} + +mod_power () { + tr -d '\n' < /sys/class/power_supply/$bat/capacity +} + +mod_vol () { + [ "$ss" = "pulse" ] && pactl list sinks | awk -F' ' '$1 == "Volume:" {print "pv" $5}' + [ "$ss" = "alsa" ] && amixer | grep '^ Front' | awk -F'[' '{ORS = ""; print "av" substr($2, 1, 3); exit}' +} + +mod_hello () { + printf "HJi there" +} + +update_mod () { + output="$(eval "mod_$1")" + eval "output_$1=\"$output\"" +} + +get_mod () { + eval "printf '%s' \${output_$1}" +} + +echo_bar () { + left="$(get_mod "power") $(get_mod "vol") $(get_mod "bspwm")" + right="$(get_mod "hello")" + + width="$(tput cols)" + rightwidth="${#right}" + + # print left side + printf "\033[2J\033[H%s" "$left" + + # print right side + printf "\033[1;%if%s" "$(($width - $rightwidth + 1))" "$right" +} + +register_sigs () { + trap "update_mod vol" USR2 + trap "update_mod bspwm" USR1 +} + +update_all () { + update_mod power + update_mod vol + update_mod bspwm +} + +tput civis + +register_sigs + +update_mod power +update_mod vol +update_mod hello +update_mod bspwm + +i=0 +while true; do + sleep 1 + [ "$i" -eq 29 ] && update_all && i=0 + echo_bar +done diff --git a/sh/statusbar b/sh/statusbar new file mode 100755 index 0000000..4c58361 --- /dev/null +++ b/sh/statusbar @@ -0,0 +1,3 @@ +#!/bin/sh + +st -c statusbar -g 195x1+0+0 -e status diff --git a/sh/vol b/sh/vol index fe2a790..0cd2572 100755 --- a/sh/vol +++ b/sh/vol @@ -16,4 +16,4 @@ else amixer -c 0 set Master "5%${sign}" fi -killall -12 simplestatus +killall -12 status From f18f974a35bcc96c83100dfb5776abd6f895c92b Mon Sep 17 00:00:00 2001 From: randomuser Date: Mon, 4 Jul 2022 12:38:02 -0500 Subject: [PATCH 137/197] make statusbar actually useable --- sh/status | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/sh/status b/sh/status index 7a72474..243beef 100755 --- a/sh/status +++ b/sh/status @@ -33,8 +33,8 @@ mod_vol () { [ "$ss" = "alsa" ] && amixer | grep '^ Front' | awk -F'[' '{ORS = ""; print "av" substr($2, 1, 3); exit}' } -mod_hello () { - printf "HJi there" +mod_date_time () { + date '+%m%d-%H:%M' | tr '\n' ' ' } update_mod () { @@ -47,8 +47,8 @@ get_mod () { } echo_bar () { - left="$(get_mod "power") $(get_mod "vol") $(get_mod "bspwm")" - right="$(get_mod "hello")" + left="$(get_mod "bspwm")" + right="$(get_mod "date_time") $(get_mod "power") $(get_mod "vol")" width="$(tput cols)" rightwidth="${#right}" @@ -69,20 +69,18 @@ update_all () { update_mod power update_mod vol update_mod bspwm + update_mod date_time } tput civis register_sigs - -update_mod power -update_mod vol -update_mod hello -update_mod bspwm +update_all i=0 while true; do - sleep 1 - [ "$i" -eq 29 ] && update_all && i=0 + sleep 0.25 + [ "$i" -eq $((29 * 4)) ] && update_all && i=0 echo_bar + i="$(($i + 1))" done From dcaa5e0f0356381f143b45e79ab79e971e96acf3 Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 5 Jul 2022 14:08:31 -0500 Subject: [PATCH 138/197] add tmenu --- Makefile | 3 +++ sh/tmenu | 8 ++++++++ sh/tmenu-backend | 6 ++++++ sh/tmenu_run | 12 ++++++++++++ 4 files changed, 29 insertions(+) create mode 100755 sh/tmenu create mode 100755 sh/tmenu-backend create mode 100755 sh/tmenu_run diff --git a/Makefile b/Makefile index ea90499..8c15632 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,9 @@ sh: cp -f sh/fire $(DESTDIR)$(PREFIX)/bin cp -f sh/pash-dmenu $(DESTDIR)$(PREFIX)/bin cp -f sh/pash-dmenu-backend $(DESTDIR)$(PREFIX)/bin + cp -f sh/tmenu $(DESTDIR)$(PREFIX)/bin + cp -f sh/tmenu-backend $(DESTDIR)$(PREFIX)/bin + cp -f sh/tmenu_run $(DESTDIR)$(PREFIX)/bin mkc: c/scream c/timer c/boid c/anaconda c/colors diff --git a/sh/tmenu b/sh/tmenu new file mode 100755 index 0000000..cbfeec6 --- /dev/null +++ b/sh/tmenu @@ -0,0 +1,8 @@ +#!/bin/sh + +file=$(mktemp) +cat - > "$file" + +st -c tmenu-prompt -g 40x10+0+0 -e tmenu-backend "$file" +cat "$file" +rm "$file" diff --git a/sh/tmenu-backend b/sh/tmenu-backend new file mode 100755 index 0000000..cd2839b --- /dev/null +++ b/sh/tmenu-backend @@ -0,0 +1,6 @@ +#!/bin/sh + +printf "%s" $1 + +fzy < "$1" > "${1}a" +mv ${1}a ${1} diff --git a/sh/tmenu_run b/sh/tmenu_run new file mode 100755 index 0000000..1b57921 --- /dev/null +++ b/sh/tmenu_run @@ -0,0 +1,12 @@ +#!/bin/sh + +tmenu_path () { + IFS=" :" + for i in $PATH; do + for j in "$i"/*; do + [ -f $j ] && [ -x $j ] && printf "%s\n" $j + done + done +} + +tmenu_path | tmenu "$@" | ${SHELL:-"/bin/sh"} & From 19172ef27b577fafb2100517e006af41158e79b7 Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 5 Jul 2022 14:09:42 -0500 Subject: [PATCH 139/197] move dmenu to tmenu --- sh/pash-dmenu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sh/pash-dmenu b/sh/pash-dmenu index 0499dcf..2aa92ba 100755 --- a/sh/pash-dmenu +++ b/sh/pash-dmenu @@ -1,6 +1,6 @@ #!/bin/sh -sel="$(pash l | dmenu)" +sel="$(pash l | tmenu)" [ "$?" -eq 1 ] && exit 0 # requires bspc rule -a st-gpg-menu state=floating From 3b7bc5491c5bb09cd78069f9a230959a65c33314 Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 5 Jul 2022 15:43:21 -0500 Subject: [PATCH 140/197] add ss --- Makefile | 1 + sh/ss | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100755 sh/ss diff --git a/Makefile b/Makefile index 8c15632..3d717fa 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,7 @@ sh: cp -f sh/tmenu $(DESTDIR)$(PREFIX)/bin cp -f sh/tmenu-backend $(DESTDIR)$(PREFIX)/bin cp -f sh/tmenu_run $(DESTDIR)$(PREFIX)/bin + cp -f sh/ss $(DESTDIR)$(PREFIX)/bin mkc: c/scream c/timer c/boid c/anaconda c/colors diff --git a/sh/ss b/sh/ss new file mode 100755 index 0000000..0dec028 --- /dev/null +++ b/sh/ss @@ -0,0 +1,12 @@ +#!/bin/sh + +scripts="$( + find /home/usr/git/utils/sh /home/usr/git/utils/c -type f | + grep -v '\.git' | + xargs file | + grep 'C source \|POSIX shell script' | + awk -F':' '{print $1}' | + fzy +)" + +[ -z "$scripts" ] || nvim "$scripts" From f98f12504de22d644e502ebfd57fc63f8a43d248 Mon Sep 17 00:00:00 2001 From: randomuser Date: Wed, 6 Jul 2022 00:12:20 -0500 Subject: [PATCH 141/197] add net script --- Makefile | 1 + sh/net | 4 ++++ 2 files changed, 5 insertions(+) create mode 100755 sh/net diff --git a/Makefile b/Makefile index 3d717fa..38dc2e2 100644 --- a/Makefile +++ b/Makefile @@ -32,6 +32,7 @@ sh: cp -f sh/tmenu-backend $(DESTDIR)$(PREFIX)/bin cp -f sh/tmenu_run $(DESTDIR)$(PREFIX)/bin cp -f sh/ss $(DESTDIR)$(PREFIX)/bin + cp -f sh/net $(DESTDIR)$(PREFIX)/bin mkc: c/scream c/timer c/boid c/anaconda c/colors diff --git a/sh/net b/sh/net new file mode 100755 index 0000000..70b74a5 --- /dev/null +++ b/sh/net @@ -0,0 +1,4 @@ +#!/bin/sh +# designed to be called from sxhkd (x session) + +[ "$(pgrep NetworkManager)" ] && st -e nmtui From 7f098bede3b47872391b5ab374a8180a06aeb25d Mon Sep 17 00:00:00 2001 From: randomuser Date: Wed, 6 Jul 2022 00:12:33 -0500 Subject: [PATCH 142/197] update todolist --- TODO | 1 + 1 file changed, 1 insertion(+) diff --git a/TODO b/TODO index 9fa70a6..2737a72 100644 --- a/TODO +++ b/TODO @@ -2,4 +2,5 @@ TODO LIST --------- - change statusbar program so it uses static allocations instead of dynamic ones +- fix paste - make the c programs less buggy and let them not suck as much From 12f5bac3b9cbb0396cd2cf34aea1bc9e46f88713 Mon Sep 17 00:00:00 2001 From: randomuser Date: Fri, 8 Jul 2022 02:28:49 +0000 Subject: [PATCH 143/197] add thinkpad x220 support --- sh/status | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sh/status b/sh/status index 243beef..aeaa3cb 100755 --- a/sh/status +++ b/sh/status @@ -2,6 +2,7 @@ power_prefix="/sys/class/power_supply/" [ -d "${power_prefix}sbs-20-000b" ] && bat="sbs-20-000b" +[ -d "${power_prefix}BAT0" ] && bat="BAT0" [ "$(ps aux | grep pulseaudio | wc -l)" -eq 2 ] && ss="pulse" || ss="alsa" @@ -25,6 +26,7 @@ mod_bspwm () { } mod_power () { + [ -z "$bat" ] || tr -d '\n' < /sys/class/power_supply/$bat/capacity } From 98705dc892c574628ac9aad7c9c302f9fbf653b6 Mon Sep 17 00:00:00 2001 From: randomuser Date: Fri, 8 Jul 2022 03:34:55 +0000 Subject: [PATCH 144/197] reconcile --- Makefile | 1 + sh/bspwm-toggle-gaps | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100755 sh/bspwm-toggle-gaps diff --git a/Makefile b/Makefile index 38dc2e2..a584e7e 100644 --- a/Makefile +++ b/Makefile @@ -33,6 +33,7 @@ sh: cp -f sh/tmenu_run $(DESTDIR)$(PREFIX)/bin cp -f sh/ss $(DESTDIR)$(PREFIX)/bin cp -f sh/net $(DESTDIR)$(PREFIX)/bin + cp -f sh/bspwm-toggle-gaps $(DESTDIR)$(PREFIX)/bin mkc: c/scream c/timer c/boid c/anaconda c/colors diff --git a/sh/bspwm-toggle-gaps b/sh/bspwm-toggle-gaps new file mode 100755 index 0000000..776fc5a --- /dev/null +++ b/sh/bspwm-toggle-gaps @@ -0,0 +1,11 @@ +#!/bin/sh + +gaps="$(bspc config top_padding)" + +if [ "$gaps" -eq 20 ]; then + bspc config window_gap 0 + bspc config top_padding 18 +else + bspc config window_gap 3 + bspc config top_padding 20 +fi From d89220e326626baeaaefa87b0a93ada2feaff308 Mon Sep 17 00:00:00 2001 From: randomuser Date: Wed, 13 Jul 2022 00:01:08 -0500 Subject: [PATCH 145/197] simple trss rss reader coming soon(tm) --- Makefile | 1 + sh/trss | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100755 sh/trss diff --git a/Makefile b/Makefile index fe7308e..bbe7512 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,7 @@ man: sh: mkdir -p $(DESTDIR)$(PREFIX)/bin cp -f sh/paste $(DESTDIR)$(PREFIX)/bin + cp -f sh/trss $(DESTDIR)$(PREFIX)/bin cp -f sh/disp $(DESTDIR)$(PREFIX)/bin cp -f sh/wallpaper $(DESTDIR)$(PREFIX)/bin cp -f sh/yt $(DESTDIR)$(PREFIX)/bin diff --git a/sh/trss b/sh/trss new file mode 100755 index 0000000..c7e0180 --- /dev/null +++ b/sh/trss @@ -0,0 +1,39 @@ +#!/bin/sh + +# get configuration & data directories +DATA="$HOME/.cache/trss" +CONFIG="$HOME/.config/trss" + +# make sure these directories are in place +mkdir -p "$DATA" +mkdir -p "$CONFIG" + +import_information () { + FEEDS="" + for i in "$CONFIG"/*; do + . "$i" + [ -z "$FEEDS" ] && FEEDS="$NAME" || FEEDS="$FEEDS $NAME" + done +} + +synchronize () { + for i in $FEEDS; do + url="$(get_feed_attr "$i" feed)" + printf "> synchronizing feed %s via url %s\n" "$i" "$url" + curl "$url" -so "$DATA/${i}.xml" + + # generate sfeed formatted file + printf "> creating sfeed compound feed file for feed %s\n" "$i" + cat "$DATA/${i}.xml" | sfeed | cat - "$DATA/${i}.sfeed" | uniq >> "$DATA/${i}.tmp.sfeed" + mv "$DATA/${i}.tmp.sfeed" "${DATA}/${i}.sfeed" + done +} + +get_feed_attr () { + eval "printf '%s' \${$1_$2}" +} + +import_information +synchronize +printf "%s\n" "$FEEDS" +get_feed_attr seirdy humanname From 45faf87871f5f058c5c0d7c28f69f12e05116bb3 Mon Sep 17 00:00:00 2001 From: randomuser Date: Wed, 13 Jul 2022 00:02:38 -0500 Subject: [PATCH 146/197] add check to makefile, hopefully work through the shellcheck error output --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index bbe7512..823f7ea 100644 --- a/Makefile +++ b/Makefile @@ -29,6 +29,9 @@ sh: cp -f sh/pash-dmenu $(DESTDIR)$(PREFIX)/bin cp -f sh/pash-dmenu-backend $(DESTDIR)$(PREFIX)/bin +check: + shellcheck sh/* + mkc: c/scream c/timer c/boid c/anaconda c/simplestatus c/colors c/boid: From 7cd526b0bdcb52b42499786f84b7bb070d101353 Mon Sep 17 00:00:00 2001 From: randomuser Date: Wed, 13 Jul 2022 00:04:31 -0500 Subject: [PATCH 147/197] make paste work again --- sh/paste | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sh/paste b/sh/paste index 89b5eb0..87987e0 100755 --- a/sh/paste +++ b/sh/paste @@ -1,5 +1,4 @@ #!/bin/sh -set -x [ "$1" = "" ] && exit 1 -[ -f "$1" ] && curl -F"file=@${1}" https://ttm.sh && exit 0 +[ -f "$1" ] && curl -F"file=@${1}" https://0x0.st && exit 0 From 2e24a2387ad8e3fb51596d0d395cf75005e42871 Mon Sep 17 00:00:00 2001 From: randomuser Date: Wed, 13 Jul 2022 00:05:23 -0500 Subject: [PATCH 148/197] no need for snownews stuff, i'll hopefully get trss working --- Makefile | 1 - sh/snownews-url-handler | 7 ------- 2 files changed, 8 deletions(-) delete mode 100755 sh/snownews-url-handler diff --git a/Makefile b/Makefile index 823f7ea..6107751 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,6 @@ sh: cp -f sh/pco $(DESTDIR)$(PREFIX)/bin cp -f sh/git-survey $(DESTDIR)$(PREFIX)/bin cp -f sh/vim-swap-handler $(DESTDIR)$(PREFIX)/bin - cp -f sh/snownews-url-handler $(DESTDIR)$(PREFIX)/bin cp -f sh/status $(DESTDIR)$(PREFIX)/bin cp -f sh/cfg $(DESTDIR)$(PREFIX)/bin cp -f sh/fire $(DESTDIR)$(PREFIX)/bin diff --git a/sh/snownews-url-handler b/sh/snownews-url-handler deleted file mode 100755 index 50bcff7..0000000 --- a/sh/snownews-url-handler +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -# tube="$(printf "%s\n" "$1" | grep "watch?v=" | wc -l)" -# [ "$tube" -eq 1 ] && mpv -v --video-sync=display-resample "$1" && exit - -firefox $1 -killall -10 simplestatus From 03ffeaadaf8f28834aeba132b5bb49a147255ab4 Mon Sep 17 00:00:00 2001 From: randomuser Date: Wed, 13 Jul 2022 18:28:23 -0500 Subject: [PATCH 149/197] add some random crap --- etc/southwest_tracker.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 etc/southwest_tracker.py diff --git a/etc/southwest_tracker.py b/etc/southwest_tracker.py new file mode 100644 index 0000000..2cf2258 --- /dev/null +++ b/etc/southwest_tracker.py @@ -0,0 +1,26 @@ +import httplib2 +import json +import math +import time + +# fun fact: i got bored so made this on a southwest flight + +while True: + request = httplib2.Http() + # you have to look in the network tab in 'inspect element', and find the '_' parameter, and paste that in + # of course, you have to be connected to southwest's onboard wifi + _param = "fill this in" + data = request.request("https://getconnected.southwestwifi.com/fp3d_fcgi-php/portal/public/index.php?_url=/index/getFile&path=last&_=" + _param) + data = json.loads(data[1]) + print("-- Update --") + print("Nautical Miles: " + str(data["distanceToDestinationNauticalMiles"])) + print("Phase: " + data["presentPhase"]) + print("Speed: " + str(data["groundSpeedKnots"]) + "kts") + seconds = data['timeToDestination'] + minutes = math.floor(seconds / 60) + seconds = seconds % 60 + print("Minutes: " + str(minutes) + " Seconds: " + str(seconds)) + print("Flight Number: " + data["flightNumber"] + " Registration: " + data["tailNumber"]) + + time.sleep(3) + print('\033[H\033[2J') From 1715cf42b29e62e4902585a92e3d0b86a741ed21 Mon Sep 17 00:00:00 2001 From: randomuser Date: Fri, 15 Jul 2022 15:48:02 -0500 Subject: [PATCH 150/197] add machine --- Makefile | 1 + sh/machine | 15 +++++++++++++++ sh/statusbar | 6 +++++- 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100755 sh/machine diff --git a/Makefile b/Makefile index a584e7e..c29fa47 100644 --- a/Makefile +++ b/Makefile @@ -34,6 +34,7 @@ sh: cp -f sh/ss $(DESTDIR)$(PREFIX)/bin cp -f sh/net $(DESTDIR)$(PREFIX)/bin cp -f sh/bspwm-toggle-gaps $(DESTDIR)$(PREFIX)/bin + cp -f sh/machine $(DESTDIR)$(PREFIX)/bin mkc: c/scream c/timer c/boid c/anaconda c/colors diff --git a/sh/machine b/sh/machine new file mode 100755 index 0000000..9733ca7 --- /dev/null +++ b/sh/machine @@ -0,0 +1,15 @@ +#!/bin/sh + +host="$(hostname)" + +case "$host" in + "mlg" | "think") + exit 1 + ;; + "toaster") + exit 2 + ;; + "fish") + exit 3 + ;; +esac diff --git a/sh/statusbar b/sh/statusbar index 4c58361..d0f73b8 100755 --- a/sh/statusbar +++ b/sh/statusbar @@ -1,3 +1,7 @@ #!/bin/sh -st -c statusbar -g 195x1+0+0 -e status +machine + +[ "$?" -eq 2 ] && + st -c statusbar -g 142x1+0+0 -e status || + st -c statusbar -g 195x1+0+0 -e status From fdb75ea541963e87f77e30f98c7eb8c1945c459c Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 17 Jul 2022 01:10:27 -0500 Subject: [PATCH 151/197] add features to trss trss is an rss feed reader. I've added the ability to subscribe to feeds, see the entries therein, and browse the entries via lynx. One thing left to do is to add functionality for opening the entry url in a web browser. Other than this, just general error checking is required, and a sweep of the code for beautification and performance. --- sh/trss | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 102 insertions(+), 4 deletions(-) diff --git a/sh/trss b/sh/trss index c7e0180..604ef85 100755 --- a/sh/trss +++ b/sh/trss @@ -3,6 +3,7 @@ # get configuration & data directories DATA="$HOME/.cache/trss" CONFIG="$HOME/.config/trss" +MODE="" # make sure these directories are in place mkdir -p "$DATA" @@ -24,7 +25,7 @@ synchronize () { # generate sfeed formatted file printf "> creating sfeed compound feed file for feed %s\n" "$i" - cat "$DATA/${i}.xml" | sfeed | cat - "$DATA/${i}.sfeed" | uniq >> "$DATA/${i}.tmp.sfeed" + cat "$DATA/${i}.xml" | sfeed | cat - "$DATA/${i}.sfeed" | sort -u | sort -r -k 1 >> "$DATA/${i}.tmp.sfeed" mv "$DATA/${i}.tmp.sfeed" "${DATA}/${i}.sfeed" done } @@ -33,7 +34,104 @@ get_feed_attr () { eval "printf '%s' \${$1_$2}" } +cli_loop () { + read -p "$MODE\$ " input + case "$input" in + "ls"*) + ls_handler $input + ;; + "cd"*) + cd_handler $input + ;; + "cat"*) + cat_handler $input + ;; + "sync"*) + sync_handler $input + ;; + "set"*) + set_handler $input + ;; + esac +} + +ls_handler () { + if [ -z "$MODE" ]; then + # just list all the feeds + for i in $FEEDS; do + printf "%s\n" "$i" + done + else + # we have to list all the items in the feed + # check first if feed is downloaded + if [ -f "$DATA/${MODE}.sfeed" ]; then + awk -F'\t' '{ print $2 }' "$DATA/${MODE}.sfeed" + else + printf "synchronization of feed %s required\n" "$MODE" + fi + fi +} + +cd_handler () { + if [ -z "$MODE" ]; then + # we're in the home state + [ -z "$2" ] && return + [ "$2" = ".." ] && return + + # check if $2 is a valid feed + j=0 + for i in $FEEDS; do + [ "$2" = "$i" ] && j=1 + done + + if [ "$j" -ne 1 ]; then + printf "trss: couldn't find feed %s\n" "$2" + return + fi + + # set the $MODE to the feed + MODE="$2" + else + # we're in an individual feed + [ -z "$2" ] && MODE="" && return + [ "$2" = ".." ] && MODE="" && return + + printf "trss: couldn't find feed %s\n" "$2" + fi +} + +sync_handler () { + synchronize +} + +set_handler () { + printf "stub, use +x or -x to disable/enable debug output\n" +} + +cat_handler () { + realargs="$(printf '%s\n' "$@" | tr '\n' ' ' | sed 's/^cat //g;s/ $//g')" + [ -z "$MODE" ] && printf "couldn't find entry matching %s\n" "$realargs" + results="$(awk -F'\t' -v pat="$realargs" '$2 ~ pat { print $0 }' "$DATA/${MODE}.sfeed")" + + OLDIFS="$IFS" + IFS=" +" + + for i in $results; do + entry="$(printf "%s" "$i" | awk -F'\t' '{ print $4 }')" + + printf "%s\n" "$entry" | + sed -e 's|\\n|\n|g' -e 's|\\t|\t|g' | + lynx -stdin + + IFS="$OLDIFS" + return + done + + printf "couldn't find any entries matching %s\n" "$realargs" +} + import_information -synchronize -printf "%s\n" "$FEEDS" -get_feed_attr seirdy humanname +while true; do + cli_loop +done From 836e8d343279a9bd29d283faae2e3bfd569f50c3 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 17 Jul 2022 07:23:22 -0500 Subject: [PATCH 152/197] small change to trss --- sh/trss | 4 ---- 1 file changed, 4 deletions(-) diff --git a/sh/trss b/sh/trss index 604ef85..69e736c 100755 --- a/sh/trss +++ b/sh/trss @@ -124,11 +124,7 @@ cat_handler () { sed -e 's|\\n|\n|g' -e 's|\\t|\t|g' | lynx -stdin - IFS="$OLDIFS" - return done - - printf "couldn't find any entries matching %s\n" "$realargs" } import_information From fc58681148c30d0480ca756361b9e25a5e2ed633 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 17 Jul 2022 08:47:30 -0500 Subject: [PATCH 153/197] add indiividual sync to trss --- sh/trss | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/sh/trss b/sh/trss index 69e736c..6042cf8 100755 --- a/sh/trss +++ b/sh/trss @@ -17,16 +17,20 @@ import_information () { done } +sync_individual () { + url="$(get_feed_attr "$1" feed)" + printf "> synchronizing feed %s via url %s\n" "$1" "$url" + curl "$url" -so "$DATA/${1}.xml" + + # generate sfeed formatted file + printf "> creating sfeed compound feed file for feed %s\n" "$i" + cat "$DATA/${1}.xml" | sfeed | cat - "$DATA/${1}.sfeed" | sort -u | sort -r -k 1 >> "$DATA/${1}.tmp.sfeed" + mv "$DATA/${1}.tmp.sfeed" "${DATA}/${1}.sfeed" +} + synchronize () { for i in $FEEDS; do - url="$(get_feed_attr "$i" feed)" - printf "> synchronizing feed %s via url %s\n" "$i" "$url" - curl "$url" -so "$DATA/${i}.xml" - - # generate sfeed formatted file - printf "> creating sfeed compound feed file for feed %s\n" "$i" - cat "$DATA/${i}.xml" | sfeed | cat - "$DATA/${i}.sfeed" | sort -u | sort -r -k 1 >> "$DATA/${i}.tmp.sfeed" - mv "$DATA/${i}.tmp.sfeed" "${DATA}/${i}.sfeed" + sync_individual "$i" done } @@ -101,7 +105,18 @@ cd_handler () { } sync_handler () { - synchronize + force=0 + [ "$2" = "-f" ] && force=1 + [ "$3" = "-f" ] && force=1 + + if [ -z "$MODE" ]; then + # sync everything + synchronize + else + [ -n "$2" ] && [ ! "$2" = "-f" ] && + sync_individual "$2" || + sync_individual "$MODE" + fi } set_handler () { From d66deef6b927b7bb4429673edf1686dd03ad709f Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 17 Jul 2022 08:47:49 -0500 Subject: [PATCH 154/197] todo change --- TODO | 1 + 1 file changed, 1 insertion(+) diff --git a/TODO b/TODO index 2737a72..cf858f6 100644 --- a/TODO +++ b/TODO @@ -4,3 +4,4 @@ TODO LIST - change statusbar program so it uses static allocations instead of dynamic ones - fix paste - make the c programs less buggy and let them not suck as much +- add manpage for trss From 62eec5e9ab626bd954027a8a2d6c4eed82ec4e95 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 17 Jul 2022 08:49:12 -0500 Subject: [PATCH 155/197] todo add --- TODO | 1 + 1 file changed, 1 insertion(+) diff --git a/TODO b/TODO index cf858f6..a2d928c 100644 --- a/TODO +++ b/TODO @@ -5,3 +5,4 @@ TODO LIST - fix paste - make the c programs less buggy and let them not suck as much - add manpage for trss +- add option to *force* syncing From 6ed0ede26d99226bf79592b31e9022b9b85a827e Mon Sep 17 00:00:00 2001 From: randomuser Date: Mon, 18 Jul 2022 22:07:17 -0500 Subject: [PATCH 156/197] remove yt and add trss-yt-id --- Makefile | 1 + sh/trss-yt-id | 8 ++++ sh/yt | 103 -------------------------------------------------- 3 files changed, 9 insertions(+), 103 deletions(-) create mode 100755 sh/trss-yt-id delete mode 100755 sh/yt diff --git a/Makefile b/Makefile index dfa07e8..b4ce4b6 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,7 @@ sh: mkdir -p $(DESTDIR)$(PREFIX)/bin cp -f sh/paste $(DESTDIR)$(PREFIX)/bin cp -f sh/trss $(DESTDIR)$(PREFIX)/bin + cp -f sh/trss-yt-id $(DESTDIR)$(PREFIX)/bin cp -f sh/disp $(DESTDIR)$(PREFIX)/bin cp -f sh/wallpaper $(DESTDIR)$(PREFIX)/bin cp -f sh/yt $(DESTDIR)$(PREFIX)/bin diff --git a/sh/trss-yt-id b/sh/trss-yt-id new file mode 100755 index 0000000..8edbfc3 --- /dev/null +++ b/sh/trss-yt-id @@ -0,0 +1,8 @@ +#!/bin/sh + +[ -z "$1" ] && exit 1 + +curl "${1}" -s | \ + grep 'youtube/www\.youtube\.com/channel/.\{24\}' -o | \ + awk -F'/' '{print "https://www.youtube.com/feeds/videos.xml?channel_id=" $NF}' | \ + sed 1q diff --git a/sh/yt b/sh/yt deleted file mode 100755 index 111af45..0000000 --- a/sh/yt +++ /dev/null @@ -1,103 +0,0 @@ -#!/bin/sh - -[ -z "${YT_DATFILE}" ] && YT_DATFILE="${HOME}/.local/share/ytdat" -[ -z "${YT_CACHEDIR}" ] && YT_CACHEDIR="${HOME}/.local/share/ytcache" -[ -z "${YT_TORIFY}" ] && YT_TORIFY="" -ver=0.1 - -info () { - printf %s "\ -yt - youtube tool - -=> [s]ync - Sync RSS feeds -=> [a]dd [id] - Add a channel to the list -=> [d]el [id] - Remove a channel from the list -=> [h]elp - Show this help -=> [i]d [url] - Show internal channel id -=> [c]lear - Clear cache - -List file: export YT_DATFILE= -Cache directory: export YT_CACHEDIR= -Torify wrapper: export YT_TORIFY= -" -} -cache () { - touch ${YT_DATFILE} - mkdir -p ${YT_CACHEDIR} -} -err () { - printf "err: %s\n" ${1} - [ -z "${2}" ] && exit 1 - exit ${2} -} -sync () { - cache - for i in $(cat $YT_DATFILE | tr '\n' ' '); do - ${YT_TORIFY} curl -s \ - https://www.youtube.com/feeds/videos.xml?channel_id=$i\ - > ${YT_CACHEDIR}/$i - done -} -id () { - ${YT_TORIFY} curl "${1}" -s | \ - grep 'youtube/www\.youtube\.com/channel/.\{24\}' -o | \ - awk -F'/' '{print $NF}' | \ - sed 1q -} -display () { - cache - tmp1=$(mktemp) - tmp2=$(mktemp) - for i in $(ls $YT_CACHEDIR | tr '\n' ' '); do - grep \ ${YT_CACHEDIR}/$i | cut -c 17- | \ - rev | cut -c 15- | rev >> $tmp1 - grep 'link rel' ${YT_CACHEDIR}/$i | grep 'watch' | \ - cut -c31- | rev | cut -c4- | rev >> $tmp2 - done - cat $tmp1 $tmp2 | pr -2t -s" | " -} -add () { # $1: name of channel id - cache - printf "%s\n" $1 >> ${YT_DATFILE} -} -del () { # $1: line number of channel id - cache - sed -i "${1}d" ${YT_DATFILE} -} -cclear () { - rm -r ${YT_CACHEDIR} -} -case $1 in - "s"*) - sync - exit 0 - ;; - "a"*) - [ $# -eq 2 ] && add $2 || \ - err "two args required" - exit 0 - ;; - "d"*) - [ $# -eq 2 ] && del $2 || \ - err "two args required" - exit 0 - ;; - "h"*) - info - exit 0 - ;; - "i"*) - [ $# -eq 2 ] && id $2 || \ - err "two args required" - exit 0 - ;; - "c"*) - cclear - exit 0 - ;; - *) - display - exit 0 - ;; -esac -exit 0 From b917fd2de9be7d766e6d7e4cb7b11ed93ef7f5c5 Mon Sep 17 00:00:00 2001 From: randomuser Date: Mon, 18 Jul 2022 22:08:31 -0500 Subject: [PATCH 157/197] remove simplestatus man page --- man/simplestatus.1 | 87 ---------------------------------------------- 1 file changed, 87 deletions(-) delete mode 100644 man/simplestatus.1 diff --git a/man/simplestatus.1 b/man/simplestatus.1 deleted file mode 100644 index 7dcb8a1..0000000 --- a/man/simplestatus.1 +++ /dev/null @@ -1,87 +0,0 @@ -'\" t -.TH SIMPLESTATUS 1 simplestatus -.SH NAME -simplestatus \- simple, lightweight status bar content generator -.SH SYNOPSIS -.B simplestatus -.SH DESCRIPTION -simplestatus is a simple status bar content generator for statusbars which accept their input via standard input (such as lemonbar), or can be used in conjunction with other utilities to set their statusbars (e.g. dwm's statusbar). simplestatus is configured via a configuration file. - -simplestatus works on the premise of each component in the statusbar being a module; in this case, simplestatus represents them in shell scripts residing in the configuration directory. When a module needs to be updated, the cooresponding shell script is executed and its stdout read as the output of the module. Modules can be updated via signals send to the process or via timers, all specified in the configuration file. -.SH CONFIGURATION -The configuration file resides in the configuration directory. The configuration file location is determined via checking the following places: -.IP -o $XDG_CONFIG_DIR/simplestatus/config -.IP -o $HOME/.config/simplestatus/config -.P -If after these two steps the configuration cannot be found, simplestatus exits. - -Once the configuration file location is determined, the configuration file is read and parsed. There are three main directives in the configuration file: -.IP -o module -.IP -o order -.IP -o format -.SS module -This directive takes three arguments: the module name, the signal trigger number, and the timer trigger. For example -.IP -.B module power 7 30 -.P -defines a module named ``power'', which is updated when signal 7 is recieved (SIGBUS) or every thirty seconds. ``power'' must be an executable placed in the configuration directory (e.g. the directory in which the configuration file resides) and must have the executable flag set for the current user. Note that entering the signals' symbolic name (SIGBUS) instead of the number (7) is not supported at this time. -.SS order -The ``order'' directive specifies in what order the modules will be placed in the format string, defined by the directive ``format''. For example, -.IP -.B order power time date wm -.P -specifies the order in which the modules will be inserted in the format string, starting with ``power'' and ending with ``wm''. -.SS format -``format'' specifies the format string that the output of the modules will be inserted into. Below is an example command: -.IP -.B format %{l}&%{c}&%{r}& -.SH CONFIGURATION EXAMPLE -Assume we have the following modules, who output the following values: -.TS -tab(@) allbox; -l|l . -MODULE@EVALUATED VALUE -foo@bar -ping@pong -a@b -.TE -.P -and this configuration: -.IP -module foo 7 30 - -module ping 10 30 - -module a 12 120 - -order foo ping a - -format output of foo: &; output of ping: &; output of a: & -.P -we will get the output: -.IP -.B output of foo: bar; output of ping: pong; output of a: b -.P -Should you wish to make comments, prefix lines with ``#''. If you wish to make spaces between instructions, make an empty line. -.SH COMMON PITFALLS -.IP -o Don't assign SIGINT (2) to a module unless you want it to update when you ^C! -.SH PLANNED FEATURES -.IP -o If the configuration file is marked +x, execute and read contents from the script's stdout to be parsed. -o free(...) memory when finished. -o Add ability to export environment variables to scripts via configuration file. -o Add signal to force re-parsing of configuration file. -.SH KNOWN BUGS -o Lack of use of free(...), causing potential for memory leaks. -.SH SEE ALSO -.BR lemonbar (1), -.BR slstatus (1) - -.SH AUTHOR -randomuser From 11d85172f5cec608ed5eb90734b7d0ddf28afc56 Mon Sep 17 00:00:00 2001 From: randomuser Date: Mon, 18 Jul 2022 22:16:42 -0500 Subject: [PATCH 158/197] add trss manpage --- man/trss.1 | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 man/trss.1 diff --git a/man/trss.1 b/man/trss.1 new file mode 100644 index 0000000..5decc38 --- /dev/null +++ b/man/trss.1 @@ -0,0 +1,32 @@ +.TH TRSS 1 trss +.SH NAME +trss \- command oriented feed reader powered by sfeed +.SH SYNOPSIS +.B trss +.SH INTERFACE +.TP +.B ls +list all feed names in the 'feed home', or within a feed, list all items within +.TP +.B cd +focus another feed. in order to go back to the 'feed home', use 'cd' or 'cd ..' +.TP +.B sync +with no arguments and in the 'feed home', syncs all feeds. if in a specific feed, syncs that feed. a feed can be specified in an argument. +.TP +.B cat +open all feeds whose titles contain text as specified by an argument in 'lynx' + +.SH trss-yt-id +this script is designed to allow one to obtain an rss feed for the uploads of a youtube channel. this command takes the homepage of the youtube channel in question as an argument and then returns the rss feed for that channel. + +.SH BUGS +- 'set' is a stub + +- when in a feed, you can't cd to another directly, you must go to to the 'feed home' and then cd + +.SH DEPENDS +sfeed + +.SH AUTHOR +randomuser From 128198e0b509c9e6519870c24e60abbb33e57b71 Mon Sep 17 00:00:00 2001 From: randomuser Date: Mon, 18 Jul 2022 22:38:47 -0500 Subject: [PATCH 159/197] small changes --- Makefile | 1 - man/trss.1 | 2 -- sh/trss | 29 +++++++++++++++++++++++------ 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index b4ce4b6..4ac0c1f 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,6 @@ sh: cp -f sh/trss-yt-id $(DESTDIR)$(PREFIX)/bin cp -f sh/disp $(DESTDIR)$(PREFIX)/bin cp -f sh/wallpaper $(DESTDIR)$(PREFIX)/bin - cp -f sh/yt $(DESTDIR)$(PREFIX)/bin cp -f sh/connect $(DESTDIR)$(PREFIX)/bin cp -f sh/nws $(DESTDIR)$(PREFIX)/bin cp -f sh/vol $(DESTDIR)$(PREFIX)/bin diff --git a/man/trss.1 b/man/trss.1 index 5decc38..575a9e5 100644 --- a/man/trss.1 +++ b/man/trss.1 @@ -21,8 +21,6 @@ open all feeds whose titles contain text as specified by an argument in 'lynx' this script is designed to allow one to obtain an rss feed for the uploads of a youtube channel. this command takes the homepage of the youtube channel in question as an argument and then returns the rss feed for that channel. .SH BUGS -- 'set' is a stub - - when in a feed, you can't cd to another directly, you must go to to the 'feed home' and then cd .SH DEPENDS diff --git a/sh/trss b/sh/trss index 6042cf8..dc07b04 100755 --- a/sh/trss +++ b/sh/trss @@ -23,7 +23,7 @@ sync_individual () { curl "$url" -so "$DATA/${1}.xml" # generate sfeed formatted file - printf "> creating sfeed compound feed file for feed %s\n" "$i" + printf "> creating sfeed compound feed file for feed %s\n" "$1" cat "$DATA/${1}.xml" | sfeed | cat - "$DATA/${1}.sfeed" | sort -u | sort -r -k 1 >> "$DATA/${1}.tmp.sfeed" mv "$DATA/${1}.tmp.sfeed" "${DATA}/${1}.sfeed" } @@ -53,8 +53,8 @@ cli_loop () { "sync"*) sync_handler $input ;; - "set"*) - set_handler $input + "open"*) + open_handler $input ;; esac } @@ -119,8 +119,25 @@ sync_handler () { fi } -set_handler () { - printf "stub, use +x or -x to disable/enable debug output\n" +open_handler() { + realargs="$(printf '%s\n' "$@" | tr '\n' ' ' | sed 's/^open //g;s/ $//g')" + [ -z "$MODE" ] && printf "couldn't find entry matching %s\n" "$realargs" + results="$(awk -F'\t' -v pat="$realargs" '$2 ~ pat { print $0 }' "$DATA/${MODE}.sfeed")" + + OLDIFS="$IFS" + IFS=" +" + + set -x + for i in $results; do + url="$(printf "%s" "$1" | awk -F'\t' '{ print $3 }')" + + echo "$url" + + fire "$url" & + done + set +x + IFS="$OLDIFS" } cat_handler () { @@ -138,8 +155,8 @@ cat_handler () { printf "%s\n" "$entry" | sed -e 's|\\n|\n|g' -e 's|\\t|\t|g' | lynx -stdin - done + IFS="$OLDIFS" } import_information From 9a81d916e55970039ec8c86c856f063a15a523ce Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 19 Jul 2022 14:46:42 -0500 Subject: [PATCH 160/197] add simple 'open' feature to open urls --- sh/trss | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sh/trss b/sh/trss index dc07b04..7afdae0 100755 --- a/sh/trss +++ b/sh/trss @@ -24,7 +24,11 @@ sync_individual () { # generate sfeed formatted file printf "> creating sfeed compound feed file for feed %s\n" "$1" - cat "$DATA/${1}.xml" | sfeed | cat - "$DATA/${1}.sfeed" | sort -u | sort -r -k 1 >> "$DATA/${1}.tmp.sfeed" + cat "$DATA/${1}.xml" | + sfeed | + cat - "$DATA/${1}.sfeed" | + sort -u | + sort -r -k 1 >> "$DATA/${1}.tmp.sfeed" mv "$DATA/${1}.tmp.sfeed" "${DATA}/${1}.sfeed" } @@ -120,7 +124,7 @@ sync_handler () { } open_handler() { - realargs="$(printf '%s\n' "$@" | tr '\n' ' ' | sed 's/^open //g;s/ $//g')" + realargs="$(printf '%s\n' "$@" | tr '\n' ' ' | sed 's/^open //g')" [ -z "$MODE" ] && printf "couldn't find entry matching %s\n" "$realargs" results="$(awk -F'\t' -v pat="$realargs" '$2 ~ pat { print $0 }' "$DATA/${MODE}.sfeed")" @@ -128,15 +132,13 @@ open_handler() { IFS=" " - set -x for i in $results; do - url="$(printf "%s" "$1" | awk -F'\t' '{ print $3 }')" + url="$(printf "%s" "$i" | awk -F'\t' '{ print $3 }')" echo "$url" fire "$url" & done - set +x IFS="$OLDIFS" } From 555b570d1d735854f1d8a11015c5f4a1ff4d7382 Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 19 Jul 2022 15:44:47 -0500 Subject: [PATCH 161/197] add a small optional section --- sh/trss | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/sh/trss b/sh/trss index 7afdae0..d7495e1 100755 --- a/sh/trss +++ b/sh/trss @@ -135,9 +135,18 @@ open_handler() { for i in $results; do url="$(printf "%s" "$i" | awk -F'\t' '{ print $3 }')" - echo "$url" - +# on low power systems mpv can be expensive to run +# have to figure out why it stutters so much more than the browser +# case "$url" in +# *youtube*) +# mpv "$url" +# ;; +# *) +# fire "$url" & +# ;; +# esac fire "$url" & + done IFS="$OLDIFS" } From c2073a8440b86999d2240143488a5de626535205 Mon Sep 17 00:00:00 2001 From: randomuser Date: Thu, 7 Jul 2022 23:03:24 -0500 Subject: [PATCH 162/197] add brightness and stuff --- Makefile | 1 + sh/brightness | 4 ++++ 2 files changed, 5 insertions(+) create mode 100755 sh/brightness diff --git a/Makefile b/Makefile index 4ac0c1f..497c292 100644 --- a/Makefile +++ b/Makefile @@ -35,6 +35,7 @@ sh: cp -f sh/net $(DESTDIR)$(PREFIX)/bin cp -f sh/bspwm-toggle-gaps $(DESTDIR)$(PREFIX)/bin cp -f sh/machine $(DESTDIR)$(PREFIX)/bin + cp -f sh/brightness $(DESTDIR)$(PREFIX)/bin check: shellcheck sh/* diff --git a/sh/brightness b/sh/brightness new file mode 100755 index 0000000..b431e44 --- /dev/null +++ b/sh/brightness @@ -0,0 +1,4 @@ +#!/bin/sh + +brightness=$(printf "250\n500\n1000\n2000\n3000\n4000\n" | tmenu) +st -c st-gpg-menu -e sh -c "sudo sh -c \"echo $brightness >> /sys/class/backlight/intel_backlight/brightness\"" From 0bc10fa4ef9af832b789fc7b8e81475c759c22e2 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 31 Jul 2022 22:42:20 -0500 Subject: [PATCH 163/197] almost works, but desktops on second monitor do not work --- sh/disp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/sh/disp b/sh/disp index 9222e02..61e24f3 100755 --- a/sh/disp +++ b/sh/disp @@ -4,6 +4,15 @@ exists() { xrandr | grep ' connected' | grep "${1}" | wc -l } +if [ $(exists "HDMI-2") -eq 1 ] && [ $(exists "LVDS-1") -eq 1 ]; then + printf "two" + xrandr --output HDMI-2 --right-of LVDS-1 --auto + xrandr --output VGA-1 --off --auto + bspc monitor LVDS-1 -d I II III IV V VI VII VIII IX X + bspc monitor HDMI-2 -d I II III IV V VI VII VIII IX X + exit 0 +fi + if [ $(exists "HDMI-2") -eq 1 ]; then printf "one" xrandr --output LVDS-1 --off --auto @@ -18,12 +27,3 @@ if [ $(exists "LVDS-1") -eq 1 ]; then bspc monitor LVDS-1 -a I II III IV V VI VII VIII IX exit 0 fi - -if [ $(exists "HDMI-2") -eq 1 ] && [ $(exists "LVDS-1") -eq 1 ]; then - printf "two" - xrandr --output HDMI-2 --above LVDS-1 --auto - xrandr --output VGA-1 --off --auto - bspc monitor LVDS-1 -a I III V VII IX - bspc monitor HDMI-2 -a II IV VI VIII - exit 0 -fi From d37e632bd8acdcdcb4e1e28893fe4c9db18c2a99 Mon Sep 17 00:00:00 2001 From: randomuser Date: Mon, 1 Aug 2022 18:32:00 -0500 Subject: [PATCH 164/197] reflect dotfile changes --- sh/disp | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/sh/disp b/sh/disp index 61e24f3..9e20d57 100755 --- a/sh/disp +++ b/sh/disp @@ -4,26 +4,15 @@ exists() { xrandr | grep ' connected' | grep "${1}" | wc -l } +bspc monitor -d 1 2 3 4 5 6 7 8 9 + if [ $(exists "HDMI-2") -eq 1 ] && [ $(exists "LVDS-1") -eq 1 ]; then printf "two" xrandr --output HDMI-2 --right-of LVDS-1 --auto xrandr --output VGA-1 --off --auto - bspc monitor LVDS-1 -d I II III IV V VI VII VIII IX X - bspc monitor HDMI-2 -d I II III IV V VI VII VIII IX X + bspc monitor LVDS-1 -d 1 2 3 4 5 6 7 8 9 + bspc monitor HDMI-2 -d 1 2 3 4 5 6 7 8 9 exit 0 fi -if [ $(exists "HDMI-2") -eq 1 ]; then - printf "one" - xrandr --output LVDS-1 --off --auto - xrandr --output VGA-1 --off --auto - bspc monitor -d I II III IV V VI VII VIII IX X - bspc monitor -g 1680x1050+0+0 - exit 0 -fi - -if [ $(exists "LVDS-1") -eq 1 ]; then - bspc monitor -d I II III IV V VI VII VIII IX X - bspc monitor LVDS-1 -a I II III IV V VI VII VIII IX - exit 0 -fi +# default configuration's fine From 6b5d621820e9d7a0bb63aa293d211160d61abcfe Mon Sep 17 00:00:00 2001 From: randomuser Date: Mon, 15 Aug 2022 18:42:26 -0500 Subject: [PATCH 165/197] improve anaconda.c make some changes to anaconda: -> fix memory leaks -> add tabs instead of spaces -> show score on screen -> adapt to different screen sizes --- c/anaconda.c | 297 +++++++++++++++++++++++++++++---------------------- 1 file changed, 171 insertions(+), 126 deletions(-) diff --git a/c/anaconda.c b/c/anaconda.c index fda09e7..2018e4c 100644 --- a/c/anaconda.c +++ b/c/anaconda.c @@ -8,15 +8,15 @@ #include typedef struct point { - double x; - double y; - struct point *next; + double x; + double y; + struct point *next; } point; typedef struct anaconda { - int score; - double rot; - struct point *chain; + int score; + double rot; + struct point *chain; } anaconda; Display *d; @@ -26,13 +26,13 @@ int s; GC gc; void xinit(void) { - d = XOpenDisplay(NULL); - s = DefaultScreen(d); - w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 100, 100, 1, - BlackPixel(d, s), WhitePixel(d, s)); - XSelectInput(d, w, ExposureMask | KeyPressMask | PointerMotionMask); - XMapWindow(d, w); - gc = XCreateGC(d, w, 0, NULL); + d = XOpenDisplay(NULL); + s = DefaultScreen(d); + w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 100, 100, 1, + BlackPixel(d, s), WhitePixel(d, s)); + XSelectInput(d, w, ExposureMask | KeyPressMask | PointerMotionMask); + XMapWindow(d, w); + gc = XCreateGC(d, w, 0, NULL); } /* thanks to @@ -41,162 +41,207 @@ void xinit(void) { */ int ccw(point *a, point *b, point *c) { - return (c->y - a->y) * (b->x - a->x) > - (b->y - a->y) * (c->x - a->x); + return (c->y - a->y) * (b->x - a->x) > + (b->y - a->y) * (c->x - a->x); } int intersect(point *a, point *b, point *c, point *d) { - return (ccw(a, c, d) != ccw(b, c, d)) && (ccw(a, b, c) != ccw(a, b, d)); + return (ccw(a, c, d) != ccw(b, c, d)) && (ccw(a, b, c) != ccw(a, b, d)); } int randrange(int b, int s) { - return rand() % (b - s + 1) + s; + return rand() % (b - s + 1) + s; } int eucliddist(point *a, point *b) { - return sqrt(pow(a->x - b->x, 2) + pow(a->y - b->y, 2)); + return sqrt(pow(a->x - b->x, 2) + pow(a->y - b->y, 2)); } point *mkPoint(double x, double y) { - point *ret = malloc(sizeof *ret); + point *ret = malloc(sizeof *ret); - ret->x = x; - ret->y = y; - ret->next = NULL; + ret->x = x; + ret->y = y; + ret->next = NULL; - return ret; + return ret; } point *rotate(point *p, double rot) { - double rad = rot * M_PI/180; + double rad = rot * M_PI/180; - return mkPoint( - p->x * cos(rad) - p->y * sin(rad), - p->x * sin(rad) + p->y * cos(rad) - ); + return mkPoint( + p->x * cos(rad) - p->y * sin(rad), + p->x * sin(rad) + p->y * cos(rad) + ); } void appendPoint(point *dest, point *origin) { - while(dest->next) dest = dest->next; - dest->next = origin; + while(dest->next) dest = dest->next; + dest->next = origin; } -int updateAnaconda(anaconda *anaconda, int w, int h, point *apple) { - point *temp, *new, *ptr; - new = anaconda->chain; - temp = rotate(mkPoint(10, 0), anaconda->rot); - new = mkPoint( - new->x + temp->x, - new->y + temp->y - ); - new->next = anaconda->chain; - anaconda->chain = new; +int updateAnaconda(anaconda *anaconda, point *basepoint, int w, int h, point *apple) { + point *temp, *new, *ptr; + new = anaconda->chain; - free(temp); + temp = rotate(basepoint, anaconda->rot); + new = mkPoint( + new->x + temp->x, + new->y + temp->y + ); + new->next = anaconda->chain; + anaconda->chain = new; - if(eucliddist(new, apple) <= 30) { - anaconda->score += 30; - apple->x = randrange(20, w / 2); - apple->y = randrange(20, h / 2); - } else { - ptr = new; + free(temp); - while(1) { - if(ptr->next) { - if(ptr->next->next) ptr = ptr->next; - else break; - } else break; - } - free(ptr->next); - ptr->next = NULL; - } + if(eucliddist(new, apple) <= 30) { + anaconda->score += 30; + apple->x = randrange(20, w / 2); + apple->y = randrange(20, h / 2); + } else { + ptr = new; - ptr = anaconda->chain; - for(int i = 0; i < 3; i++) { - if(ptr->next) ptr = ptr->next; - else return 1; /* we're fine, the snake is too short to intersect itself */ - } + while(1) { + if(ptr->next) { + if(ptr->next->next) ptr = ptr->next; + else break; + } else break; + } + free(ptr->next); + ptr->next = NULL; + } - while(ptr->next) { - if(intersect(new, new->next, ptr, ptr->next)) return 0; - ptr = ptr->next; - } + ptr = anaconda->chain; + for(int i = 0; i < 3; i++) { + if(ptr->next) ptr = ptr->next; + else return 1; /* we're fine, the snake is too short to intersect itself */ + } - if( - new->x >= w || new->x <= 0 || - new->y >= h || new->y <= 0 - ) return 0; + while(ptr->next) { + if(intersect(new, new->next, ptr, ptr->next)) return 0; + ptr = ptr->next; + } - if(eucliddist(new, apple) <= 30) { - anaconda->score += 30; - apple->x = randrange(20, w / 2); - apple->y = randrange(20, h / 2); - } + if( + new->x >= w || new->x <= 0 || + new->y >= h || new->y <= 0 + ) return 0; - return 1; + if(eucliddist(new, apple) <= 30) { + anaconda->score += 30; + apple->x = randrange(20, w / 2); + apple->y = randrange(20, h / 2); + } + + return 1; +} + +void freeAnaconda(anaconda *anaconda) { + point *current = anaconda->chain; + point *next = NULL; + for(;;) { + if(!current) break; + next = current->next; + free(current); + current = next; + } + + free(anaconda); + + return; } point *generateChain(int length) { - point *ret = mkPoint(100, 100); - point *head = ret; + point *ret = mkPoint(100, 100); + point *head = ret; - for(int i = 1; i < length - 1; i++) { - ret->next = mkPoint( - 10 * i + 100, - 5 * i + 100 - ); - ret = ret->next; - } + for(int i = 1; i < length - 1; i++) { + ret->next = mkPoint( + 10 * i + 100, + 5 * i + 100 + ); + ret = ret->next; + } - return head; + return head; } anaconda *mkAnaconda(point *point, double rot) { - anaconda *ret = malloc(sizeof *ret); + anaconda *ret = malloc(sizeof *ret); - ret->chain = point; - ret->rot = rot; - ret->score = 0; + ret->chain = point; + ret->rot = rot; + ret->score = 0; - return ret; + return ret; } int main(void) { - anaconda *anaconda = mkAnaconda(generateChain(30), 0); - xinit(); - srand(time(0)); - int width = DisplayWidth(d, s); - int height = DisplayHeight(d, s); - point *apple = mkPoint(randrange(20, width / 2 - 20), randrange(20, height / 2 - 20)); - while(1) { - if(!updateAnaconda(anaconda, width, height, apple)) { - return 0; - } - XClearWindow(d, w); - point *ptr = anaconda->chain; - while(ptr->next) { - XDrawLine(d, w, gc, ptr->x, ptr->y, ptr->next->x, ptr->next->y); - ptr = ptr->next; - } - printf("%f %f\n", apple->x, apple->y); - XDrawArc(d, w, gc, apple->x - (5/2), apple->y - (5/2), 5, 5, 0, 360*64); - while(XPending(d)) { - XNextEvent(d, &e); - switch(e.type) { - case KeyPress: - switch(e.xkey.keycode) { - case 113: /* left arrow key */ - anaconda->rot += 10; - break; - case 114: /* right arrow key */ - anaconda->rot -= 10; - break; - } - break; - } - } - usleep(100000); - } + anaconda *anaconda = mkAnaconda(generateChain(30), 0); + point *basepoint = mkPoint(10, 0); + char scorebuffer[30]; + xinit(); + srand(time(0)); + int width = DisplayWidth(d, s); + int height = DisplayHeight(d, s); + point *apple = mkPoint(randrange(20, width / 2 - 20), randrange(20, height / 2 - 20)); + int exposed = 0; + while(1) { + if(exposed) { + if(!updateAnaconda(anaconda, basepoint, width, height, apple)) { + freeAnaconda(anaconda); + free(apple); + free(basepoint); + return 0; + } + XClearWindow(d, w); + point *ptr = anaconda->chain; + while(ptr->next) { + XDrawLine(d, w, gc, ptr->x, ptr->y, ptr->next->x, ptr->next->y); + ptr = ptr->next; + } + XDrawArc(d, w, gc, apple->x - (5/2), apple->y - (5/2), 5, 5, 0, 360*64); + int len = snprintf(&scorebuffer, 30, "%i", anaconda->score); + XDrawString(d, w, gc, 25, 25, &scorebuffer, len); + } + while(XPending(d)) { + XNextEvent(d, &e); + switch(e.type) { + case KeyPress: + switch(e.xkey.keycode) { + case 113: /* left arrow key */ + anaconda->rot += 10; + break; + case 114: /* right arrow key */ + anaconda->rot -= 10; + break; + } + break; + case Expose: + /* hold off drawing until we get an expose event */ + exposed = 1; - return 0; + width = e.xexpose.width; + height = e.xexpose.height; + + if(apple->x > width) { + free(apple); + apple = mkPoint(randrange(20, width / 2 - 20), randrange(20, height / 2 - 20)); + } else if (apple->y > height) { + free(apple); + apple = mkPoint(randrange(20, width / 2 - 20), randrange(20, height / 2 - 20)); + } + + break; + } + } + usleep(100000); + } + + freeAnaconda(anaconda); + free(apple); + free(basepoint); + + return 0; } From 6a78941134f03cf2caa3c1d2c6b8827d276a85d5 Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 16 Aug 2022 20:42:57 -0500 Subject: [PATCH 166/197] make new modules for status --- sh/status | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sh/status b/sh/status index aeaa3cb..a4b71b8 100755 --- a/sh/status +++ b/sh/status @@ -25,6 +25,14 @@ mod_bspwm () { printf "%s" "$final_string" } +mod_period () { + nextclass +} + +mod_sensors () { + sensors | grep 'Core 0' | awk -F' ' '{print $3}' | tr -d '\n' +} + mod_power () { [ -z "$bat" ] || tr -d '\n' < /sys/class/power_supply/$bat/capacity @@ -50,7 +58,7 @@ get_mod () { echo_bar () { left="$(get_mod "bspwm")" - right="$(get_mod "date_time") $(get_mod "power") $(get_mod "vol")" + right="$(get_mod "date_time")$(get_mod "period") $(get_mod "sensors") $(get_mod "power") $(get_mod "vol")" width="$(tput cols)" rightwidth="${#right}" @@ -72,6 +80,8 @@ update_all () { update_mod vol update_mod bspwm update_mod date_time + update_mod period + update_mod sensors } tput civis From 24392d6a88df956f5a0316179f2299e35871dfcc Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 16 Aug 2022 20:43:44 -0500 Subject: [PATCH 167/197] add changes to tmenu --- sh/tmenu | 2 +- sh/tmenu-backend | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sh/tmenu b/sh/tmenu index cbfeec6..bff2038 100755 --- a/sh/tmenu +++ b/sh/tmenu @@ -3,6 +3,6 @@ file=$(mktemp) cat - > "$file" -st -c tmenu-prompt -g 40x10+0+0 -e tmenu-backend "$file" +st -c tmenu-prompt -g 40x10+0+0 -e tmenu-backend "$file" "$1" cat "$file" rm "$file" diff --git a/sh/tmenu-backend b/sh/tmenu-backend index cd2839b..28b755b 100755 --- a/sh/tmenu-backend +++ b/sh/tmenu-backend @@ -2,5 +2,5 @@ printf "%s" $1 -fzy < "$1" > "${1}a" +fzy $2 < "$1" > "${1}a" mv ${1}a ${1} From ed3d5a6d25b4f810fc6627eee8263bdb2e4e6ca8 Mon Sep 17 00:00:00 2001 From: randomuser Date: Wed, 14 Sep 2022 20:36:12 -0500 Subject: [PATCH 168/197] git credentials system --- Makefile | 1 + sh/git-credential-gitpass | 3 +++ 2 files changed, 4 insertions(+) create mode 100755 sh/git-credential-gitpass diff --git a/Makefile b/Makefile index 497c292..0f35f2f 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,7 @@ sh: cp -f sh/bspwm-toggle-gaps $(DESTDIR)$(PREFIX)/bin cp -f sh/machine $(DESTDIR)$(PREFIX)/bin cp -f sh/brightness $(DESTDIR)$(PREFIX)/bin + cp -f sh/git-credential-gitpass $(DESTDIR)$(PREFIX)/bin check: shellcheck sh/* diff --git a/sh/git-credential-gitpass b/sh/git-credential-gitpass new file mode 100755 index 0000000..749d7fb --- /dev/null +++ b/sh/git-credential-gitpass @@ -0,0 +1,3 @@ +#!/bin/sh + +printf "password=%s\n" "$(pash s tildegit)" From 8dce7054a61b9ed9ac7f4a388f72feaa0a786120 Mon Sep 17 00:00:00 2001 From: randomuser Date: Fri, 14 Oct 2022 13:39:55 -0500 Subject: [PATCH 169/197] add support for new computer --- sh/machine | 5 ++++- sh/statusbar | 8 +++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/sh/machine b/sh/machine index 9733ca7..3a77716 100755 --- a/sh/machine +++ b/sh/machine @@ -3,7 +3,7 @@ host="$(hostname)" case "$host" in - "mlg" | "think") + "mlg") exit 1 ;; "toaster") @@ -12,4 +12,7 @@ case "$host" in "fish") exit 3 ;; + "think") + exit 4 + ;; esac diff --git a/sh/statusbar b/sh/statusbar index d0f73b8..38a0ad3 100755 --- a/sh/statusbar +++ b/sh/statusbar @@ -2,6 +2,8 @@ machine -[ "$?" -eq 2 ] && - st -c statusbar -g 142x1+0+0 -e status || - st -c statusbar -g 195x1+0+0 -e status +res="$?" + +[ "$res" -eq 1 ] && st -c statusbar -g 274x1+0+0 -e status +[ "$res" -eq 2 ] && st -c statusbar -g 142x1+0+0 -e status +[ "$res" -eq 4 ] && st -c statusbar -g 195x1+0+0 -e status From db9413e1187cff81015d630df049990a8b31e787 Mon Sep 17 00:00:00 2001 From: randomuser Date: Thu, 10 Nov 2022 20:48:01 +0000 Subject: [PATCH 170/197] add updated statusbar --- sh/statusbar | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/sh/statusbar b/sh/statusbar index 38a0ad3..8230919 100755 --- a/sh/statusbar +++ b/sh/statusbar @@ -1,9 +1,21 @@ #!/bin/sh -machine +barwidth=20 -res="$?" +# remove all current statusbars +processes="$(ps aux | grep 'st -c' | grep 'status' | awk -F' ' '{print $2}')" +for i in $processes; do + pkill -P "$i" 2>&1 > /dev/null + kill $i +done -[ "$res" -eq 1 ] && st -c statusbar -g 274x1+0+0 -e status -[ "$res" -eq 2 ] && st -c statusbar -g 142x1+0+0 -e status -[ "$res" -eq 4 ] && st -c statusbar -g 195x1+0+0 -e status +# get all screens +screens="$(xrandr | grep ' connected' | sed 's/ primary//g' | awk -F' ' '{print $1 " " $3}')" + +# for every screen, create a statusbar +IFS=" +" +for i in $screens; do + screenstring=$(echo $i | awk -v a="$barwidth" -F'[ x+]' '{print $2 "x" a "+" $4 "+" $5}') + st -c statusbar -p -g "$screenstring" -e status & +done From 8c9020eec27a8d3335a5e841aa54530cae95da4b Mon Sep 17 00:00:00 2001 From: randomuser Date: Thu, 10 Nov 2022 20:51:19 +0000 Subject: [PATCH 171/197] slim down timer --- c/timer.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/c/timer.c b/c/timer.c index 3f19fd0..256570a 100644 --- a/c/timer.c +++ b/c/timer.c @@ -32,12 +32,12 @@ struct settings { .s = 0 }; -void timerdec(struct timer *t) { if (t->s != 0) t->s--; } +void timerdec(struct timer *t) { if (t->s) t->s--; } void timerinc(struct timer *t) { t->s++; } -void timerupdate(struct timer *t) { if(t->u != NULL) t->u(t); } +void timerupdate(struct timer *t) { if(t->u) t->u(t); } int timerstate(int (*f)(struct timer *t), struct timer *t) { - if(f != NULL) { + if(f) { if(f(t)) return 1; else return 0; } @@ -48,7 +48,7 @@ int timerstop(struct timer *t) { return timerstate(t->c, t); } int timerpause(struct timer *t) { return timerstate(t->p, t); } int timerzero(struct timer *t) { - if(t->s == 0) return 1; + if(!t->s) return 1; return 0; } @@ -68,13 +68,13 @@ struct timer *timerinit(void) { } int timerissettings(struct timer *t) { - if(t->s == 0) return 0; + if(!t->s) return 0; if(s.s == t->s) return 1; return 0; } int tomatotimer(struct timer *t) { - if(t->s != 0) return 0; + if(t->s) return 0; if(t->d % 2) t->s = s.s / 2; else t->s = s.s; t->d++; From a4cdc434be57ef2b87cab1b06219ddc30664d5f1 Mon Sep 17 00:00:00 2001 From: randomuser Date: Fri, 11 Nov 2022 11:31:20 +0000 Subject: [PATCH 172/197] remove trss, now using sfeed, lol --- Makefile | 1 - sh/trss | 176 ------------------------------------------------------- 2 files changed, 177 deletions(-) delete mode 100755 sh/trss diff --git a/Makefile b/Makefile index 0f35f2f..23a80de 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,6 @@ man: sh: mkdir -p $(DESTDIR)$(PREFIX)/bin cp -f sh/paste $(DESTDIR)$(PREFIX)/bin - cp -f sh/trss $(DESTDIR)$(PREFIX)/bin cp -f sh/trss-yt-id $(DESTDIR)$(PREFIX)/bin cp -f sh/disp $(DESTDIR)$(PREFIX)/bin cp -f sh/wallpaper $(DESTDIR)$(PREFIX)/bin diff --git a/sh/trss b/sh/trss deleted file mode 100755 index d7495e1..0000000 --- a/sh/trss +++ /dev/null @@ -1,176 +0,0 @@ -#!/bin/sh - -# get configuration & data directories -DATA="$HOME/.cache/trss" -CONFIG="$HOME/.config/trss" -MODE="" - -# make sure these directories are in place -mkdir -p "$DATA" -mkdir -p "$CONFIG" - -import_information () { - FEEDS="" - for i in "$CONFIG"/*; do - . "$i" - [ -z "$FEEDS" ] && FEEDS="$NAME" || FEEDS="$FEEDS $NAME" - done -} - -sync_individual () { - url="$(get_feed_attr "$1" feed)" - printf "> synchronizing feed %s via url %s\n" "$1" "$url" - curl "$url" -so "$DATA/${1}.xml" - - # generate sfeed formatted file - printf "> creating sfeed compound feed file for feed %s\n" "$1" - cat "$DATA/${1}.xml" | - sfeed | - cat - "$DATA/${1}.sfeed" | - sort -u | - sort -r -k 1 >> "$DATA/${1}.tmp.sfeed" - mv "$DATA/${1}.tmp.sfeed" "${DATA}/${1}.sfeed" -} - -synchronize () { - for i in $FEEDS; do - sync_individual "$i" - done -} - -get_feed_attr () { - eval "printf '%s' \${$1_$2}" -} - -cli_loop () { - read -p "$MODE\$ " input - case "$input" in - "ls"*) - ls_handler $input - ;; - "cd"*) - cd_handler $input - ;; - "cat"*) - cat_handler $input - ;; - "sync"*) - sync_handler $input - ;; - "open"*) - open_handler $input - ;; - esac -} - -ls_handler () { - if [ -z "$MODE" ]; then - # just list all the feeds - for i in $FEEDS; do - printf "%s\n" "$i" - done - else - # we have to list all the items in the feed - # check first if feed is downloaded - if [ -f "$DATA/${MODE}.sfeed" ]; then - awk -F'\t' '{ print $2 }' "$DATA/${MODE}.sfeed" - else - printf "synchronization of feed %s required\n" "$MODE" - fi - fi -} - -cd_handler () { - if [ -z "$MODE" ]; then - # we're in the home state - [ -z "$2" ] && return - [ "$2" = ".." ] && return - - # check if $2 is a valid feed - j=0 - for i in $FEEDS; do - [ "$2" = "$i" ] && j=1 - done - - if [ "$j" -ne 1 ]; then - printf "trss: couldn't find feed %s\n" "$2" - return - fi - - # set the $MODE to the feed - MODE="$2" - else - # we're in an individual feed - [ -z "$2" ] && MODE="" && return - [ "$2" = ".." ] && MODE="" && return - - printf "trss: couldn't find feed %s\n" "$2" - fi -} - -sync_handler () { - force=0 - [ "$2" = "-f" ] && force=1 - [ "$3" = "-f" ] && force=1 - - if [ -z "$MODE" ]; then - # sync everything - synchronize - else - [ -n "$2" ] && [ ! "$2" = "-f" ] && - sync_individual "$2" || - sync_individual "$MODE" - fi -} - -open_handler() { - realargs="$(printf '%s\n' "$@" | tr '\n' ' ' | sed 's/^open //g')" - [ -z "$MODE" ] && printf "couldn't find entry matching %s\n" "$realargs" - results="$(awk -F'\t' -v pat="$realargs" '$2 ~ pat { print $0 }' "$DATA/${MODE}.sfeed")" - - OLDIFS="$IFS" - IFS=" -" - - for i in $results; do - url="$(printf "%s" "$i" | awk -F'\t' '{ print $3 }')" - -# on low power systems mpv can be expensive to run -# have to figure out why it stutters so much more than the browser -# case "$url" in -# *youtube*) -# mpv "$url" -# ;; -# *) -# fire "$url" & -# ;; -# esac - fire "$url" & - - done - IFS="$OLDIFS" -} - -cat_handler () { - realargs="$(printf '%s\n' "$@" | tr '\n' ' ' | sed 's/^cat //g;s/ $//g')" - [ -z "$MODE" ] && printf "couldn't find entry matching %s\n" "$realargs" - results="$(awk -F'\t' -v pat="$realargs" '$2 ~ pat { print $0 }' "$DATA/${MODE}.sfeed")" - - OLDIFS="$IFS" - IFS=" -" - - for i in $results; do - entry="$(printf "%s" "$i" | awk -F'\t' '{ print $4 }')" - - printf "%s\n" "$entry" | - sed -e 's|\\n|\n|g' -e 's|\\t|\t|g' | - lynx -stdin - done - IFS="$OLDIFS" -} - -import_information -while true; do - cli_loop -done From 7410ddbfd1407d7a5a0758c5a9061a965e3da08d Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 13 Nov 2022 18:21:06 +0000 Subject: [PATCH 173/197] update trss-yt-id to sfeed_yt_add --- Makefile | 2 +- sh/sfeed_yt_add | 25 +++++++++++++++++++++++++ sh/trss-yt-id | 8 -------- 3 files changed, 26 insertions(+), 9 deletions(-) create mode 100755 sh/sfeed_yt_add delete mode 100755 sh/trss-yt-id diff --git a/Makefile b/Makefile index 23a80de..458d811 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ man: sh: mkdir -p $(DESTDIR)$(PREFIX)/bin cp -f sh/paste $(DESTDIR)$(PREFIX)/bin - cp -f sh/trss-yt-id $(DESTDIR)$(PREFIX)/bin + cp -f sh/ $(DESTDIR)$(PREFIX)/bin cp -f sh/disp $(DESTDIR)$(PREFIX)/bin cp -f sh/wallpaper $(DESTDIR)$(PREFIX)/bin cp -f sh/connect $(DESTDIR)$(PREFIX)/bin diff --git a/sh/sfeed_yt_add b/sh/sfeed_yt_add new file mode 100755 index 0000000..43c8a95 --- /dev/null +++ b/sh/sfeed_yt_add @@ -0,0 +1,25 @@ +#!/bin/sh + +[ -z "$1" ] && exit 1 +[ -z "$2" ] && exit 1 + +printf "[info] this utility is used for adding youtube urls as rss feeds\n" + +feed="$(curl ${1} -s | \ + grep 'youtube/www\.youtube\.com/channel/.\{24\}' -o | \ + awk -F'/' '{print "https://www.youtube.com/feeds/videos.xml?channel_id=" $NF}' | \ + sed 1q)" + +[ -z "$feed" ] && printf "[err] error processing the feed. are you sure it's *www*.youtube.com and not youtube.com?\n" && exit 1 + +tmp="$(mktemp)" + +sfeedrc="$HOME/.config/sfeed/sfeedrc" + +ed "$sfeedrc" <&2 - -looped=$(\ - cat $temp_output | \ - ( [ $randomize -eq 0 ] && shuf || cat ) | \ - ( [ $choose -ne 0 ] && head -n $choose || cat ) | \ - tr '\n' ' ' | \ - tr -d '\r' -) - -for i in $looped; do - ip=$(printf $i | awk -F':' '{print $1}') - port=$(printf $i | awk -F':' '{print $2}' | tr -d '\r') - - # TODO: timeout is a non-posix gnu extension, remove/replace it - timeout 2s nc -zv -x 127.0.0.1:$torport $ip $port 2>/dev/null 1>&2 && \ - outputted_proxies="$outputted_proxies $i" && \ - printf "success! %s\n" $i 1>&2 || \ - printf "failure! %s\n" $i 1>&2 -done - -if [ $output_as_proxychains -eq 0 ]; then - printf "# generated by proxtest.sh @ %s\n" "$(date)" - printf "random_chain\nproxy_dns\nchain_len = 5\n" - printf "tcp_read_time_out 15000\ntcp_connect_time_out 8000\n" - printf "[ProxyList]\n" - - # assumes all socks5 proxies, change this in future - for i in $outputted_proxies; do - printf "socks5 %s\n" "$(printf %s $i | tr ':' ' ')" - done - - printf "# finished!\n" -else - for i in $outputted_proxies; do - printf "%s\n" $i - done -fi From 8594f34cb6e5f666e99beca128909b876f2d212e Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 27 Nov 2022 17:04:53 +0000 Subject: [PATCH 176/197] add changes recommended/needed as indicated by shellcheck --- sh/connect | 19 ++++++++++--------- sh/disp | 4 ++-- sh/fire | 2 +- sh/git-survey | 9 ++++----- sh/net | 2 +- sh/nws | 31 +++++++++++++++++-------------- sh/pash-dmenu | 2 +- sh/sfeed_yt_add | 4 +--- sh/status | 6 +++--- sh/statusbar | 8 +++++--- sh/tmenu-backend | 6 +++--- sh/tmenu_run | 2 +- sh/vim-swap-handler | 2 +- sh/vol | 8 ++++---- sh/wallpaper | 30 +++++++++--------------------- 15 files changed, 63 insertions(+), 72 deletions(-) diff --git a/sh/connect b/sh/connect index d0e721f..c37240d 100755 --- a/sh/connect +++ b/sh/connect @@ -1,36 +1,37 @@ #!/bin/sh -[ "$(ps -aux | grep -c NetworkManager)" -eq 2 ] && \ - printf "NetworkManager is already running!" && \ +[ "$(pgrep -c NetworkManager)" -eq 1 ] && + printf "NetworkManager is already running!\n" && exit case $1 in "c"*) wpa_supplicant -iwlp3s0 -c/etc/wpa_supplicant/wpa_supplicant.conf -B dhcpcd wlp3s0 - tor & disown + # make tor and nohup shut up in a posix-compliant way + nohup tor >/dev/null 2>&1 ;; "d"*) killall -15 wpa_supplicant dhcpcd tor ;; "r"*) - sh $0 d - sh $0 c + sh "$0" d + sh "$0" c ;; "t"*) - [ $(ps aux | grep wpa_supplicant | wc -l) -eq 2 ] && sh $0 d && exit - sh $0 c + [ "$(pgrep -c wpa_supplicant)" -eq 1 ] && sh "$0" d && exit + sh "$0" c ;; "l"*) iw dev wlp3s0 scan | \ grep 'SSID\|signal' | \ - grep -v '* SSID List' | \ + grep -v 'SSID List' | \ awk -F': ' '{print $2}' | \ sed 'N;s/\n/ /' | \ grep -v '\x00' ;; *) - printf "\ + echo " simple wrapper for connecting to a network ${0} toggle to toggle wifi connection ${0} restart to restart wifi diff --git a/sh/disp b/sh/disp index 9e20d57..026da93 100755 --- a/sh/disp +++ b/sh/disp @@ -1,12 +1,12 @@ #!/bin/sh exists() { - xrandr | grep ' connected' | grep "${1}" | wc -l + xrandr | grep ' connected' | grep -c "${1}" } bspc monitor -d 1 2 3 4 5 6 7 8 9 -if [ $(exists "HDMI-2") -eq 1 ] && [ $(exists "LVDS-1") -eq 1 ]; then +if [ "$(exists "HDMI-2")" -eq 1 ] && [ "$(exists "LVDS-1")" -eq 1 ]; then printf "two" xrandr --output HDMI-2 --right-of LVDS-1 --auto xrandr --output VGA-1 --off --auto diff --git a/sh/fire b/sh/fire index 60903bf..298f915 100755 --- a/sh/fire +++ b/sh/fire @@ -1,3 +1,3 @@ #!/bin/sh -HOME="/home/usr/.local/share/firefox" firefox $@ +HOME="/home/usr/.local/share/firefox" firefox "$@" diff --git a/sh/git-survey b/sh/git-survey index 2dac26c..8f6b862 100755 --- a/sh/git-survey +++ b/sh/git-survey @@ -1,11 +1,10 @@ #!/bin/sh -for i in $(ls); do - cd $i +for i in *; do + cd "$i" || continue exists=$( - git status |\ - grep 'Your branch is ahead of ' |\ - wc -l + git status | + grep -c 'Your branch is ahead of ' ) [ "$exists" -eq 0 ] || printf "> %s\n" "$i" diff --git a/sh/net b/sh/net index 70b74a5..e79c8f9 100755 --- a/sh/net +++ b/sh/net @@ -1,4 +1,4 @@ #!/bin/sh # designed to be called from sxhkd (x session) -[ "$(pgrep NetworkManager)" ] && st -e nmtui +pgrep NetworkManager && st -e nmtui diff --git a/sh/nws b/sh/nws index b0f415e..056d52c 100755 --- a/sh/nws +++ b/sh/nws @@ -3,8 +3,8 @@ [ -z "${XDG_CONFIG_DIR}" ] && XDG_CONFIG_DIR="${HOME}/.config" [ -z "${NWS_CONFIG}" ] && NWS_CONFIG="${XDG_CONFIG_DIR}/nws" [ -n "${NWS_ZONE}" ] || \ - [ -e ${NWS_CONFIG} ] && NWS_ZONE=$(cat ${NWS_CONFIG}) || \ - NWS_ZONE="KGYX" + [ -e "${NWS_CONFIG}" ] && NWS_ZONE=$(cat "${NWS_CONFIG}") || + NWS_ZONE="KGYX" [ -z "${NWS_GIF}" ] && NWS_GIF="mpv --loop" [ -z "${NWS_TORIFY}" ] && NWS_TORIFY="" @@ -28,9 +28,9 @@ Torify wrapper: export NWS_TORIFY= " } err () { - printf "err: %s\n" ${1} + printf "err: %s\n" "${1}" [ -z "${2}" ] && exit 1 - exit ${2} + exit "${2}" } kstrip () { printf %s "$1" | sed 's/^K\(.*\)/\1/' @@ -46,7 +46,7 @@ mosaic () { ${NWS_GIF} "https://radar.weather.gov/ridge/lite/${1}_loop.gif" } setzone () { - printf "%s" "${1}" > ${NWS_CONFIG} + printf "%s" "${1}" > "${NWS_CONFIG}" } river () { textmessage "RVA" @@ -66,36 +66,39 @@ textmessage () { case $1 in "n"*) national - exit 0 ;; "l"*) localradar - exit 0 ;; "r"*) river - exit 0 ;; "w"*) weather - exit 0 ;; "m"*) - [ $# -eq 2 ] && mosaid $2 || \ + if [ "$#" -eq 2 ]; then + mosaid "$2" + else err "two args required" + fi ;; "s"*) - [ $# -eq 2 ] && setzone $2 || \ + if [ "$#" -eq 2 ]; then + setzone "$2" + else err "two args required" - exit 0 + fi ;; "t"*) - [ $# -eq 2 ] && textmessage $2 || \ + if [ "$#" -eq 2 ]; then + textmessage "$2" + else err "two args required" + fi ;; *) info - exit 0 ;; esac exit 0 diff --git a/sh/pash-dmenu b/sh/pash-dmenu index 2aa92ba..3929379 100755 --- a/sh/pash-dmenu +++ b/sh/pash-dmenu @@ -4,4 +4,4 @@ sel="$(pash l | tmenu)" [ "$?" -eq 1 ] && exit 0 # requires bspc rule -a st-gpg-menu state=floating -st -c st-gpg-menu -e pash-dmenu-backend $sel +st -c st-gpg-menu -e pash-dmenu-backend "$sel" diff --git a/sh/sfeed_yt_add b/sh/sfeed_yt_add index 43c8a95..4cd2937 100755 --- a/sh/sfeed_yt_add +++ b/sh/sfeed_yt_add @@ -5,15 +5,13 @@ printf "[info] this utility is used for adding youtube urls as rss feeds\n" -feed="$(curl ${1} -s | \ +feed="$(curl "$1" -s | \ grep 'youtube/www\.youtube\.com/channel/.\{24\}' -o | \ awk -F'/' '{print "https://www.youtube.com/feeds/videos.xml?channel_id=" $NF}' | \ sed 1q)" [ -z "$feed" ] && printf "[err] error processing the feed. are you sure it's *www*.youtube.com and not youtube.com?\n" && exit 1 -tmp="$(mktemp)" - sfeedrc="$HOME/.config/sfeed/sfeedrc" ed "$sfeedrc" <&1 > /dev/null - kill $i + pkill -P "$i" >/dev/null 2>&1 + kill "$i" done # get all screens @@ -16,6 +18,6 @@ screens="$(xrandr | grep ' connected' | sed 's/ primary//g' | awk -F' ' '{print IFS=" " for i in $screens; do - screenstring=$(echo $i | awk -v a="$barwidth" -F'[ x+]' '{print $2 "x" a "+" $4 "+" $5}') + screenstring=$(echo "$i" | awk -v a="$barwidth" -F'[ x+]' '{print $2 "x" a "+" $4 "+" $5}') st -c statusbar -p -g "$screenstring" -e status & done diff --git a/sh/tmenu-backend b/sh/tmenu-backend index 28b755b..02289d2 100755 --- a/sh/tmenu-backend +++ b/sh/tmenu-backend @@ -1,6 +1,6 @@ #!/bin/sh -printf "%s" $1 +printf "%s" "$1" -fzy $2 < "$1" > "${1}a" -mv ${1}a ${1} +fzy "$2" < "$1" > "${1}a" +mv "${1}a" "${1}" diff --git a/sh/tmenu_run b/sh/tmenu_run index 1b57921..cc42dca 100755 --- a/sh/tmenu_run +++ b/sh/tmenu_run @@ -4,7 +4,7 @@ tmenu_path () { IFS=" :" for i in $PATH; do for j in "$i"/*; do - [ -f $j ] && [ -x $j ] && printf "%s\n" $j + [ -f "$j" ] && [ -x "$j" ] && printf "%s\n" "$j" done done } diff --git a/sh/vim-swap-handler b/sh/vim-swap-handler index bf39d6c..06082af 100755 --- a/sh/vim-swap-handler +++ b/sh/vim-swap-handler @@ -19,7 +19,7 @@ desk=$( ) [ "$desk" = "none" ] && exit 1 -desk=$(($desk + 1)) +desk=$((desk + 1)) bspc desktop -f "^${desk}" killall -10 simplestatus diff --git a/sh/vol b/sh/vol index 0cd2572..7bcd832 100755 --- a/sh/vol +++ b/sh/vol @@ -1,16 +1,16 @@ #!/bin/sh -pulse=$(ps aux | grep pulseaudio | wc -l) +pulse=$(pgrep -c pulseaudio) [ "$1" = "inc" ] && sign="+" [ "$1" = "dec" ] && sign="-" [ "$#" -eq 0 ] && exit 1 -if [ "$pulse" -eq 2 ]; then - for SINK in `pacmd list-sinks | grep 'index:' | cut -b12-` +if [ "$pulse" -eq 1 ]; then + for SINK in $(pacmd list-sinks | grep 'index:' | cut -b12-) do - pactl set-sink-volume $SINK "${sign}5%" + pactl set-sink-volume "$SINK" "${sign}5%" done else amixer -c 0 set Master "5%${sign}" diff --git a/sh/wallpaper b/sh/wallpaper index 83fe25d..2b519eb 100755 --- a/sh/wallpaper +++ b/sh/wallpaper @@ -1,12 +1,11 @@ #!/bin/sh WALLDIR="${HOME}/.local/share/wallpapers" -TEEFILE="${WALLDIR}/.hist" BASECMD="feh --no-fehbg --bg-fill" generate_wall () { GENWALL=$( \ - ls $WALLDIR | \ + ls "$WALLDIR" | \ grep "." | \ shuf -n 1 ) @@ -19,26 +18,15 @@ wall () { done } displays () { - displays=$(xrandr | grep ' connected' | wc -l) -} -check () { - which $1 &>/dev/null + displays=$(xrandr | grep -c ' connected') } cmd="" -check "feh" || exit 1 -if check "xrandr"; then - displays - for i in $(seq 1 $displays); do - wall ${tmp} - tmp=${GENWALL} - echo ${GENWALL} ${i} | tee $TEEFILE - cmd="${cmd} ${GENWALL}" - done - eval ${BASECMD} ${cmd} -else - generate_wall - eval ${BASECMD} ${GENWALL} -fi -unset GENWALL BASECMD tmp cmd displays i +displays +for i in $(seq 1 "$displays"); do + wall "${tmp}" + tmp="${GENWALL}" + cmd="${cmd} ${GENWALL}" +done +eval "${BASECMD}" "${cmd}" exit 0 From bbe9174e885c9f685ad38402002eb273e731a1a7 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 27 Nov 2022 18:45:24 +0000 Subject: [PATCH 177/197] whoops, broke tmenu --- sh/tmenu | 2 +- sh/tmenu-backend | 2 +- sh/tmenu_run | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sh/tmenu b/sh/tmenu index bff2038..cbfeec6 100755 --- a/sh/tmenu +++ b/sh/tmenu @@ -3,6 +3,6 @@ file=$(mktemp) cat - > "$file" -st -c tmenu-prompt -g 40x10+0+0 -e tmenu-backend "$file" "$1" +st -c tmenu-prompt -g 40x10+0+0 -e tmenu-backend "$file" cat "$file" rm "$file" diff --git a/sh/tmenu-backend b/sh/tmenu-backend index 02289d2..c44defb 100755 --- a/sh/tmenu-backend +++ b/sh/tmenu-backend @@ -2,5 +2,5 @@ printf "%s" "$1" -fzy "$2" < "$1" > "${1}a" +fzy < "$1" > "${1}a" mv "${1}a" "${1}" diff --git a/sh/tmenu_run b/sh/tmenu_run index cc42dca..ac28a73 100755 --- a/sh/tmenu_run +++ b/sh/tmenu_run @@ -9,4 +9,4 @@ tmenu_path () { done } -tmenu_path | tmenu "$@" | ${SHELL:-"/bin/sh"} & +tmenu_path | tmenu | ${SHELL:-"/bin/sh"} & From 2dba69ed07ada45d3e4ceeac03fb0294abf34475 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 27 Nov 2022 18:47:08 +0000 Subject: [PATCH 178/197] change url for nws --- sh/nws | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sh/nws b/sh/nws index 056d52c..e1e52a1 100755 --- a/sh/nws +++ b/sh/nws @@ -43,7 +43,7 @@ localradar () { mosaic ${NWS_ZONE} } mosaic () { - ${NWS_GIF} "https://radar.weather.gov/ridge/lite/${1}_loop.gif" + ${NWS_GIF} "https://radar.weather.gov/ridge/standard/${1}_loop.gif" } setzone () { printf "%s" "${1}" > "${NWS_CONFIG}" From ca3faec6cec943baae51fd04e8e398edcb80c424 Mon Sep 17 00:00:00 2001 From: randomuser Date: Thu, 22 Dec 2022 15:31:19 -0600 Subject: [PATCH 179/197] change installation path --- Makefile | 7 +++---- config.mk | 2 ++ 2 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 config.mk diff --git a/Makefile b/Makefile index 6ec81c3..59dedfc 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,11 @@ +include config.mk all: mkc install: man sh c all .PHONY: man sh mkc c man: - # this used to be {command} $(DESTDIR)$(PREFIX)/man/man1 - # this did not work on my computer, but might be needed on other installations - mkdir -p /usr/local/man/man1 - cp -f man/* /usr/local/man/man1 + mkdir -p $(DESTDIR)$(PREFIX)/man/man1 + cp -f man/* $(DESTDIR)$(PREFIX)/man/man1 sh: mkdir -p $(DESTDIR)$(PREFIX)/bin diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..bcab3b0 --- /dev/null +++ b/config.mk @@ -0,0 +1,2 @@ +DESTDIR=$(HOME)/.local + From decef894bdd3adf991a7d96300ee32c9fc41aa6d Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 3 Jan 2023 23:28:16 -0600 Subject: [PATCH 180/197] add xgetnewwindow, which waits the creation of a new window in the xorg server --- c/xgetnewwindow.c | 29 +++++++++++++++++++++++++++++ man/xgetnewwindow.1 | 10 ++++++++++ 2 files changed, 39 insertions(+) create mode 100644 c/xgetnewwindow.c create mode 100644 man/xgetnewwindow.1 diff --git a/c/xgetnewwindow.c b/c/xgetnewwindow.c new file mode 100644 index 0000000..923ee64 --- /dev/null +++ b/c/xgetnewwindow.c @@ -0,0 +1,29 @@ +#include +#include + +int main(void) { + Display* display = XOpenDisplay(NULL); + if(!display) { + printf("Error: Unable to open display.\n"); + return 1; + } + + int screen = DefaultScreen(display); + Window root = RootWindow(display, screen); + + /* SubstructureNotifyMask allows us to be notified of CreateNotify events */ + XSelectInput(display, root, SubstructureNotifyMask); + + XEvent event; + for(;;) { + XNextEvent(display, &event); + if(event.type == CreateNotify) { + /* print window id */ + printf("0x%x\n", event.xcreatewindow.window); + break; + } + } + + XCloseDisplay(display); + return 0; +} diff --git a/man/xgetnewwindow.1 b/man/xgetnewwindow.1 new file mode 100644 index 0000000..8c5adab --- /dev/null +++ b/man/xgetnewwindow.1 @@ -0,0 +1,10 @@ +.TH XGETNEWWINDOW 1 xgetnewwindow +.SH NAME +xgetnewwindow +.SH SYNOPSIS +xgetnewwindow blocks until it recieves a CreateNotify event; that is, until a new window is created within the current Xorg instance. Once a new window is created, xgetnewwindow prints the window id (in hexadecimal) to stdout and exits. +.SH EXIT CODES +1 for abnormal termination, 0 for success. +.SH AUTHOR +randomuser + From 71ebc5f170a232fcf4b459fb510210590795305c Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 3 Jan 2023 23:28:40 -0600 Subject: [PATCH 181/197] oh yeah, add the makefile --- Makefile | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 59dedfc..0973123 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ sh: check: shellcheck sh/* -mkc: c/scream c/timer c/boid c/anaconda c/colors +mkc: c/scream c/timer c/boid c/anaconda c/colors c/xgetnewwindow c/boid: cc c/boid.c -o c/boid -lm -lX11 @@ -46,16 +46,21 @@ c/boid: c/anaconda: cc c/anaconda.c -o c/anaconda -lm -lX11 +c/xgetnewwindow: + cc c/xgetnewwindow.c -o c/xgetnewwindow -lX11 + c: cp -f c/scream $(DESTDIR)$(PREFIX)/bin cp -f c/timer $(DESTDIR)$(PREFIX)/bin cp -f c/boid $(DESTDIR)$(PREFIX)/bin cp -f c/anaconda $(DESTDIR)$(PREFIX)/bin cp -f c/colors $(DESTDIR)$(PREFIX)/bin + cp -f c/xgetnewwindow $(DESTDIR)$(PREFIX)/bin clean: - rm c/scream - rm c/timer - rm c/boid - rm c/anaconda - rm c/simplestatus + rm -f c/scream + rm -f c/timer + rm -f c/boid + rm -f c/anaconda + rm -f c/simplestatus + rm -f c/xgetnewwindow From 4fb280225e985e6389eac6785c42fa65971dabc8 Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 3 Jan 2023 23:28:57 -0600 Subject: [PATCH 182/197] misc changes --- .gitignore | 1 + sh/status | 3 +++ 2 files changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 02a7574..eac255e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.swp *.tmp c/scream +c/xgetnewwindow c/timer c/boid c/a.out diff --git a/sh/status b/sh/status index 53b2c62..7a31cef 100755 --- a/sh/status +++ b/sh/status @@ -7,6 +7,7 @@ power_prefix="/sys/class/power_supply/" [ "$(pgrep -c pulseaudio)" -eq 1 ] && ss="pulse" || ss="alsa" mod_bspwm () { + set -x used_desk=$(bspc query -D -d .occupied --names | tr '\n' ' ') current_desk=$(bspc query -D -d .focused --names) final_string="" @@ -23,6 +24,7 @@ mod_bspwm () { final_string=${final_string}"*$current_desk " printf "%s" "$final_string" + set +x } mod_period () { @@ -36,6 +38,7 @@ mod_sensors () { mod_power () { [ -z "$bat" ] || tr -d '\n' < /sys/class/power_supply/$bat/capacity + sed 's/Charging/↑/g;s/Discharging/↓/g;s/Full/-/g' < /sys/class/power_supply/$bat/status } mod_vol () { From 1d767b3377b529ebce9953562cb1d3be3b72a53a Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 3 Jan 2023 23:49:10 -0600 Subject: [PATCH 183/197] minor changes to status --- sh/status | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sh/status b/sh/status index 7a31cef..9512ab2 100755 --- a/sh/status +++ b/sh/status @@ -7,7 +7,6 @@ power_prefix="/sys/class/power_supply/" [ "$(pgrep -c pulseaudio)" -eq 1 ] && ss="pulse" || ss="alsa" mod_bspwm () { - set -x used_desk=$(bspc query -D -d .occupied --names | tr '\n' ' ') current_desk=$(bspc query -D -d .focused --names) final_string="" @@ -38,7 +37,7 @@ mod_sensors () { mod_power () { [ -z "$bat" ] || tr -d '\n' < /sys/class/power_supply/$bat/capacity - sed 's/Charging/↑/g;s/Discharging/↓/g;s/Full/-/g' < /sys/class/power_supply/$bat/status + sed 's/Charging/↑/g;s/Not charging/-/g;s/Discharging/↓/g;s/Full/-/g' < /sys/class/power_supply/$bat/status } mod_vol () { From 8e58e2cd777c1e6c25de8a6dbb8900564b77fcf8 Mon Sep 17 00:00:00 2001 From: randomuser Date: Wed, 4 Jan 2023 13:26:41 -0600 Subject: [PATCH 184/197] remove possibility for excess globbing in statusA --- sh/status | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sh/status b/sh/status index 9512ab2..6da8555 100755 --- a/sh/status +++ b/sh/status @@ -11,19 +11,19 @@ mod_bspwm () { current_desk=$(bspc query -D -d .focused --names) final_string="" current_printed=0 + cur_char='>' for i in $used_desk; do [ "$i" = "$current_desk" ] && \ - final_string=${final_string}"*$i " && \ + final_string=${final_string}"$cur_char$i " && \ current_printed=1 || \ final_string=${final_string}"$i " done [ $current_printed -eq 0 ] && - final_string=${final_string}"*$current_desk " + final_string=${final_string}"$cur_char$current_desk " printf "%s" "$final_string" - set +x } mod_period () { From 7bde5419e0962255c93198ec4c1e2dae59a99f40 Mon Sep 17 00:00:00 2001 From: randomuser Date: Wed, 4 Jan 2023 13:27:26 -0600 Subject: [PATCH 185/197] remove items from todo; no longer relevant --- TODO | 3 --- 1 file changed, 3 deletions(-) diff --git a/TODO b/TODO index a2d928c..0d8b47b 100644 --- a/TODO +++ b/TODO @@ -1,8 +1,5 @@ TODO LIST --------- -- change statusbar program so it uses static allocations instead of dynamic ones - fix paste - make the c programs less buggy and let them not suck as much -- add manpage for trss -- add option to *force* syncing From ad572313d06e76666fda687575389042352a6e4b Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 15 Jan 2023 16:48:49 -0600 Subject: [PATCH 186/197] add capture, migrate from bash/bashrc --- Makefile | 1 + sh/capture | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100755 sh/capture diff --git a/Makefile b/Makefile index 0973123..fceab0a 100644 --- a/Makefile +++ b/Makefile @@ -34,6 +34,7 @@ sh: cp -f sh/machine $(DESTDIR)$(PREFIX)/bin cp -f sh/brightness $(DESTDIR)$(PREFIX)/bin cp -f sh/git-credential-gitpass $(DESTDIR)$(PREFIX)/bin + cp -f sh/capture $(DESTDIR)$(PREFIX)/bin check: shellcheck sh/* diff --git a/sh/capture b/sh/capture new file mode 100755 index 0000000..b251669 --- /dev/null +++ b/sh/capture @@ -0,0 +1,60 @@ +#!/bin/sh + +# get screen info and temporary file +tmp=$(mktemp) +res=$(xrandr | + grep ' connected' | + awk -F' ' '{print $1 " " $4}' | + awk -F'+' '{print $1}' | + fzy | + awk -F' ' '{print $2}' ) + +# still or motion +medium=$(printf ".mp4\n.png\n" | fzy) +output="$tmp$medium" + +# capture +case "$medium" in + *mp4*) + printf "> starting video capture...\n" + ffmpeg -video_size "$res" -f x11grab -framerate 60 -i $DISPLAY -preset ultrafast -pix_fmt yuv420p "$output" + ;; + *png*) + printf "> taking screenshot...\n" + # for a screenshot, we usually want an a s t h e t i c + ffmpeg -f x11grab -video_size "$res" -i $DISPLAY -vframes 1 "$output" -loglevel quiet # be quiet + ;; + *) + printf "not a choice\n" + exit 1 +esac + +# what to do with the capture? +printf "> written to %s\n" "$output" +while true; do + result=$(printf "delete\nmove to home directory\nupload to pastebin\nreview footage\nquit\n" | fzy --prompt="what next? ") + case "$result" in + *upload*) + paste "$output" | xclip -i + printf "> pasted! check your clipboard\n" + ;; + *review*) + [ "$medium" = ".mp4" ] && mpv "$output" && continue + feh "$output" + ;; + *delete*) + printf "> removing target file...\n" + rm "$output" + exit 1 + ;; + *home*) + printf "> warping your capture to home...\n" + name=$(echo "capture$medium" | fzy --prompt="name please? ") + mv "$output" "$HOME/$name" + exit 1 + ;; + *quit*) + exit 1 + ;; + esac +done From 08e6b7a16c8c7c2f000cfdb6a7aa4e306b36e08b Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 15 Jan 2023 16:50:01 -0600 Subject: [PATCH 187/197] add alternate display configuration --- sh/disp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sh/disp b/sh/disp index 026da93..824559c 100755 --- a/sh/disp +++ b/sh/disp @@ -15,4 +15,13 @@ if [ "$(exists "HDMI-2")" -eq 1 ] && [ "$(exists "LVDS-1")" -eq 1 ]; then exit 0 fi +if [ "$(exists "HDMI-1")" -eq 1 ] && [ "$(exists "LVDS-1")" -eq 1 ]; then + printf "two" + xrandr --output HDMI-1 --right-of LVDS-1 --auto + xrandr --output VGA-1 --off --auto + bspc monitor LVDS-1 -d 1 2 3 4 5 6 7 8 9 + bspc monitor HDMI-1 -d 1 2 3 4 5 6 7 8 9 + exit 0 +fi + # default configuration's fine From 1196d794238b862c68babfa07e37bddadbf66838 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 15 Jan 2023 16:50:16 -0600 Subject: [PATCH 188/197] try out a new firefox wrapper. maybe it will work? --- sh/firew | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 sh/firew diff --git a/sh/firew b/sh/firew new file mode 100755 index 0000000..cfae372 --- /dev/null +++ b/sh/firew @@ -0,0 +1,41 @@ +#!/bin/sh +# wrapper script to make firefox suck less + +RHOME="${HOME}" + +firefox_data_location="$HOME/firefoxdumpster" +[ -z "$3" ] || url="$3" + +# start a profile chooser +if [ -z "$2" ]; then + profile=$(printf "programming\nschool\ntmp-school\ntmp\nchromium\n" | tmenu) +else + profile="$2" +fi + +[ -z "$profile" ] && exit + +if [ "$profile" = "tmp" ]; then + # firefox doesn't start in a directory within /tmp + # so we create one in $HOME/.cache + + tmp=$(basename $(mktemp)) + mkdir -p "${RHOME}/.cache/${tmp}" + rm -r "/tmp/$tmp" + HOME="/home/$(whoami)/.local/share/firefox" firefox --profile "${RHOME}/.cache/${tmp}" --no-remote "$url" + rm -r "${RHOME}/.cache/${tmp}" + exit +fi + +if [ "$profile" = "chromium" ]; then + HOME="/home/$(whoami)/.local/share/firefox" chromium + exit +fi + +# start firefox +mkdir -p "${firefox_data_location}/profile" +HOME="/home/$(whoami)/.local/share/firefox" firefox --profile "${firefox_data_location}/${profile}" --no-remote "$url" +exit + +printf "failed to specify a profile. exiting.\n" +exit 1 From a22c5fa20cb095e5d52cbff3c84aa331a3ad2e07 Mon Sep 17 00:00:00 2001 From: randomuser Date: Thu, 26 Jan 2023 13:33:05 -0600 Subject: [PATCH 189/197] add a contingency mode --- Makefile | 1 + sh/toggle-contingency-mode | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100755 sh/toggle-contingency-mode diff --git a/Makefile b/Makefile index fceab0a..334e13a 100644 --- a/Makefile +++ b/Makefile @@ -35,6 +35,7 @@ sh: cp -f sh/brightness $(DESTDIR)$(PREFIX)/bin cp -f sh/git-credential-gitpass $(DESTDIR)$(PREFIX)/bin cp -f sh/capture $(DESTDIR)$(PREFIX)/bin + cp -f sh/toggle-contingency-mode $(DESTDIR)$(PREFIX)/bin check: shellcheck sh/* diff --git a/sh/toggle-contingency-mode b/sh/toggle-contingency-mode new file mode 100755 index 0000000..9052a29 --- /dev/null +++ b/sh/toggle-contingency-mode @@ -0,0 +1,28 @@ +#!/bin/sh + +pid=$(pgrep sxhkd) + +for i in $pid; do + inv_id=$(cat /proc/$i/cmdline | awk -F'\0' '{print $3}') + + echo $inv_id + [ -z "$inv_id" ] && contingency_mode="off" + [ "$inv_id" = *"contingency" ] && contingency_mode="on" +done + +killall sxhkd + +trackpoint=$(xinput | grep "TrackPoint" | awk -F'\t' '{print $2}' | awk -F'=' '{print $2}') +touchpad=$(xinput | grep "TouchPad" | awk -F'\t' '{print $2}' | awk -F'=' '{print $2}') + +if [ "$contingency_mode" = "off" ]; then + sxhkd -c $HOME/.config/sxhkd/contingency & + xinput disable "$trackpoint" + xinput disable "$touchpad" + xmessage "contingency mode enabled." +else + sxhkd & + xinput enable "$trackpoint" + xinput enable "$touchpad" + killall xmessage +fi From 38a242c9991d35ddf514aa7bc3510be0b1624503 Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 31 Jan 2023 11:26:27 -0600 Subject: [PATCH 190/197] make tmenu_run faster by having an application name cache --- Makefile | 1 + sh/tmenu_run | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 334e13a..b6814b6 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,7 @@ sh: cp -f sh/git-credential-gitpass $(DESTDIR)$(PREFIX)/bin cp -f sh/capture $(DESTDIR)$(PREFIX)/bin cp -f sh/toggle-contingency-mode $(DESTDIR)$(PREFIX)/bin + ln -sf $(DESTDIR)$(PREFIX)/bin/tmenu_run $(DESTDIR)$(PREFIX)/bin/regenerate check: shellcheck sh/* diff --git a/sh/tmenu_run b/sh/tmenu_run index ac28a73..695e6b5 100755 --- a/sh/tmenu_run +++ b/sh/tmenu_run @@ -4,9 +4,15 @@ tmenu_path () { IFS=" :" for i in $PATH; do for j in "$i"/*; do - [ -f "$j" ] && [ -x "$j" ] && printf "%s\n" "$j" + [ -f "$j" ] && [ -x "$j" ] && printf "%s\n" "$j" | xargs basename done done } -tmenu_path | tmenu | ${SHELL:-"/bin/sh"} & +if [ "$1" = "-g" ] || [ "$(basename $0)" = "regenerate" ]; then + mkdir -p $HOME/.local/share + tmenu_path > $HOME/.local/share/tmenu_cache + xmessage "regeneration complete" +else + cat $HOME/.local/share/tmenu_cache | tmenu | ${SHELL:-"/bin/sh"} & +fi From 908cb7c24d6b292a59caa4bf3a361c00ccfdd0c3 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 2 Apr 2023 12:45:15 -0500 Subject: [PATCH 191/197] add a simple discord shortcut --- Makefile | 1 + sh/discord | 3 +++ 2 files changed, 4 insertions(+) create mode 100755 sh/discord diff --git a/Makefile b/Makefile index b6814b6..503175c 100644 --- a/Makefile +++ b/Makefile @@ -37,6 +37,7 @@ sh: cp -f sh/capture $(DESTDIR)$(PREFIX)/bin cp -f sh/toggle-contingency-mode $(DESTDIR)$(PREFIX)/bin ln -sf $(DESTDIR)$(PREFIX)/bin/tmenu_run $(DESTDIR)$(PREFIX)/bin/regenerate + cp -f sh/discord $(DESTDIR)$(PREFIX)/bin check: shellcheck sh/* diff --git a/sh/discord b/sh/discord new file mode 100755 index 0000000..45f1bf8 --- /dev/null +++ b/sh/discord @@ -0,0 +1,3 @@ +#!/bin/sh + +chromium --app=https://discord.com/login --profile-directory="Profile 1" From b3d186ee92aeb197c08e2c689acd40f820fffbfe Mon Sep 17 00:00:00 2001 From: randomuser Date: Mon, 10 Apr 2023 08:57:35 -0500 Subject: [PATCH 192/197] add two other program --- Makefile | 2 ++ sh/keyboard | 7 +++++++ sh/snapcad | 4 ++++ 3 files changed, 13 insertions(+) create mode 100755 sh/keyboard create mode 100755 sh/snapcad diff --git a/Makefile b/Makefile index 503175c..fc15a5d 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,7 @@ man: sh: mkdir -p $(DESTDIR)$(PREFIX)/bin cp -f sh/paste $(DESTDIR)$(PREFIX)/bin + cp -f sh/snapcad $(DESTDIR)$(PREFIX)/bin cp -f sh/sfeed_yt_add $(DESTDIR)$(PREFIX)/bin cp -f sh/disp $(DESTDIR)$(PREFIX)/bin cp -f sh/wallpaper $(DESTDIR)$(PREFIX)/bin @@ -36,6 +37,7 @@ sh: cp -f sh/git-credential-gitpass $(DESTDIR)$(PREFIX)/bin cp -f sh/capture $(DESTDIR)$(PREFIX)/bin cp -f sh/toggle-contingency-mode $(DESTDIR)$(PREFIX)/bin + cp -f sh/keyboard $(DESTDIR)$(PREFIX)/bin ln -sf $(DESTDIR)$(PREFIX)/bin/tmenu_run $(DESTDIR)$(PREFIX)/bin/regenerate cp -f sh/discord $(DESTDIR)$(PREFIX)/bin diff --git a/sh/keyboard b/sh/keyboard new file mode 100755 index 0000000..4917d4f --- /dev/null +++ b/sh/keyboard @@ -0,0 +1,7 @@ +#!/bin/sh + +setxkbmap -option caps:super +killall xcape +xcape -e 'Super_L=Escape' +xset -q | grep "Caps Lock:\s*on" && xdotool key Caps_Lock +xset r rate 200 40 diff --git a/sh/snapcad b/sh/snapcad new file mode 100755 index 0000000..8e6d344 --- /dev/null +++ b/sh/snapcad @@ -0,0 +1,4 @@ +#!/bin/sh +# opens snapcad + +wine ~/.wine/drive_c/Program\ Files\ \(x86\)/VEX\ Robotics/SnapCAD/SnapCAD.exe From bf5bfc71da250444686b02aa3c94d05167ced4c9 Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 6 Jun 2023 00:31:48 -0500 Subject: [PATCH 193/197] add tmessage application --- Makefile | 4 +- c/tmessage.c | 148 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 c/tmessage.c diff --git a/Makefile b/Makefile index fc15a5d..b02bbb7 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,7 @@ sh: check: shellcheck sh/* -mkc: c/scream c/timer c/boid c/anaconda c/colors c/xgetnewwindow +mkc: c/scream c/timer c/boid c/anaconda c/colors c/xgetnewwindow c/tmessage c/boid: cc c/boid.c -o c/boid -lm -lX11 @@ -62,6 +62,7 @@ c: cp -f c/anaconda $(DESTDIR)$(PREFIX)/bin cp -f c/colors $(DESTDIR)$(PREFIX)/bin cp -f c/xgetnewwindow $(DESTDIR)$(PREFIX)/bin + cp -f c/tmessage $(DESTDIR)$(PREFIX)/bin clean: rm -f c/scream @@ -70,3 +71,4 @@ clean: rm -f c/anaconda rm -f c/simplestatus rm -f c/xgetnewwindow + rm -f c/tmessage diff --git a/c/tmessage.c b/c/tmessage.c new file mode 100644 index 0000000..e696d4b --- /dev/null +++ b/c/tmessage.c @@ -0,0 +1,148 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#define ESC_CLEAR "\033[2J" +#define ESC_CUSHOME "\033[H" +#define ESC_NEWLINE "\033[E\033[1C" + +const char MSG_OK[] = "(O)k"; +const char MSG_CANCEL[] = "(C)ancel"; + +typedef struct winsize ws; + +int lines, cols; +char *message; +size_t message_len; + +struct termios original_termios; + +void render(char *message, int message_len, int lines, int cols); + +void rawmode_start() { + tcgetattr(STDIN_FILENO, &original_termios); + struct termios raw = original_termios; + raw.c_lflag &= ~(ECHO | ICANON); + tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw); +} + +void rawmode_stop() { + tcsetattr(STDIN_FILENO, TCSAFLUSH, &original_termios); + printf("\n\n"); + fflush(stdout); +} + +ws *getWinSize(void) { + /* we're only going to use these values once per invocation, + * so it's fine that it's static. */ + static ws w; + ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); + + return &w; +} + +void handler(int signal, siginfo_t *info, void *context) { + ws *w = getWinSize(); + lines = w->ws_row; + cols = w->ws_col; + + render(message, message_len, lines, cols); + return; +} + +void termhandler(int signal, siginfo_t *info, void *context) { + rawmode_stop(); + + return; +} + +int calculate_number_of_lines(int length, int cols) { + /* cols - 1 accounts for right padding */ + return length / (cols - 1) + 1; +} + +void go_to_initial_message_printing_pos(void) { + printf(ESC_CUSHOME "\033[1B\033[1C"); +} + +void print_message(char *message, int messagelen, int cols) { + int linecount = calculate_number_of_lines(messagelen, cols); + int adjcols = cols - 2; + int offset = 1; + for(int character = 0; character < messagelen; character++) { + if(character == adjcols * offset) { + printf(ESC_NEWLINE); + offset++; + } + putchar(message[character]); + } +} + +void render(char *message, int messagelen, int lines, int cols) { + int cancel_length = sizeof(MSG_CANCEL) / sizeof(MSG_CANCEL[0]); + + /* print the stuff */ + printf(ESC_CLEAR "" ESC_CUSHOME); + go_to_initial_message_printing_pos(); + print_message(message, message_len, cols); + + printf(ESC_NEWLINE); + printf(ESC_NEWLINE); + printf("%s", MSG_OK); + printf("\033[1D\033[%iC\033[%iD%s", cols, cancel_length, MSG_CANCEL); + fflush(stdout); +} + +int main(int argc, char **argv) { + int cancel_length = strlen(MSG_CANCEL); + char c; + struct sigaction resizeaction = {}; + struct sigaction termaction = {}; + ws *w; + + /* check if we have a message */ + if(argc > 1) { + message = argv[1]; /* second argument's a message */ + message_len = strlen(message); + } else { + return 1; + } + + /* setup sigaction handlers */ + resizeaction.sa_sigaction = &handler; + if(sigaction(SIGWINCH, &resizeaction, NULL) == -1) { + return 1; + } + + termaction.sa_sigaction = &termhandler; + if(sigaction(SIGTERM, &termaction, NULL) == -1) { + return 1; + } + + rawmode_start(); + + /* get window properties */ + w = getWinSize(); + lines = w->ws_row; + cols = w->ws_col; + + render(message, message_len, lines, cols); + + for(;;) { + read(STDIN_FILENO, &c, 1); + if(c == 'o') { + return 2; + rawmode_stop(); + } else if(c == 'c') { + return 3; + rawmode_stop(); + } + } + + return 0; +} From 1d9958c27f7f05180204b5ba4eb16252760aac06 Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 6 Jun 2023 00:33:39 -0500 Subject: [PATCH 194/197] improve clean target --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index b02bbb7..5c1023e 100644 --- a/Makefile +++ b/Makefile @@ -69,6 +69,7 @@ clean: rm -f c/timer rm -f c/boid rm -f c/anaconda + rm -f c/colors rm -f c/simplestatus rm -f c/xgetnewwindow rm -f c/tmessage From 400aa6ff4f4dbfd1eb610d50ff28035ac631c08a Mon Sep 17 00:00:00 2001 From: randomuser Date: Sat, 24 Jun 2023 16:41:18 -0500 Subject: [PATCH 195/197] update gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index eac255e..0976ab1 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ c/boid c/a.out c/anaconda c/colors +c/tmessage From b8a7ecad2d4d2b926059decd989d1cdd3f002874 Mon Sep 17 00:00:00 2001 From: randomuser Date: Fri, 7 Jul 2023 14:47:15 -0500 Subject: [PATCH 196/197] initial commit --- .merging_helper | 1 + 1 file changed, 1 insertion(+) create mode 100644 .merging_helper diff --git a/.merging_helper b/.merging_helper new file mode 100644 index 0000000..9daeafb --- /dev/null +++ b/.merging_helper @@ -0,0 +1 @@ +test From b272ffae99de5ed7cbd5f986281ba172a29a731c Mon Sep 17 00:00:00 2001 From: randomuser Date: Fri, 7 Jul 2023 14:54:19 -0500 Subject: [PATCH 197/197] move everything to utils directory in preparation for merge --- Makefile => utils/Makefile | 0 TODO => utils/TODO | 0 {c => utils/c}/anaconda.c | 0 {c => utils/c}/boid.c | 0 {c => utils/c}/colors.c | 0 {c => utils/c}/scream.c | 0 {c => utils/c}/timer.c | 0 {c => utils/c}/tmessage.c | 0 {c => utils/c}/xgetnewwindow.c | 0 config.mk => utils/config.mk | 0 {etc => utils/etc}/southwest_tracker.py | 0 {man => utils/man}/colors.1 | 0 {man => utils/man}/rndutils.1 | 0 {man => utils/man}/timer.1 | 0 {man => utils/man}/trss.1 | 0 {man => utils/man}/xgetnewwindow.1 | 0 {sh => utils/sh}/brightness | 0 {sh => utils/sh}/bspwm-toggle-gaps | 0 {sh => utils/sh}/capture | 0 {sh => utils/sh}/cfg | 0 {sh => utils/sh}/connect | 0 {sh => utils/sh}/discord | 0 {sh => utils/sh}/disp | 0 {sh => utils/sh}/fire | 0 {sh => utils/sh}/firew | 0 {sh => utils/sh}/git-credential-gitpass | 0 {sh => utils/sh}/git-survey | 0 {sh => utils/sh}/keyboard | 0 {sh => utils/sh}/machine | 0 {sh => utils/sh}/net | 0 {sh => utils/sh}/nws | 0 {sh => utils/sh}/pash-dmenu | 0 {sh => utils/sh}/pash-dmenu-backend | 0 {sh => utils/sh}/paste | 0 {sh => utils/sh}/pco | 0 {sh => utils/sh}/sfeed_yt_add | 0 {sh => utils/sh}/snapcad | 0 {sh => utils/sh}/ss | 0 {sh => utils/sh}/status | 0 {sh => utils/sh}/statusbar | 0 {sh => utils/sh}/tmenu | 0 {sh => utils/sh}/tmenu-backend | 0 {sh => utils/sh}/tmenu_run | 0 {sh => utils/sh}/toggle-contingency-mode | 0 {sh => utils/sh}/vim-swap-handler | 0 {sh => utils/sh}/vol | 0 {sh => utils/sh}/wallpaper | 0 47 files changed, 0 insertions(+), 0 deletions(-) rename Makefile => utils/Makefile (100%) rename TODO => utils/TODO (100%) rename {c => utils/c}/anaconda.c (100%) rename {c => utils/c}/boid.c (100%) rename {c => utils/c}/colors.c (100%) rename {c => utils/c}/scream.c (100%) rename {c => utils/c}/timer.c (100%) rename {c => utils/c}/tmessage.c (100%) rename {c => utils/c}/xgetnewwindow.c (100%) rename config.mk => utils/config.mk (100%) rename {etc => utils/etc}/southwest_tracker.py (100%) rename {man => utils/man}/colors.1 (100%) rename {man => utils/man}/rndutils.1 (100%) rename {man => utils/man}/timer.1 (100%) rename {man => utils/man}/trss.1 (100%) rename {man => utils/man}/xgetnewwindow.1 (100%) rename {sh => utils/sh}/brightness (100%) rename {sh => utils/sh}/bspwm-toggle-gaps (100%) rename {sh => utils/sh}/capture (100%) rename {sh => utils/sh}/cfg (100%) rename {sh => utils/sh}/connect (100%) rename {sh => utils/sh}/discord (100%) rename {sh => utils/sh}/disp (100%) rename {sh => utils/sh}/fire (100%) rename {sh => utils/sh}/firew (100%) rename {sh => utils/sh}/git-credential-gitpass (100%) rename {sh => utils/sh}/git-survey (100%) rename {sh => utils/sh}/keyboard (100%) rename {sh => utils/sh}/machine (100%) rename {sh => utils/sh}/net (100%) rename {sh => utils/sh}/nws (100%) rename {sh => utils/sh}/pash-dmenu (100%) rename {sh => utils/sh}/pash-dmenu-backend (100%) rename {sh => utils/sh}/paste (100%) rename {sh => utils/sh}/pco (100%) rename {sh => utils/sh}/sfeed_yt_add (100%) rename {sh => utils/sh}/snapcad (100%) rename {sh => utils/sh}/ss (100%) rename {sh => utils/sh}/status (100%) rename {sh => utils/sh}/statusbar (100%) rename {sh => utils/sh}/tmenu (100%) rename {sh => utils/sh}/tmenu-backend (100%) rename {sh => utils/sh}/tmenu_run (100%) rename {sh => utils/sh}/toggle-contingency-mode (100%) rename {sh => utils/sh}/vim-swap-handler (100%) rename {sh => utils/sh}/vol (100%) rename {sh => utils/sh}/wallpaper (100%) diff --git a/Makefile b/utils/Makefile similarity index 100% rename from Makefile rename to utils/Makefile diff --git a/TODO b/utils/TODO similarity index 100% rename from TODO rename to utils/TODO diff --git a/c/anaconda.c b/utils/c/anaconda.c similarity index 100% rename from c/anaconda.c rename to utils/c/anaconda.c diff --git a/c/boid.c b/utils/c/boid.c similarity index 100% rename from c/boid.c rename to utils/c/boid.c diff --git a/c/colors.c b/utils/c/colors.c similarity index 100% rename from c/colors.c rename to utils/c/colors.c diff --git a/c/scream.c b/utils/c/scream.c similarity index 100% rename from c/scream.c rename to utils/c/scream.c diff --git a/c/timer.c b/utils/c/timer.c similarity index 100% rename from c/timer.c rename to utils/c/timer.c diff --git a/c/tmessage.c b/utils/c/tmessage.c similarity index 100% rename from c/tmessage.c rename to utils/c/tmessage.c diff --git a/c/xgetnewwindow.c b/utils/c/xgetnewwindow.c similarity index 100% rename from c/xgetnewwindow.c rename to utils/c/xgetnewwindow.c diff --git a/config.mk b/utils/config.mk similarity index 100% rename from config.mk rename to utils/config.mk diff --git a/etc/southwest_tracker.py b/utils/etc/southwest_tracker.py similarity index 100% rename from etc/southwest_tracker.py rename to utils/etc/southwest_tracker.py diff --git a/man/colors.1 b/utils/man/colors.1 similarity index 100% rename from man/colors.1 rename to utils/man/colors.1 diff --git a/man/rndutils.1 b/utils/man/rndutils.1 similarity index 100% rename from man/rndutils.1 rename to utils/man/rndutils.1 diff --git a/man/timer.1 b/utils/man/timer.1 similarity index 100% rename from man/timer.1 rename to utils/man/timer.1 diff --git a/man/trss.1 b/utils/man/trss.1 similarity index 100% rename from man/trss.1 rename to utils/man/trss.1 diff --git a/man/xgetnewwindow.1 b/utils/man/xgetnewwindow.1 similarity index 100% rename from man/xgetnewwindow.1 rename to utils/man/xgetnewwindow.1 diff --git a/sh/brightness b/utils/sh/brightness similarity index 100% rename from sh/brightness rename to utils/sh/brightness diff --git a/sh/bspwm-toggle-gaps b/utils/sh/bspwm-toggle-gaps similarity index 100% rename from sh/bspwm-toggle-gaps rename to utils/sh/bspwm-toggle-gaps diff --git a/sh/capture b/utils/sh/capture similarity index 100% rename from sh/capture rename to utils/sh/capture diff --git a/sh/cfg b/utils/sh/cfg similarity index 100% rename from sh/cfg rename to utils/sh/cfg diff --git a/sh/connect b/utils/sh/connect similarity index 100% rename from sh/connect rename to utils/sh/connect diff --git a/sh/discord b/utils/sh/discord similarity index 100% rename from sh/discord rename to utils/sh/discord diff --git a/sh/disp b/utils/sh/disp similarity index 100% rename from sh/disp rename to utils/sh/disp diff --git a/sh/fire b/utils/sh/fire similarity index 100% rename from sh/fire rename to utils/sh/fire diff --git a/sh/firew b/utils/sh/firew similarity index 100% rename from sh/firew rename to utils/sh/firew diff --git a/sh/git-credential-gitpass b/utils/sh/git-credential-gitpass similarity index 100% rename from sh/git-credential-gitpass rename to utils/sh/git-credential-gitpass diff --git a/sh/git-survey b/utils/sh/git-survey similarity index 100% rename from sh/git-survey rename to utils/sh/git-survey diff --git a/sh/keyboard b/utils/sh/keyboard similarity index 100% rename from sh/keyboard rename to utils/sh/keyboard diff --git a/sh/machine b/utils/sh/machine similarity index 100% rename from sh/machine rename to utils/sh/machine diff --git a/sh/net b/utils/sh/net similarity index 100% rename from sh/net rename to utils/sh/net diff --git a/sh/nws b/utils/sh/nws similarity index 100% rename from sh/nws rename to utils/sh/nws diff --git a/sh/pash-dmenu b/utils/sh/pash-dmenu similarity index 100% rename from sh/pash-dmenu rename to utils/sh/pash-dmenu diff --git a/sh/pash-dmenu-backend b/utils/sh/pash-dmenu-backend similarity index 100% rename from sh/pash-dmenu-backend rename to utils/sh/pash-dmenu-backend diff --git a/sh/paste b/utils/sh/paste similarity index 100% rename from sh/paste rename to utils/sh/paste diff --git a/sh/pco b/utils/sh/pco similarity index 100% rename from sh/pco rename to utils/sh/pco diff --git a/sh/sfeed_yt_add b/utils/sh/sfeed_yt_add similarity index 100% rename from sh/sfeed_yt_add rename to utils/sh/sfeed_yt_add diff --git a/sh/snapcad b/utils/sh/snapcad similarity index 100% rename from sh/snapcad rename to utils/sh/snapcad diff --git a/sh/ss b/utils/sh/ss similarity index 100% rename from sh/ss rename to utils/sh/ss diff --git a/sh/status b/utils/sh/status similarity index 100% rename from sh/status rename to utils/sh/status diff --git a/sh/statusbar b/utils/sh/statusbar similarity index 100% rename from sh/statusbar rename to utils/sh/statusbar diff --git a/sh/tmenu b/utils/sh/tmenu similarity index 100% rename from sh/tmenu rename to utils/sh/tmenu diff --git a/sh/tmenu-backend b/utils/sh/tmenu-backend similarity index 100% rename from sh/tmenu-backend rename to utils/sh/tmenu-backend diff --git a/sh/tmenu_run b/utils/sh/tmenu_run similarity index 100% rename from sh/tmenu_run rename to utils/sh/tmenu_run diff --git a/sh/toggle-contingency-mode b/utils/sh/toggle-contingency-mode similarity index 100% rename from sh/toggle-contingency-mode rename to utils/sh/toggle-contingency-mode diff --git a/sh/vim-swap-handler b/utils/sh/vim-swap-handler similarity index 100% rename from sh/vim-swap-handler rename to utils/sh/vim-swap-handler diff --git a/sh/vol b/utils/sh/vol similarity index 100% rename from sh/vol rename to utils/sh/vol diff --git a/sh/wallpaper b/utils/sh/wallpaper similarity index 100% rename from sh/wallpaper rename to utils/sh/wallpaper