78 wiersze
1.8 KiB
Bash
Executable File
78 wiersze
1.8 KiB
Bash
Executable File
#!/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
|