#!/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