From 79157b7a4f06999eb0db1aad6e6f6d76ae09a642 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Sun, 25 Feb 2018 21:30:01 +0100 Subject: [PATCH] Add misc/searchproviders2html.sh --- bin/searchproviders2html | 1 + misc/README.md | 28 +++++++++++++ misc/searchproviders2html.sh | 77 ++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 120000 bin/searchproviders2html create mode 100644 misc/README.md create mode 100755 misc/searchproviders2html.sh diff --git a/bin/searchproviders2html b/bin/searchproviders2html new file mode 120000 index 0000000..3dbdf21 --- /dev/null +++ b/bin/searchproviders2html @@ -0,0 +1 @@ +../misc/searchproviders2html.sh \ No newline at end of file diff --git a/misc/README.md b/misc/README.md new file mode 100644 index 0000000..50b2c77 --- /dev/null +++ b/misc/README.md @@ -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. diff --git a/misc/searchproviders2html.sh b/misc/searchproviders2html.sh new file mode 100755 index 0000000..2227f24 --- /dev/null +++ b/misc/searchproviders2html.sh @@ -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 < +Bookmarks +

Bookmarks Menu

+

+

Search providers

+

+EOF +} + +print_bookmark() +{ + printf '\t\t

%s\n' \ + "$URL" "$SHORTCUT" "$TITLE" +} + +print_footer() +{ + cat <

+

+EOF +} + +if [ $# -ne 0 ] ; then + cat <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