make some things better #7
@ -1,7 +1,7 @@
 | 
				
			|||||||
#!/bin/sh
 | 
					#!/bin/sh
 | 
				
			||||||
 | 
					set -e
 | 
				
			||||||
 | 
					
 | 
				
			||||||
argv0="$0"
 | 
					argv0="$0"
 | 
				
			||||||
argv1="$1"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
# cats out the configuration or {'\n', EOF} if it can't be found
 | 
					# cats out the configuration or {'\n', EOF} if it can't be found
 | 
				
			||||||
stream_config(){
 | 
					stream_config(){
 | 
				
			||||||
@ -23,6 +23,11 @@ if ! command -v curl >/dev/null 2>&1; then
 | 
				
			|||||||
	exit 71 # sysexits(3) EX_OSERR
 | 
						exit 71 # sysexits(3) EX_OSERR
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# check if we have handlr(1), but we might not need it
 | 
				
			||||||
 | 
					if ! command -v handlr >/dev/null 2>&1; then
 | 
				
			||||||
 | 
						alias handlr=false
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
test -n "$BROWSER" || BROWSER="$(stream_config | sed -ne 's/^browser *= *//p')"
 | 
					test -n "$BROWSER" || BROWSER="$(stream_config | sed -ne 's/^browser *= *//p')"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# check if we have a $BROWSER
 | 
					# check if we have a $BROWSER
 | 
				
			||||||
@ -31,39 +36,44 @@ if ! test -n "$BROWSER"; then
 | 
				
			|||||||
%s: \$BROWSER not filled.
 | 
					%s: \$BROWSER not filled.
 | 
				
			||||||
	Please place the path to your default browser's executable in
 | 
						Please place the path to your default browser's executable in
 | 
				
			||||||
	/etc/xdg-sanity/xdg-sanity.conf
 | 
						/etc/xdg-sanity/xdg-sanity.conf
 | 
				
			||||||
" "$0"
 | 
					" "$argv0"
 | 
				
			||||||
	exit 71 # sysexits(3) EX_OSERR
 | 
						exit 71 # sysexits(3) EX_OSERR
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
MIME="$(curl -s -o /dev/null -w '%{content_type}' $1 | sed 's/\;.*//' | xargs echo)"
 | 
					while test -n "$1"; do
 | 
				
			||||||
 | 
						argv1="$1"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						# use curl(1) to write out the request header's content_type,
 | 
				
			||||||
 | 
						# strip everything after the first semicolon,
 | 
				
			||||||
 | 
						# chop off any weird whitespace remnants
 | 
				
			||||||
 | 
						MIME="$(curl -Ls -o /dev/null -w '%{content_type}' $1 | sed 's/\;.*//' | xargs echo)"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	# RESPONSE_CODE=$(curl -fLIs "$INPUT" | sed -ne 's/ [[:space:]]*$//p' | sed -ne 's|^HTTP/.\+ ||p')
 | 
						# RESPONSE_CODE=$(curl -fLIs "$INPUT" | sed -ne 's/ [[:space:]]*$//p' | sed -ne 's|^HTTP/.\+ ||p')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
for EXT in /etc/xdg-sanity/extensions/*.sh; do
 | 
						for extension in /etc/xdg-sanity/extensions/*.sh; do
 | 
				
			||||||
	if [ "$EXT" = "/etc/xdg-sanity/extensions/*.sh" ]; then
 | 
							! [ "$extension" = "/etc/xdg-sanity/extensions/*.sh" ] || break
 | 
				
			||||||
		echo "No extensions to load"
 | 
							# switch(extension_type)
 | 
				
			||||||
	else
 | 
							case "$(sed -ne 's/^# EXT-TYPE=//p' <"$extension" | xargs echo)" in
 | 
				
			||||||
		for EXT in /etc/xdg-sanity/extensions/*.sh; do
 | 
							replace)
 | 
				
			||||||
			TYPE=$(cat $EXT | sed -ne 's/^# EXT-TYPE=//p' | tr -d '\n')
 | 
								argv1="$("$extension" "$argv1")"
 | 
				
			||||||
			echo "Found $TYPE extension $EXT"
 | 
								;;
 | 
				
			||||||
 | 
							mime)
 | 
				
			||||||
			if [ "$TYPE" = "replace" ]; then
 | 
								argv1="$("$extension" "$argv1")"
 | 
				
			||||||
				echo "Modifying $INPUT..."
 | 
								;;
 | 
				
			||||||
				argv1=$($EXT "$argv1")
 | 
							esac
 | 
				
			||||||
				echo "Got $INPUT"
 | 
					 | 
				
			||||||
			elif [ "$TYPE" = "mime" ]; then
 | 
					 | 
				
			||||||
				echo "Modifying MIME type..."
 | 
					 | 
				
			||||||
				MIME="$($EXT "$argv1")"
 | 
					 | 
				
			||||||
				echo "Got $MIME"
 | 
					 | 
				
			||||||
			fi
 | 
					 | 
				
			||||||
		done
 | 
					 | 
				
			||||||
	fi
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	done
 | 
						done
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# determine the MIME type, strip everything after the first semicolon, and
 | 
						# these commands may fail; this is intentional
 | 
				
			||||||
# check to see if it's HTML
 | 
					 | 
				
			||||||
	if [ "$MIME" = "text/html" ]; then
 | 
						if [ "$MIME" = "text/html" ]; then
 | 
				
			||||||
	$BROWSER "$1"
 | 
							"$BROWSER" "$argv1"
 | 
				
			||||||
else
 | 
						elif ! handlr launch "$MIME" -- "$argv1"; then
 | 
				
			||||||
	handlr launch "$MIME" -- "$1"
 | 
							printf "%s: %s: handlr(1) failed: " "$argv0" "$argv1"
 | 
				
			||||||
 | 
							[ "$(command -v handlr)" = "false" ] \
 | 
				
			||||||
 | 
								&& printf "'handlr' program not found\n" \
 | 
				
			||||||
 | 
								|| printf "non-zero exit status\n"
 | 
				
			||||||
	fi
 | 
						fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						shift
 | 
				
			||||||
 | 
					done
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					exit 0
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user