about summary refs log tree commit diff stats
path: root/bin
diff options
context:
space:
mode:
authorensa <psii@riseup.net>2020-06-29 19:45:18 -0700
committerensa <psii@riseup.net>2020-06-29 19:45:18 -0700
commite1d03e2fe607c5e1643be186c4ce4031ae1004e0 (patch)
treeee249107b5fb051f8d11e6c87e2e5e19775c5daa /bin
parenta11f7c357236afea1b00df5f85dc8674f5f1d661 (diff)
downloadcfg-e1d03e2fe607c5e1643be186c4ce4031ae1004e0.tar.gz
bin/fl added, lh reworked, opener renamed, data/applications removed
bin/
	fl: finds links, sends list to dmenu so user can choose one to copy to the
	clipboard
	lh:
		replaced sed invocations with lstrip() invocations
		redir handling changed to function findredir(), which loops over curl's
		output, only outputting location urls
		changed case statement to look for .extensions instead of the end of the url
		local files are now sent to bin/op for processing
		mpv given --no-terminal flag for no output instead of redirection shit
		similarly, sxiv is given -q (and -p to not cache)
	op:
		formerly opener
		changed error message to be more portable
	prompt:
		removed help text
	pw:
		doesn't need to be in a variable
	rsschk:
		redesigned after an eternity
		uses a modified re_urls, looking for .rss and .xml urls
		generally smaller
	shenv:
		uses ${var:=val}
		specifies /bin/sh
	xbg:
		removed .fehbg handling
config/
	aliasrc:
		e and v set TERM to xterm-256color, otherwise vis freaks out
	cwmrc:
		urgencyborder color added (with color1)
		ungroupborder changed to color5
		program list removed
		4-Return set to $TERMINAL
		4S-r rebound to restart
		4-X set to $LOCK
		prompt binds fixed
	dunst/dunstrc:
		icons disabled
	ksh/functions/l.:
		changed to ksh function
		for non-current directories, changes there in a subshell and uses that
		current directory, sending an error message if the directory doesn't exist
	lf/lfrc:
		cmd open removed
		cmd ttmsh fixed
	shrc:
		removed ALTSCR
		added OPENER=op
		IRC_SERVERS_FILE removed
		TODO changed to correct path
		GOCACHE and GOBIN added, self-explanatory
data/
	applications/:
		removed
	mailcap:
		changed to relegate most of its functionality to bin/op
Diffstat (limited to 'bin')
-rwxr-xr-xbin/fl32
-rwxr-xr-xbin/lh56
-rwxr-xr-xbin/op (renamed from bin/opener)4
-rwxr-xr-xbin/prompt6
-rwxr-xr-xbin/pw3
-rwxr-xr-xbin/rsschk21
-rwxr-xr-xbin/shenv4
-rwxr-xr-xbin/xbg3
8 files changed, 89 insertions, 40 deletions
diff --git a/bin/fl b/bin/fl
new file mode 100755
index 0000000..8c058d7
--- /dev/null
+++ b/bin/fl
@@ -0,0 +1,32 @@
+#!/bin/sh
+# fl: Find Links
+# uses regular expressions to find links in the stream it's given,
+# or its args if it is given args
+
+# from pure-sh-bible, strips from the start of a string
+lstrip() {
+	printf '%s\n' "${1##$2}"
+}
+
+# put url-finding regex in a variable so no lines go over 80 chars
+re_urls='((https?://|www\.)[[:alnum:].]*:?[[:alnum:]./@$&%?$#=_-]*)'
+
+# finds links, puts them in a list
+# sort -u prevents duplicates, but also sorts the links
+urlparse() {
+	lstrip "$(cat)" "*\│" |\
+	grep -Eo "$re_urls" |\
+	sort -u | sed 's|^www.|http://www\.|g'
+}
+if [ -n "$1" ]; then
+	urls=$(echo "$@"|urlparse)
+else
+	urls=$(urlparse)
+fi
+
+# wipe IFS so dmenu handles being sent the links properly
+IFS=
+
+# send any found links to dmenu so one can be chosen to be sent to the clipboard
+[ -n "$urls" ] &&\
+	echo $urls | dmenu -i -p 'copy which url?' -l 10 | xclip -r -sel c
\ No newline at end of file
diff --git a/bin/lh b/bin/lh
index e662589..4332487 100755
--- a/bin/lh
+++ b/bin/lh
@@ -1,10 +1,12 @@
 #!/bin/sh
 # lh: the Link Handler
-# takes one path or URL as its argument, launches the appropriate program for this.
+# takes one path or URL as its argument, launches the appropriate program for it
 
 # if $1 isn't provided, spawn $BROWSER and exit. this allows lh to be used as a pseudo-browser.
 [ -z "$1" ] && exec "$BROWSER"
 #from pure-sh-bible
+
+#splits a string by $2
 split() {
 	set -f
 	old_ifs=$IFS
@@ -14,32 +16,58 @@ split() {
 	IFS=$old_ifs
 	set +f
 }
+#strips from the right end of a string
+lstrip() {
+	printf '%s\n' "${1##$2}"
+}
+
+# redir unwinding
+# prints all redirect locations
+findredir() {
+	#note: for loop turns all whitespace into newlines
+	for line in $(curl -sIL "$1")
+	do
+		# catch is used to find the line after location:
+		if [ -n "$catch" ]
+		then
+			# return caught line
+			echo "$line"
+			# reset catch variable
+			unset -- catch
+		fi
+		# set catch if the current line is location
+		if echo "$line"|grep -Fq 'ocation:'
+		then
+			catch=1
+		fi
+	done
+}
 
 # handle redirects. tr removes control characters, so the case statement below works as expected.
-URL=$(curl -IL "$1"|grep '^location: '|tail -1|sed 's/location: //'|tr -d '[:cntrl:]')
+URL=$(findredir|tail -1|tr -d '[:cntrl:]')
+
 # if there were no redirects, just set URL to the first argument
 [ -z "$URL" ] && URL="$1"
 
-echo $URL
 case "$URL" in
 	gemini://*|gopher://*)
 		$TERMINAL -e bombadillo "$URL" ;;
-	*mkv|*webm|*mp4)
-		mpv "$URL" >/dev/null 2>&1 & ;;
+	*.mkv*|*.webm*|*.mp4*)
+		mpv --no-terminal "$URL" & ;;
 	*youtube.com/watch*|*youtube.com/playlist*|*youtu.be*|*hooktube.com*|*bitchute.com*|*twitch.tv/videos/*|*twitch.tv/*/v/*)
-		mpv --ytdl "$URL" >/dev/null 2>&1 & ;;
+		mpv --no-terminal --ytdl "$URL" & ;;
 	*twitch.tv/*)
 		STREAMQUAL="$(split "$(streamlink "$URL"|grep 'Available streams')" ", "|\
 			grep -E "[0-9]"|\
 			dmenu -p "choose stream quality for $URL")"
 		streamlink -p mpv $URL $STREAMQUAL >/dev/null 2>&1 & ;;
-	*png|*jpg|*jpe|*jpeg|*gif)
-		IMGPATH="/tmp/$(echo "$URL"|sed "s/.*\\///")"
-		curl -sL "$URL" >"$IMGPATH"&&sxiv -a "$IMGPATH">/dev/null 2>&1 & ;;
-	*mp3|*m4a|*flac|*aiff|*opus|*ogg|*mp3?source*)
-		mpv "$URL" >/dev/null 2>&1 & ;;
-	*epub|*pdf|*djvu)
-		BOOKPATH="/tmp/$(echo "$URL"|sed 's/.*\///')"
+	*.png*|*.jpg*|*.jpe*|*.jpeg*|*.gif*)
+		IMGPATH="/tmp/$(lstrip "$URL" "*/")"
+		curl -sL "$URL" >"$IMGPATH"&&sxiv -pqa "$IMGPATH" & ;;
+	*.mp3*|*.m4a*|*.flac*|*.aiff*|*.opus*|*.ogg*|*.mp3?source*)
+		mpv --no-terminal "$URL"& ;;
+	*.epub*|*.pdf*|*.djvu*)
+		BOOKPATH="/tmp/$(lstrip "$URL" "*/")"
 		if [ -n "$READER" ]; then
 			curl -sL "$URL" >"$BOOKPATH"&&$READER "$BOOKPATH">/dev/null 2>&1 &
 		else
@@ -47,7 +75,7 @@ case "$URL" in
 		fi ;;
 	*)
 		if [ -f "$URL" ]; then
-			$TERMINAL -e "${EDITOR:-vi} $URL"
+			op "$URL"
 		else
 			$BROWSER "$URL" >/dev/null 2>&1 &
 		fi ;;
diff --git a/bin/opener b/bin/op
index 4ae3446..688912b 100755
--- a/bin/opener
+++ b/bin/op
@@ -1,5 +1,5 @@
 #!/bin/sh
-# opener: opens files according to its contents
+# op: file OPener
 # takes one path as its argument, launches the appropriate program for it
 if ! [ -f "$1" ]; then
 	printf 'file %s does not exist!\n' "$1" >/dev/stderr
@@ -28,6 +28,6 @@ case "$FILEMIME" in
 		${EDITOR:-vi} "$FILEPATH">/dev/null 2>&1 & ;;
 	#catchall
 	*)
-		echo "file $(basename "$FILEPATH") could not be opened. its type is $FILEMIME, go tell ensa that opener didn't work" >/dev/stderr
+		echo "file $(basename "$FILEPATH") could not be opened. its type is $FILEMIME, go tell ensa that $(basename $0) didn't work" >/dev/stderr
 		return 1 ;;
 esac
diff --git a/bin/prompt b/bin/prompt
index ac1a319..fc0a07b 100755
--- a/bin/prompt
+++ b/bin/prompt
@@ -1,10 +1,4 @@
 #!/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
index fa33761..f7fd00a 100755
--- a/bin/pw
+++ b/bin/pw
@@ -1,4 +1,3 @@
 #!/bin/sh
 # generates a password of length $1.
-PW=$(tr -cd "[:alnum:][:punct:]"</dev/urandom|fold -w "$1"|head -1)
-printf '%s\n' "$PW"
+tr -cd "[:alnum:][:punct:]"</dev/urandom|fold -w "$1"|head -1
diff --git a/bin/rsschk b/bin/rsschk
index 5a8de6e..ab74169 100755
--- a/bin/rsschk
+++ b/bin/rsschk
@@ -1,16 +1,15 @@
 #!/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.
+# checks if $1 is a valid URL
+# if so, checks to see if it's in newsboat's urls file
+# 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 &&
+# regex for finding urls
+re_urls='https?://[[:alnum:].]*:?[[:alnum:]./@$&%?$#=_-]*\.(rss|xml)'
+
+! echo "$1" | grep -Eq "$re_urls" &&
 	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
+RSSFILE="${XDG_CONFIG_HOME:=~/.config}/newsboat/urls"
+grep -q "^$1" "$RSSFILE" &&
+	{ echo "$1">>"$RSSFILE"&&notify-send "RSS feed added.";}
diff --git a/bin/shenv b/bin/shenv
index d37733f..b242955 100755
--- a/bin/shenv
+++ b/bin/shenv
@@ -1,5 +1,5 @@
 #!/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.
-. ~/etc/shrc
-exec sh "$@"
+. ${XDG_CONFIG_HOME:=$HOME/.config}/shrc
+exec /bin/sh "$@"
diff --git a/bin/xbg b/bin/xbg
index bde015d..339ed69 100755
--- a/bin/xbg
+++ b/bin/xbg
@@ -1,10 +1,7 @@
 #!/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