added scheme extensions and fixed URIs only remembering their domains when replaced.
This commit is contained in:
parent
da348f82f2
commit
ada7c6976f
26
README.md
26
README.md
@ -39,29 +39,39 @@ Extensions are written using TOML and are stored in either
|
|||||||
Extension support requires the installation of the `tomcat(1)` tool, which
|
Extension support requires the installation of the `tomcat(1)` tool, which
|
||||||
parses TOML for the command line.
|
parses TOML for the command line.
|
||||||
|
|
||||||
There are two types of extensions: MIME and replace. MIME extensions are parsed
|
There are three kinds of extensions: MIME, replace, and scheme. MIME extensions
|
||||||
first and replace the MIME type of the content being fetched. Replace extensions
|
are parsed first and replace the MIME type of the content being fetched. Replace
|
||||||
change the URI passed to the command to another.
|
extensions change the URI passed to the command to another. Scheme extensions
|
||||||
|
replace the protocol by which the URI hostname is being accessed.
|
||||||
|
|
||||||
The type of the extension depends on the file name. MIME extensions should have
|
The type of the extension depends on the file name. MIME extensions should have
|
||||||
a name ending in `-mime.toml` and replace extensions should have
|
a name ending in `.mime.toml`, replace extensions should have
|
||||||
`-replace.toml`.
|
`.replace.toml`, and scheme extensions should end with `.scheme.toml`.
|
||||||
|
|
||||||
Here's what a MIME extension looks like:
|
Here's what a MIME extension looks like:
|
||||||
```
|
```
|
||||||
$ cat $XDG_DATA_HOME/xdg-sanity/youtube-mime.toml
|
$ cat $XDG_DATA_HOME/xdg-sanity/youtube.mime.toml
|
||||||
[replace]
|
[replace]
|
||||||
urls = [ "youtube.com", "youtu.be" ]
|
urls = [ "youtube.com", "youtu.be" ]
|
||||||
|
|
||||||
[with]
|
[with]
|
||||||
mime = "video/vnd.youtube.yt"
|
mime = "video/vnd.youtube.yt"
|
||||||
```
|
```
|
||||||
and here's what a replace extension looks like:
|
what a replace extension looks like:
|
||||||
```
|
```
|
||||||
$ cat $XDG_DATA_HOME/xdg-sanity/youtube-replace.toml
|
$ cat $XDG_DATA_HOME/xdg-sanity/youtube.replace.toml
|
||||||
[replace]
|
[replace]
|
||||||
urls = [ "youtube.com", "youtu.be" ]
|
urls = [ "youtube.com", "youtu.be" ]
|
||||||
|
|
||||||
[with]
|
[with]
|
||||||
url = "https://piped.mint.lgbt/"
|
url = "https://piped.mint.lgbt/"
|
||||||
```
|
```
|
||||||
|
and what a scheme extension looks like:
|
||||||
|
```
|
||||||
|
$ cat $XDG_DATA_HOME/xdg-sanity/spotify.scheme.toml
|
||||||
|
[replace]
|
||||||
|
urls = [ "spotify.com" ]
|
||||||
|
|
||||||
|
[with]
|
||||||
|
scheme = "spotify://"
|
||||||
|
```
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
# xdg-sanity mime extension
|
|
||||||
|
|
||||||
[replace] # replaces these urls
|
|
||||||
urls = [ "youtube.com", "youtu.be" ]
|
|
||||||
|
|
||||||
[with] # replaces the mime type of the above
|
|
||||||
mime = "video/vnd.youtube.yt"
|
|
39
xdg-sanity
39
xdg-sanity
@ -63,17 +63,22 @@ while test -n "$1"; do
|
|||||||
MIME="$(curl -Ls -o /dev/null -w '%{content_type}' "$1" | sed 's/\;.*//' \
|
MIME="$(curl -Ls -o /dev/null -w '%{content_type}' "$1" | sed 's/\;.*//' \
|
||||||
| xargs echo)"
|
| xargs echo)"
|
||||||
|
|
||||||
|
# get the URL with no scheme
|
||||||
|
NO_SCHEME="$(printf "%s\n" "$URL" | sed -n 's/^h.\+\/\///p')"
|
||||||
|
|
||||||
# get the pattern for the extensions to MATCH
|
# get the pattern for the extensions to MATCH
|
||||||
MATCH="$(printf "%s\n" "$URL" | sed -ne 's/^h.\+\/\///p' \
|
MATCH="$(printf "%s\n" "$NO_SCHEME" | sed 's/\/.*\+//g')"
|
||||||
| sed -e 's/\/.*\+//g')"
|
|
||||||
|
# get the non-domain of the URI for tacking onto the end of replaced URIs
|
||||||
|
URI="$(printf "%s\n" "$NO_SCHEME" | sed -n 's/^[^/]*\///p')"
|
||||||
|
|
||||||
# only check for extensions if tomcat(1) is installed
|
# only check for extensions if tomcat(1) is installed
|
||||||
if command -v tomcat >/dev/null 2>&1; then
|
if command -v tomcat >/dev/null 2>&1; then
|
||||||
# run through MIME extensions
|
# run through MIME extensions
|
||||||
for file in \
|
for file in \
|
||||||
"$XDG_DATA_HOME"/xdg-sanity/*-mime.toml \
|
"$XDG_DATA_HOME"/xdg-sanity/*.mime.toml \
|
||||||
/usr/share/xdg-sanity/*-mime.toml \
|
/usr/share/xdg-sanity/*.mime.toml \
|
||||||
/usr/local/share/xdg-sanity/*-mime.toml
|
/usr/local/share/xdg-sanity/*.mime.toml
|
||||||
do
|
do
|
||||||
if test -e "$file"; then
|
if test -e "$file"; then
|
||||||
get_urls
|
get_urls
|
||||||
@ -85,21 +90,35 @@ while test -n "$1"; do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# and the replace extensions
|
# then replace extensions
|
||||||
for file in \
|
for file in \
|
||||||
"$XDG_DATA_HOME"/xdg-sanity/*-replace.toml \
|
"$XDG_DATA_HOME"/xdg-sanity/*.replace.toml \
|
||||||
/usr/share/xdg-sanity/*-replace.toml \
|
/usr/share/xdg-sanity/*.replace.toml \
|
||||||
/usr/local/share/xdg-sanity/*-replace.toml
|
/usr/local/share/xdg-sanity/*.replace.toml
|
||||||
do
|
do
|
||||||
if test -e "$file"; then
|
if test -e "$file"; then
|
||||||
get_urls
|
get_urls
|
||||||
for url in $URLS; do
|
for url in $URLS; do
|
||||||
if [ "$MATCH" = "$url" ]; then
|
if [ "$MATCH" = "$url" ]; then
|
||||||
URL="$(tomcat with.url "$file")"
|
URL="$(tomcat with.url "$file")$URI"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# and the scheme extensions
|
||||||
|
for file in \
|
||||||
|
"$XDG_DATA_HOME"/xdg-sanity/*.scheme.toml \
|
||||||
|
/usr/share/xdg-sanity/*.scheme.toml \
|
||||||
|
/usr/local/share/xdg-sanity/*.scheme.toml
|
||||||
|
do
|
||||||
|
get_urls
|
||||||
|
for url in $URLS; do
|
||||||
|
if [ "$URL" = "$url" ]; then
|
||||||
|
URL="$(tomcat with.scheme "$file")$MATCH"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# these commands may fail; this is intentional
|
# these commands may fail; this is intentional
|
||||||
|
Loading…
Reference in New Issue
Block a user