commit efc1fe8c2f44ad6d8c57ccd33857765cc2680d5f
parent f73806d2edea6f5d2329d3b1f7d6925dde20ec7c
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date: Sat, 29 Aug 2020 11:34:00 -0700
Add scripts from bin repository
Diffstat:
11 files changed, 314 insertions(+), 0 deletions(-)
diff --git a/scripts/.local/bin/dp b/scripts/.local/bin/dp
@@ -0,0 +1,18 @@
+#!/usr/bin/env dash
+# simplify managing multiple monitors.
+
+set -eu
+
+usage()
+{
+ echo "usage, `basename $0` [output [output]]"
+ echo " specifying one output will turn it off, two"
+ echo " will setup the first left of the second."
+}
+
+case $#
+in
+ 2) xrandr --output "$1" --auto --left-of "$2";;
+ 1) xrandr --output "$1" --off;;
+ *) usage; exit 1;;
+esac
diff --git a/scripts/.local/bin/feed b/scripts/.local/bin/feed
@@ -0,0 +1,30 @@
+#!/usr/bin/env dash
+# manage viewing text/html rss feeds formatted by sfeed(1) in RSSTEXT
+# directory.
+
+# options:
+# default: match whole item
+# -f, list feed files
+# -l, list feeds with sfeed_plain
+# -n, get nth feed
+# -t, get title matches
+
+# format "title<tab>content<newline>" text.
+ffmt()
+{
+ awk -F'\t' '{ gsub(/\\t/, "\t", $0); gsub(/\\n+/, "<p>", $0); \
+ printf "<h1>%s</h1>%s\n", $1, $2 }' | html2text -style pretty
+}
+
+set -e
+
+case $1
+in
+ -h) echo "usage: `basename $0` -h | -f | -l | -n index | -t regex | regex | [file]";;
+ -f) ls -1 $RSSTEXT;;
+ -l) cut -f2 $RSSTEXT/${2:-*};;
+ -n) cat $RSSTEXT/${3:-*} | head -n "$2" | tail -1 | cut -f2,4 | ffmt;;
+ -t) awk -vOFS="\t" -vFS="\t" "match(tolower(\$2), \"$2\") > 0 \
+ { print \$2, \$4 }" $RSSTEXT/${3:-*} | ffmt;;
+ *) grep -i "$1" $RSSTEXT/${2:-*} | cut -f2,4 | ffmt;;
+esac
diff --git a/scripts/.local/bin/fsmenu b/scripts/.local/bin/fsmenu
@@ -0,0 +1,52 @@
+#!/usr/bin/env dash
+# navigate filesystem with dmenu.
+
+set -eu
+
+aflag=0
+pflag=0
+filter=""
+find_flags=""
+
+# display usage.
+usage()
+{
+ echo "usage: `basename $0` [-pah] [-t type]"
+ echo "\t-p, display given path in options"
+ echo "\t-a, don't hide dotfiles"
+ echo "\t-h, display usage and exit"
+ echo "\t-t, pass type argument to find(1)"
+}
+
+args=`getopt "t:pah" $*` || (usage; exit 2);
+set -- $args
+
+while [ $# -ne 0 ]
+do
+ case "$1"
+ in
+ -t) find_flags="-type $2"; shift 2;;
+ -a) aflag=1; shift;;
+ -p) pflag=1; shift;;
+ -h) usage; exit 2;;
+ --) shift; break;;
+ *) usage; exit 2;;
+ esac
+done
+
+# note that prefix is quoted in all situations intentionaly, that is because of
+# the basename and corrosponding -p flag which would break if multiple
+# directories were given.
+prefix="${@:-"."}"
+
+[ $aflag -eq 0 ] && filter="$filter | grep -ve '/\\\.'"
+[ $pflag -eq 0 ] && filter="$filter | sed -Ee \"s!^$prefix/?!!\" | grep -v '^$'"
+
+d="$(eval find "$prefix" $find_flags $filter | dmenu -l 10)"
+[ $pflag -eq 0 ] && d="$prefix/$d"
+if [ ! -e "$d" ]; then
+ echo "error: '$d': No such file or directory" 1>&2
+ exit 2
+else
+ echo "$d"
+fi
diff --git a/scripts/.local/bin/gp b/scripts/.local/bin/gp
@@ -0,0 +1,13 @@
+#!/usr/bin/env dash
+# copy password who's path matches regex.
+
+set -eu
+
+dir="${PASSWORD_STORE_DIR:-$HOME/.password-store}"
+# errexit prevents no match
+match="`find "$dir" -type f -name "*.gpg" | sed -E "s:^$dir/?(.*)\.gpg$:\1:g" | egrep $@`"
+
+echo "$match"
+if [ `echo "$match" | wc -l` -eq 1 ]; then
+ pass -c "$match"
+fi
diff --git a/scripts/.local/bin/loop b/scripts/.local/bin/loop
@@ -0,0 +1,31 @@
+#!/usr/bin/env dash
+# loops command indefinitly.
+
+# display usage
+usage()
+{
+ echo "usage, `basename $0` [-ih]"
+ echo "\t-i, interactive, prompt at each iteration"
+ echo "\t-e, errexit, exit on error"
+ echo "\t-h, usage"
+}
+
+while [ $# -ne 0 ]
+do
+ case $1
+ in
+ -i) interactive=1; shift;;
+ -e) set -e; shift;;
+ -h) usage; exit 0;;
+ *) break;;
+ esac
+done
+
+while true
+do
+ if [ ${interactive:=0} -eq 1 ]
+ then
+ read null || break
+ fi
+ eval $@
+done
diff --git a/scripts/.local/bin/mark b/scripts/.local/bin/mark
@@ -0,0 +1,19 @@
+#!/usr/bin/env dash
+# bookmarks via dmenu.
+
+# configuration
+dmenu() { command dmenu -l 10 ;}
+xclip() { command xclip -selection clipboard $* ;}
+
+if [ "$1" = "-h" ]
+then
+ echo "usage: `basename $0` [-a]"
+else
+ if [ "$1" = "-a" ]
+ then
+ cat `find $BOOKMARK -type f` | dmenu | xclip
+ else
+ dmenu < $BOOKMARK/`find $BOOKMARK -type f | awk -F"$BOOKMARK/?" '{print $2}' | dmenu` | xclip
+ fi
+ notify-send "`xclip -out`"
+fi
diff --git a/scripts/.local/bin/mps b/scripts/.local/bin/mps
@@ -0,0 +1,31 @@
+#!/usr/bin/env dash
+# save or restore mpd track at specific timestamp.
+
+set -eu
+
+case "${1:-"-s"}"
+in
+ -s)
+ file=${2:-"-"}
+ [ "$file" = "-" ] && file="/dev/stdout"
+ mpc current -f "%file%" | tr '\n' ',' > "$file"
+ mpc status | egrep -o "[0-9]+:[0-9]+/[0-9]+:[0-9]+" | cut -d"/" -f1 >> "$file";;
+ -l)
+ if [ $# -lt 2 ]; then
+ echo "No input specified." 1>&2
+ exit 1
+ elif [ ! -f "$2" ]; then
+ echo "File does not exist." 1>&2
+ exit 1
+ else
+ file="$2"
+ track="$(cut -d"," -f1 "$file")"
+ # if time is invalid unhandled error ocours due to mpc next
+ mpc -q insert "${track:?track does not exist}" && mpc -q next
+ mpc -q seek `cut -d"," -f2 "$file"`
+ fi;;
+ *)
+ echo "usage, `basename $0` [-sl]"
+ echo "\t-s, save state to file ('-' for stdout)"
+ echo "\t-l, load state from file";;
+esac
diff --git a/scripts/.local/bin/now b/scripts/.local/bin/now
@@ -0,0 +1,26 @@
+#!/usr/bin/env dash
+# print the current date, time, or both.
+
+set -eu
+
+# date and time formats
+date="%Y%m%d"
+time="%H%M%S"
+
+# display usage
+usage()
+{
+ echo "usage, `basename $0` [-fdt]"
+ echo "\t-f, display date and time"
+ echo "\t-d, display date"
+ echo "\t-t, display time"
+ echo "\t-h, display help and exit"
+}
+
+case ${1:-"-f"} in
+ -f) date +$date-$time;;
+ -d) date +$date;;
+ -t) date +$time;;
+ -h) usage; exit;;
+ *) echo "error: invalid argument" 1>&2; return 1;;
+esac
diff --git a/scripts/.local/bin/snap b/scripts/.local/bin/snap
@@ -0,0 +1,25 @@
+#!/usr/bin/env dash
+# take a screenshot in various ways.
+
+set -e
+
+# output
+path="$SCREENSHOT/`date +%Y%m%d-%H%M%S`.png"
+
+# display usage
+usage()
+{
+ echo "usage, `basename $0` [-fsw]"
+ echo "\t-f, select everything"
+ echo "\t-s, select region"
+ echo "\t-w, select window"
+ echo "\t-h, display usage and exit"
+}
+
+case ${1:-"-f"} in
+ -f) imlib2_grab "$path";;
+ -s) ffcast -s png "$path";;
+ -w) ffcast -w png "$path";;
+ -h) usage; exit;;
+ *) echo "error: invalid argument" 1>&2; exit 2;;
+esac
diff --git a/scripts/.local/bin/w3 b/scripts/.local/bin/w3
@@ -0,0 +1,34 @@
+#!/usr/bin/env dash
+# build a searx url from arguments either opening or outputing it.
+
+set -eu
+
+# configuration
+browser=w3m
+mirror=searx.prvcy.eu
+lang=en-US
+
+# display usage
+usage()
+{
+ echo "usage, `basename $0` [-oeh] [search-term ...]"
+ echo "\t-o, output url instead of opening"
+ echo "\t-e, use environment variable BROWSER"
+ echo "\t-h, display usage and exit"
+ echo "\narguments only interperated if first argument."
+}
+
+case "${1:-"-h"}"
+in
+ -o) output=1; shift;;
+ -e) browser=$BROWSER; shift;;
+ -h) usage; exit;;
+esac
+
+query="$(echo -n $@ | sed "s/ /%20/g")"
+if [ ${output:-0} -eq 1 ]
+then
+ echo "https://${mirror}/?q=${query}&categories=general&language=${lang}"
+else
+ $browser "https://${mirror}/?q=${query}&categories=general&language=${lang}"
+fi
diff --git a/scripts/.local/bin/webq b/scripts/.local/bin/webq
@@ -0,0 +1,35 @@
+#!/usr/bin/env dash
+# parse, cache, and display searx results.
+
+set -eu
+
+# settings
+user_agent="shell script to use searx without a browser"
+ttl=1024
+request_delay=12
+
+# display usage
+usage() { echo "usage, `basename $0` [query ...]" ;}
+
+if [ $# -eq 0 ]; then
+ usage; exit 1
+fi
+
+requests=0
+while [ $# -ne 0 ]
+do
+ # $1 is unquoted so extra whitespace is delt with.
+ query="$(echo -n $1 | sed -E "s/ /%20/g")"
+ cache="$HOME/.cache/webq/$query"
+ [ -f "$cache" ] && lifetime=$((`date +%s` - `stat -f %c $cache`)) || lifetime="-1"
+
+ if [ $lifetime -gt $ttl -o $lifetime -lt 0 ]; then
+ [ $requests -gt 0 ] && sleep $request_delay
+
+ # egrep removes suggestions and such.
+ curl -sSH "User-Agent: $user_agent" "$(w3 -o $1)&format=csv" | cut -d"," -f1,2 | egrep -v ",$" > "$cache"
+ requests=$(($requests + 1))
+ fi
+ cat "$cache"
+ shift
+done