about summary refs log tree commit diff stats
path: root/bin
diff options
context:
space:
mode:
authorEnsa <psychoticfervor@tuta.io>2019-12-20 00:14:09 -0800
committerEnsa <psychoticfervor@tuta.io>2019-12-20 00:14:09 -0800
commit4684d80b6271dd775cd23dabf2b91d6ce56fa33a (patch)
treeddb6c6219e213132b8500e016b1ce238aa71029d /bin
parentf733ca7c8041866df27752c8e0c2610e0ecef6a7 (diff)
downloadcfg-4684d80b6271dd775cd23dabf2b91d6ce56fa33a.tar.gz
first significant commit
see README.md for information
Diffstat (limited to 'bin')
-rwxr-xr-xbin/comm-sel9
-rwxr-xr-xbin/lh37
-rwxr-xr-xbin/popmail71
-rwxr-xr-xbin/prompt10
-rwxr-xr-xbin/pw14
-rwxr-xr-xbin/rsschk16
-rwxr-xr-xbin/shenv6
-rwxr-xr-xbin/xbg14
8 files changed, 177 insertions, 0 deletions
diff --git a/bin/comm-sel b/bin/comm-sel
new file mode 100755
index 0000000..f67787f
--- /dev/null
+++ b/bin/comm-sel
@@ -0,0 +1,9 @@
+#!/bin/sh
+# sends a list of communication TUIs (e.g irssi) to dmenu and allows the user to choose one.
+# class "comm" is added to enable window managers (e.g dwm) to do specific things with them.
+case "$(dmenu_path|grep -E "irssi|6cord|scli$"|dmenu -p "choose chat app:")" in
+	irssi) $TERMINAL -c comm -e irssi --home=$XDG_CONFIG_HOME/irssi&;;
+	6cord) $TERMINAL -c comm -e 6cord&;;
+	scli) $TERMINAL -c comm -e scli&;;
+	*) notify-send "comm-sel error" "invalid program selection"&&return 1;;
+esac
diff --git a/bin/lh b/bin/lh
new file mode 100755
index 0000000..e4bdf0c
--- /dev/null
+++ b/bin/lh
@@ -0,0 +1,37 @@
+#!/bin/sh
+# lh: the Link Handler
+# takes one path or URL as its argument, launches the appropriate program for this.
+### differs from Luke Smith's linkhandler in cleaner code, inclusion of epub/pdf handling, proper interpretation of twitch video URLs, and livestream handling with streamlink (twitch only for now, tipping me off to URL schemes to look for for other streaming sites would be appreciated.)
+
+# if $1 isn't provided, spawn $BROWSER and exit. this allows lh to be used as a pseudo-browser.
+[ -z "$1" ] && exec "$BROWSER"
+
+case "$1" in
+	*mkv|*webm|*mp4)
+		mpv --input-ipc-server=/tmp/mpv-socket$(date +%s) --quiet "$1" >/dev/null 2>&1 & ;;
+	*youtube.com/watch*|*youtube.com/playlist*|*youtu.be*|*hooktube.com*|*bitchute.com*|*twitch.tv/videos/*)
+		mpv --input-ipc-server=/tmp/mpv-socket$(date +%s) --quiet --ytdl "$1" >/dev/null 2>&1 & ;;
+	*twitch.tv/*)
+		STREAMQUAL="$(streamlink "$1"|\
+			grep "Available streams"|tr " " "\n"|grep -E "[0-9]"|tr -d ,|\
+			dmenu -p "choose stream quality for $1")"
+		streamlink -p mpv $1 $STREAMQUAL >/dev/null 2>&1 & ;;
+	*png|*jpg|*jpe|*jpeg|*gif)
+		IMGPATH="/tmp/$(echo "$1"|sed "s/.*\\///")"
+		curl -sL "$1" >"$IMGPATH"&&sxiv -a "$IMGPATH">/dev/null 2>&1 & ;;
+	*mp3|*m4a|*flac|*aiff|*opus|*mp3?source*)
+		curl -LO "$1" >/dev/null 2>&1 & ;;
+	*epub|*pdf|*djvu)
+		BOOKPATH="/tmp/$(echo "$1"|sed "s/.*\\///")"
+		if [ -n "$READER" ]; then
+			curl -sL "$1" >"$BOOKPATH"&&$READER "$BOOKPATH">/dev/null 2>&1 &
+		else
+			curl -sL "$1" >"$BOOKPATH" &
+		fi ;;
+	*)
+		if [ -f "$1" ]; then
+			$TERMINAL -e "$EDITOR $1"
+		else
+			$BROWSER "$1" >/dev/null 2>&1 &
+		fi ;;
+esac
diff --git a/bin/popmail b/bin/popmail
new file mode 100755
index 0000000..d1bae9f
--- /dev/null
+++ b/bin/popmail
@@ -0,0 +1,71 @@
+#!/bin/sh
+# populate maildirs and give notification if there is new mail.
+# run only if all of the following is true:
+# 	user logged in (prevent cron errors)
+#	mbsync isn't already running
+#	there is an internet connection.
+if ! pgrep -u "${USER:=$LOGNAME}" >/dev/null; then
+	printf '%s not logged in. quitting...\n' "$USER" >/dev/stderr
+	exit
+elif pgrep -x mbsync >/dev/null; then
+	printf 'mbsync is already running. quitting...\n' >/dev/stderr
+	exit
+elif ! ping -q -c 1 1.1.1.1 >/dev/null; then
+	printf 'no internet connection, quitting...\n' >/dev/stderr
+fi
+
+export DISPLAY=:0
+# ensure touch file's directory exists
+if ! [ -d "$XDG_DATA_HOME/neomutt" ]; then
+	mkdir "$XDG_DATA_HOME/neomutt"
+fi
+# check account for new mail, notify for new content
+syncandnotify() {
+    # sanitize $account for use in function
+    acc="$(printf '%s\n' "$account" | sed "s/.*\///")"
+    mbsync "$acc">/dev/null 2>&1
+    # $new holds an index of all mail since the last time popmail ran
+    new=$(find "$XDG_DATA_HOME/mail/$acc/inbox/new/" -type f -newer "$XDG_DATA_HOME/neomutt/.popmail-last" 2> /dev/null)
+    # $newcount is the number of new mails
+    newcount=$(printf '%s\n' "$new" | sed '/^\s*$/d' | wc -l | tr -d " ")
+    # send $newcount to a file specific to $acc
+    # the preceding space makes generating a status bar string easier.
+    printf ' %s' "$newcount" > "$XDG_DATA_HOME/mail/$acc/note"
+    # don't notify if there isn't new mail
+    if [ "$newcount" -gt "0" ]; then
+        notify-send --app-name="popmail" "mail fetcher" "new mail for profile $acc! [$newcount]" &
+        for file in $new; do
+	    # broken lines, not sure what they're supposed to do
+            #from=$(awk '/^From: / && ++n ==1,/^\<.*\>:/' "$file" | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)' | awk '{ $1=""; if (NF>=3)$NF=""; print $0 }' | sed 's/^[[:blank:]]*[\"'\''\<]*//;s/[\"'\''\>]*[[:blank:]]*$//')
+            #subject=$(awk '/^Subject: / && ++n == 1,/^\<.*\>: / && ++i == 2' "$file" | sed '$D' | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)' | sed 's/^Subject: //' | sed 's/^{[[:blank:]]*[\"'\''\<]*//;s/[\"'\''\>]*[[:blank:]]*$//' | tr -d '\n')
+            # Extract subject and sender from mail.
+	    # modified version of broken $from variable, only prints the first from (so forwards are slightly unclear)
+	    from=$(awk '/^From: / && ++n ==1,/^\<.*\>:/' "$file" | awk '{ $1=""; if (NF>=3)$NF=""; print $0 }' | sed '1!d'| sed '1,/From/s/From: //')
+	    # modified version of broken $subject variable, only prints the first subject line (so forwards are slightly unclear)
+            subject=$(awk '/^Subject: / && ++n == 1,/^\<.*\>: / && ++i == 2' "$file" | sed '$D' | grep -m 1 '^Subject: ' | sed 's/Subject: //')
+            notify-send --app-name="popmail" "$from:" "$subject" &
+	    # sleep for half a second to avoid notification clog
+	    sleep .5
+        done
+    fi
+}
+
+# if popmail is given arguments, treat them as accounts to get mail from.
+# otherwise, scan the mbsync config to get account names
+if [ "$#" -eq "0" ]; then
+    accounts="$(awk '/^Group/ {print $2}' "$HOME/.mbsyncrc")"
+else
+    accounts=$*
+fi
+
+# call syncandnotify() for every account and background so it does all of them at once
+for account in $accounts
+do
+    syncandnotify &
+done
+
+wait
+# collect all previously created note files and collate them into a file that can be read by a status bar to notify the user of new mails
+printf "$(cat "$XDG_DATA_HOME"/mail/*/note|tr " " "|"|sed 's/|//')\n">"$XDG_DATA_HOME/mail/note"
+#create/update modification time on an empty file that indicates the time of the last run of popmail
+touch "$XDG_DATA_HOME/neomutt/.popmail-last"
diff --git a/bin/prompt b/bin/prompt
new file mode 100755
index 0000000..ac1a319
--- /dev/null
+++ b/bin/prompt
@@ -0,0 +1,10 @@
+#!/bin/sh
+# calls dmenu with $1 as the prompt and "no" and "yes" as the options.
+# if "yes" is chosen, call $2.
+if [ $# -eq 1 ]; then
+	case "$1" in
+		[!-]*|-*[!h]*) return 1 ;;
+		*h*) printf 'usage: %s [-h]|prompt cmd\n' "$(basename $0)">/dev/stderr&&return 1 ;;
+	esac
+fi
+[ "$(printf "no\\nyes"|dmenu -p "$1")" = "yes" ] && $2
diff --git a/bin/pw b/bin/pw
new file mode 100755
index 0000000..140f1dc
--- /dev/null
+++ b/bin/pw
@@ -0,0 +1,14 @@
+#!/bin/sh
+# generates a password of length $1, sends it to stdout if $2 isn't clip.
+# if it is clip, sends it to the X clipboard and clears it after 10 seconds.
+if [ "$1" = "-h" ]; then
+	printf 'usage: %s [-h]|LENGTH [clip]\n' "$(basename $0)">/dev/stderr&&return 1
+fi
+PW=$(tr -cd "[:alnum:][:punct:]"</dev/urandom|fold -w $1|head -1)
+if [ "$2" = "clip" ]; then
+	printf '%s' "$PW"|xclip -sel clip -i&&notify-send "Password Generated" "$1-character password generated. It will clear in 10 seconds."
+	sleep 10
+	printf "\0"|xclip -sel clip -i&&notify-send "Clipboard Cleared" "Generated password cleared from clipboard."
+else
+	printf '%s\n' "$PW"
+fi
diff --git a/bin/rsschk b/bin/rsschk
new file mode 100755
index 0000000..5a8de6e
--- /dev/null
+++ b/bin/rsschk
@@ -0,0 +1,16 @@
+#!/bin/sh
+# checks if $1 is a valid URL, and if so, checks to see if it's in newsboat's urls file, and if not, adds it to the file.
+if [ "$1" = "-h" ]; then
+	printf 'usage: rsschk [-h]|URL [\"category\"]\n'>/dev/stderr&&return 1
+fi
+XDG_CONFIG_HOME=${XDG_CONFIG_HOME:=~/.config}
+! echo "$1" | grep "http*://\S\+\.[A-Za-z]\+\S*" >/dev/null &&
+	notify-send "Invalid input. rsschk takes http(s) URLs as input." && exit
+RSSFILE="$XDG_CONFIG_HOME/newsboat/urls"
+if grep -E "^$1" "$RSSFILE"; then
+	if [ -z "$2" ]; then
+		echo "$1">>"$RSSFILE"&&notify-send "RSS feed added." "You may want to edit $RSSFILE now."
+	else
+		echo "$1 $2">>"$RSSFILE"&&notify-send "RSS feed added with one category."
+	fi
+fi
diff --git a/bin/shenv b/bin/shenv
new file mode 100755
index 0000000..b9428b8
--- /dev/null
+++ b/bin/shenv
@@ -0,0 +1,6 @@
+#!/bin/sh
+# simply sources the shrc and runs a shell with that as its environment.
+# passes through all arguments that sh takes. to be used instead of sh.
+XDG_CONFIG_DIR=${XDG_CONFIG_DIR:="$HOME/.config"}
+. $XDG_CONFIG_DIR/shrc
+exec sh "$@"
diff --git a/bin/xbg b/bin/xbg
new file mode 100755
index 0000000..bde015d
--- /dev/null
+++ b/bin/xbg
@@ -0,0 +1,14 @@
+#!/bin/sh
+# checks to see if .fehbg exists. if so, sources it and exits.
+# if there is an argument, forcibly symlink it to $PICPATH and set $PICPATH to the background using xwallpaper.
+# if there is not an argument, set the wallpaper through the aforementioned method without setting the symlink.
+# $PICPATH is by default $XDG_PICTURES_DIR/bg.png, determined by xdg-user-dir if available or assumed to be ~/Pictures/bg.png if unavailable. $PICPATH can be set by the user in shrc if they wish to use a different background location.
+[ -e "$HOME/.fehbg" ]&&. "$HOME/.fehbg"&&exit
+
+if command -v xdg-user-dir >/dev/null; then
+	PICPATH=${PICPATH:="$(xdg-user-dir PICTURES)/bg.png"}
+else
+	PICPATH=${PICPATH:="$HOME/Pictures/bg.png"}
+fi
+[ -n "$1" ]&&ln -sf "$1" "$PICPATH"
+xwallpaper --zoom "$PICPATH"