(WIP) merge in upstream
This commit is contained in:
		
							parent
							
								
									ffcf3ad4b0
								
							
						
					
					
						commit
						2fce1e39ef
					
				
							
								
								
									
										109
									
								
								xdg-sanity.sh
									
									
									
									
									
								
							
							
						
						
									
										109
									
								
								xdg-sanity.sh
									
									
									
									
									
								
							@ -1,66 +1,69 @@
 | 
				
			|||||||
#!/bin/sh
 | 
					#!/bin/sh
 | 
				
			||||||
 | 
					
 | 
				
			||||||
INPUT=$(echo $1)
 | 
					argv0="$0"
 | 
				
			||||||
echo "Loading configuration..."
 | 
					argv1="$1"
 | 
				
			||||||
CONFIG=$(cat /etc/xdg-sanity/xdg-sanity.conf)
 | 
					 | 
				
			||||||
BROWSER=$(echo $CONFIG | sed -ne 's/^browser *= *//p')
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [ "$BROWSER" = "" ]
 | 
					# cats out the configuration or {'\n', EOF} if it can't be found
 | 
				
			||||||
then
 | 
					stream_config(){
 | 
				
			||||||
echo "Please place the path to your default browser's executable in /etc/xdg-sanity/xdg-sanity.conf"
 | 
						cat "$HOME"/.xdg-sanity.conf 2>/dev/null \
 | 
				
			||||||
exit
 | 
							|| cat "$HOME"/.config/xdg-sanity.conf 2>/dev/null \
 | 
				
			||||||
else
 | 
							|| cat /etc/xdg-sanity/xdg-sanity.conf 2>/dev/null \
 | 
				
			||||||
echo "Found default browser $BROWSER"
 | 
							|| echo # empty line
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# check if usage is valid
 | 
				
			||||||
 | 
					if ! test -n "$1"; then
 | 
				
			||||||
 | 
						printf "Usage: %s [resource...]\n" "$argv0"
 | 
				
			||||||
 | 
						exit 64 # sysexits(3) EX_USAGE
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
echo "Loading extensions..."
 | 
					# check if we have curl(1)
 | 
				
			||||||
for EXT in /etc/xdg-sanity/extensions/*.sh
 | 
					if ! command -v curl >/dev/null 2>&1; then
 | 
				
			||||||
do
 | 
						printf "%s: Missing dependency: curl(1)\n" "$argv0"
 | 
				
			||||||
 | 
						exit 71 # sysexits(3) EX_OSERR
 | 
				
			||||||
if [ "$EXT" = "/etc/xdg-sanity/extensions/*.sh" ]
 | 
					 | 
				
			||||||
then
 | 
					 | 
				
			||||||
echo "No extensions to load"
 | 
					 | 
				
			||||||
else
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
for EXT in /etc/xdg-sanity/extensions/*.sh
 | 
					 | 
				
			||||||
do
 | 
					 | 
				
			||||||
TYPE=$(cat $EXT | sed -ne 's/^# EXT-TYPE=//p' | tr -d '\n')
 | 
					 | 
				
			||||||
echo "Found $TYPE extension $EXT"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
if [ "$TYPE" = "replace" ]
 | 
					 | 
				
			||||||
then
 | 
					 | 
				
			||||||
echo "Modifying $INPUT..."
 | 
					 | 
				
			||||||
INPUT=$($EXT "$INPUT")
 | 
					 | 
				
			||||||
echo "Got $INPUT"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
else
 | 
					 | 
				
			||||||
if [ "$TYPE" = "mime" ]
 | 
					 | 
				
			||||||
then
 | 
					 | 
				
			||||||
echo "Modifying MIME type..."
 | 
					 | 
				
			||||||
MIME=$($EXT "$INPUT")
 | 
					 | 
				
			||||||
echo "Got $MIME"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
done
 | 
					test -n "$BROWSER" || BROWSER="$(stream_config | sed -ne 's/^browser *= *//p')"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# check if we have a $BROWSER
 | 
				
			||||||
 | 
					if ! test -n "$BROWSER"; then
 | 
				
			||||||
 | 
						printf "\
 | 
				
			||||||
 | 
					%s: \$BROWSER not filled.
 | 
				
			||||||
 | 
						Please place the path to your default browser's executable in
 | 
				
			||||||
 | 
						/etc/xdg-sanity/xdg-sanity.conf
 | 
				
			||||||
 | 
					" "$0"
 | 
				
			||||||
 | 
						exit 71 # sysexits(3) EX_OSERR
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					MIME="$(curl -s -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')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					for EXT in /etc/xdg-sanity/extensions/*.sh; do
 | 
				
			||||||
 | 
						if [ "$EXT" = "/etc/xdg-sanity/extensions/*.sh" ]; then
 | 
				
			||||||
 | 
							echo "No extensions to load"
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							for EXT in /etc/xdg-sanity/extensions/*.sh; do
 | 
				
			||||||
 | 
								TYPE=$(cat $EXT | sed -ne 's/^# EXT-TYPE=//p' | tr -d '\n')
 | 
				
			||||||
 | 
								echo "Found $TYPE extension $EXT"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if [ "$TYPE" = "replace" ]; then
 | 
				
			||||||
 | 
									echo "Modifying $INPUT..."
 | 
				
			||||||
 | 
									argv1=$($EXT "$argv1")
 | 
				
			||||||
 | 
									echo "Got $INPUT"
 | 
				
			||||||
 | 
								elif [ "$TYPE" = "mime" ]; then
 | 
				
			||||||
 | 
									echo "Modifying MIME type..."
 | 
				
			||||||
 | 
									MIME="$($EXT "$argv1")"
 | 
				
			||||||
 | 
									echo "Got $MIME"
 | 
				
			||||||
 | 
								fi
 | 
				
			||||||
 | 
							done
 | 
				
			||||||
 | 
						fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
done
 | 
					done
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [ "$MIME" = "" ] || [ "$MIME" = "$1" ] || [ "$MIME" = "$INPUT" ]
 | 
					# determine the MIME type, strip everything after the first semicolon, and
 | 
				
			||||||
then
 | 
					# check to see if it's HTML
 | 
				
			||||||
echo "Determining MIME type of $INPUT:"
 | 
					if [ "$MIME"= "text/html" ]; then
 | 
				
			||||||
# Determines HTTP code, might use for something else?
 | 
						$BROWSER "$1"
 | 
				
			||||||
# CODE=$(curl -fLIs "$INPUT" | sed -ne 's/ [[:space:]]*$//p' | sed -ne 's|^HTTP/.\+ ||p')
 | 
					 | 
				
			||||||
MIME=$(curl -fLIs "$INPUT" | sed -ne 's/^[cC]ontent-[tT]ype: //p' | sed -e 's/;.\+//p' | tail -n1 | tr -d '\r')
 | 
					 | 
				
			||||||
echo $MIME
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
if [ "$MIME" = "text/html" ]
 | 
					 | 
				
			||||||
then
 | 
					 | 
				
			||||||
$BROWSER $INPUT
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
else
 | 
					else
 | 
				
			||||||
handlr launch "$MIME" -- "$INPUT"
 | 
						handlr launch "$MIME" -- "$1"
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user