Compare commits
11 Commits
0.1
...
439ef97f29
| Author | SHA1 | Date | |
|---|---|---|---|
| 439ef97f29 | |||
| a10f4a3ceb | |||
| e11e73d8a6 | |||
| ffcf3ad4b0 | |||
| 1f912360e7 | |||
| fecb5e103e | |||
| 9a1c33d0d1 | |||
| 8c9b55bb96 | |||
| bc18380fec | |||
| bce239da30 | |||
| 2cfd97c158 |
37
README.md
37
README.md
@@ -1,9 +1,34 @@
|
|||||||
# xdg-sanity
|
# xdg-sanity
|
||||||
|
|
||||||
This script is built to replace your default web browser in your desktop/XDG
|
The `xdg-sanity` script is built to replace your default web browser in your
|
||||||
settings. It intercepts http/s URIs sent to the default browser by XDG settings
|
desktop/XDG settings. It intercepts http/s URIs sent to the default browser by
|
||||||
and sends it to the appropriate application. For example, it will send
|
`xdg-open` and sends it to the appropriate application. For example, it will
|
||||||
image/jpeg MIME type files to your image viewer.
|
send `image/jpeg` MIME type files to your image viewer.
|
||||||
|
|
||||||
Add your default web browser to `/etc/xdg-sanity.conf` so the script can forward
|
## Installation
|
||||||
links to it.
|
|
||||||
|
### Arch
|
||||||
|
|
||||||
|
I maintain a package [on the
|
||||||
|
AUR](https://aur.archlinux.org/packages/xdg-sanity).
|
||||||
|
|
||||||
|
### From Source
|
||||||
|
|
||||||
|
First, make sure you have `curl(1)` and `handlr(1)` installed. Then, clone this
|
||||||
|
repository and move the `xdg-sanity/` folder into `/etc` and `xdg-sanity.sh` to
|
||||||
|
`xdg-sanity` wherever your operating system stores locally-installed binaries.
|
||||||
|
This is usually `/usr/local/bin`. Make sure the installation location is in your
|
||||||
|
`$PATH`.
|
||||||
|
|
||||||
|
Create a `xdg-sanity.desktop` file either manually or with `gendesk(1)`,
|
||||||
|
placing it, also, where your OS stores locally-installed `.desktop` files,
|
||||||
|
usually `/usr/local/applications`. Set your default web browser to that
|
||||||
|
`.desktop` file.
|
||||||
|
|
||||||
|
Add your default web browser to `/etc/xdg-sanity/xdg-sanity.conf` so the
|
||||||
|
script can forward links to it.
|
||||||
|
|
||||||
|
### Usage
|
||||||
|
|
||||||
|
Open links from applications outside your web browser as normal. Alternatively,
|
||||||
|
you can call `xdg-sanity` directly with the only argument accepted being a URI.
|
||||||
@@ -1,17 +1,66 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
echo "Determining MIME type of $1:"
|
INPUT=$(echo $1)
|
||||||
|
echo "Loading configuration..."
|
||||||
|
CONFIG=$(cat /etc/xdg-sanity/xdg-sanity.conf)
|
||||||
|
BROWSER=$(echo $CONFIG | sed -ne 's/^browser *= *//p')
|
||||||
|
|
||||||
MIME=$(curl -I -s "$1" | sed -n -e 's/^[cC]ontent-[tT]ype: //p' | sed -e 's/;.\+//g' | tr -d '\r')
|
if [ "$BROWSER" = "" ]
|
||||||
|
then
|
||||||
|
echo "Please place the path to your default browser's executable in /etc/xdg-sanity/xdg-sanity.conf"
|
||||||
|
exit
|
||||||
|
else
|
||||||
|
echo "Found default browser $BROWSER"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Loading extensions..."
|
||||||
|
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..."
|
||||||
|
INPUT=$($EXT "$INPUT")
|
||||||
|
echo "Got $INPUT"
|
||||||
|
|
||||||
|
else
|
||||||
|
if [ "$TYPE" = "mime" ]
|
||||||
|
then
|
||||||
|
echo "Modifying MIME type..."
|
||||||
|
MIME=$($EXT "$INPUT")
|
||||||
|
echo "Got $MIME"
|
||||||
|
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "$MIME" = "" ] || [ "$MIME" = "$1" ] || [ "$MIME" = "$INPUT" ]
|
||||||
|
then
|
||||||
|
echo "Determining MIME type of $INPUT:"
|
||||||
|
# Determines HTTP code, might use for something else?
|
||||||
|
# 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
|
echo $MIME
|
||||||
|
fi
|
||||||
BROWSER=$(cat /etc/xdg-sanity.conf | sed -n -e 's/^browser = //p' )
|
|
||||||
|
|
||||||
if [ "$MIME" = "text/html" ]
|
if [ "$MIME" = "text/html" ]
|
||||||
then
|
then
|
||||||
$BROWSER $1
|
$BROWSER $INPUT
|
||||||
|
|
||||||
else
|
else
|
||||||
handlr launch "$MIME" -- "$1"
|
handlr launch "$MIME" -- "$INPUT"
|
||||||
fi
|
fi
|
||||||
12
xdg-sanity/extensions/teddit-mime.sample
Executable file
12
xdg-sanity/extensions/teddit-mime.sample
Executable file
@@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# EXT-TYPE=mime
|
||||||
|
|
||||||
|
TEST=$(echo $1 | sed -ne 's/^h.\+\/\///p' | sed -e 's/\/.*\+//g')
|
||||||
|
|
||||||
|
if [ "$TEST" = "teddit.net" ]
|
||||||
|
then
|
||||||
|
echo "text/html"
|
||||||
|
else
|
||||||
|
echo $1
|
||||||
|
fi
|
||||||
3
xdg-sanity/extensions/youtube-replace
Executable file
3
xdg-sanity/extensions/youtube-replace
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
# EXT-TYPE=replace
|
||||||
|
|
||||||
|
replace youtube.com or youtu.be with piped.mint.lgbt
|
||||||
12
xdg-sanity/extensions/youtube-replace.sample
Executable file
12
xdg-sanity/extensions/youtube-replace.sample
Executable file
@@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# EXT-TYPE=replace
|
||||||
|
|
||||||
|
TEST=$(echo $1 | sed -ne 's/^h.\+\/\///p' | sed -e 's/\/.*\+//g')
|
||||||
|
|
||||||
|
if [ "$TEST" = "youtube.com" ]
|
||||||
|
then
|
||||||
|
echo $1 | sed -ne 's/youtube.com/piped.mint.lgbt/p'
|
||||||
|
else
|
||||||
|
echo $1
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user