Add misc/searchproviders2html.sh
parent
b8619f8d0b
commit
79157b7a4f
@ -0,0 +1 @@
|
||||
../misc/searchproviders2html.sh
|
@ -0,0 +1,28 @@
|
||||
searchproviders2html.sh
|
||||
=======================
|
||||
|
||||
This script converts KDE/Konqueror's search providers (a.k.a. web shortcuts),
|
||||
that are stored as `.desktop` files, into a Firefox-friendly HTML bookmarks
|
||||
file, ready to be imported with Firefox's bookmark manager. Imported bookmarks
|
||||
will be in the "Search providers" directory.
|
||||
|
||||
The HTML is printed on the standard output, so you'll have to redirect it to a
|
||||
file, such as:
|
||||
|
||||
searchproviders2html >searchproviders.html
|
||||
|
||||
If your `.desktop` files are not stored at the default location, or if this
|
||||
script becomes out of date and the default location is wrong, you can define
|
||||
the `SEARCHPROVIDERS_PATH` variable in the environment:
|
||||
|
||||
SEARCHPROVIDERS_PATH=/my/search/providers/directory
|
||||
|
||||
Limitations:
|
||||
|
||||
- Only the `\{@}` syntax is handled at the moment in input URLs. That means
|
||||
that if you're using numbered values (`\{0}`, `\{1}`, etc.) or named
|
||||
variables, they will appear as is in the output HTML.
|
||||
|
||||
- Firefox handles only one keyword (shortcut) per bookmark, therefore
|
||||
`searchproviders2html` will retain only the *first* keyword from the
|
||||
`.desktop` file.
|
@ -0,0 +1,77 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# searchproviders2html.sh, Copyright © 2018 Matteo Cypriani
|
||||
#
|
||||
# This program is free software. It comes without any warranty, to the extent
|
||||
# permitted by applicable law. You can redistribute it and/or modify it under
|
||||
# the terms of the Do What The Fuck You Want To Public License, Version 2, as
|
||||
# published by Sam Hocevar. See http://sam.zoy.org/wtfpl/COPYING for more
|
||||
# details.
|
||||
#
|
||||
# This script converts Konqueror's search providers (a.k.a. web shortcuts) into
|
||||
# a Firefox-friendly HTML bookmarks file.
|
||||
|
||||
set -e
|
||||
|
||||
print_header()
|
||||
{
|
||||
cat <<EOF
|
||||
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
|
||||
<TITLE>Bookmarks</TITLE>
|
||||
<H1>Bookmarks Menu</H1>
|
||||
<DL><p>
|
||||
<DT><H3>Search providers</H3>
|
||||
<DL><p>
|
||||
EOF
|
||||
}
|
||||
|
||||
print_bookmark()
|
||||
{
|
||||
printf '\t\t<DT><A HREF="%s" SHORTCUTURL="%s">%s</A>\n' \
|
||||
"$URL" "$SHORTCUT" "$TITLE"
|
||||
}
|
||||
|
||||
print_footer()
|
||||
{
|
||||
cat <<EOF
|
||||
</DL><p>
|
||||
</DL>
|
||||
EOF
|
||||
}
|
||||
|
||||
if [ $# -ne 0 ] ; then
|
||||
cat <<EOF
|
||||
Usage: $0 >searchproviders.html
|
||||
|
||||
You can define SEARCHPROVIDERS_PATH in the environment if your search provider
|
||||
files (.desktop) are not at the default location.
|
||||
EOF
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$SEARCHPROVIDERS_PATH" ] ; then
|
||||
SEARCHPROVIDERS_PATH="$HOME/.local/share/kde5/services/searchproviders"
|
||||
printf 'SEARCHPROVIDERS_PATH not set in the environment, using "%s".' \
|
||||
"$SEARCHPROVIDERS_PATH"
|
||||
fi
|
||||
|
||||
print_header
|
||||
|
||||
for FILE in "$SEARCHPROVIDERS_PATH"/*.desktop ; do
|
||||
printf 'Processing "%s"...\n' "$FILE" >&2
|
||||
|
||||
# Get the title
|
||||
TITLE=$(sed -n 's/^Name=//p' "$FILE")
|
||||
|
||||
# Get the URL and replace \\{@} with %s
|
||||
URL=$(sed -n -e 's/^Query=//' -e 's/\\\\{@}/%s/p' "$FILE")
|
||||
|
||||
# Retain only the first shortcut, as Firfox only handles one
|
||||
SHORTCUT=$(sed -n 's/^Keys=//p' "$FILE" | sed 's/,.*//')
|
||||
|
||||
# Uncomment the following line for debugging
|
||||
#printf 'TITLE="%s"\nURL="%s"\nSHORTCUT="%s"\n\n' "$TITLE" "$URL" "$SHORTCUT" >&2
|
||||
print_bookmark
|
||||
done
|
||||
|
||||
print_footer
|
Loading…
Reference in New Issue