Quellcode durchsuchen

Add misc/searchproviders2html.sh

master
Matteo Cypriani vor 1 Jahr
Ursprung
Commit
79157b7a4f
3 geänderte Dateien mit 106 neuen und 0 gelöschten Zeilen
  1. 1
    0
      bin/searchproviders2html
  2. 28
    0
      misc/README.md
  3. 77
    0
      misc/searchproviders2html.sh

+ 1
- 0
bin/searchproviders2html Datei anzeigen

@@ -0,0 +1 @@
1
+../misc/searchproviders2html.sh

+ 28
- 0
misc/README.md Datei anzeigen

@@ -0,0 +1,28 @@
1
+searchproviders2html.sh
2
+=======================
3
+
4
+This script converts KDE/Konqueror's search providers (a.k.a. web shortcuts),
5
+that are stored as `.desktop` files, into a Firefox-friendly HTML bookmarks
6
+file, ready to be imported with Firefox's bookmark manager. Imported bookmarks
7
+will be in the "Search providers" directory.
8
+
9
+The HTML is printed on the standard output, so you'll have to redirect it to a
10
+file, such as:
11
+
12
+    searchproviders2html >searchproviders.html
13
+
14
+If your `.desktop` files are not stored at the default location, or if this
15
+script becomes out of date and the default location is wrong, you can define
16
+the `SEARCHPROVIDERS_PATH` variable in the environment:
17
+
18
+    SEARCHPROVIDERS_PATH=/my/search/providers/directory
19
+
20
+Limitations:
21
+
22
+- Only the `\{@}` syntax is handled at the moment in input URLs. That means
23
+  that if you're using numbered values (`\{0}`, `\{1}`, etc.) or named
24
+  variables, they will appear as is in the output HTML.
25
+
26
+- Firefox handles only one keyword (shortcut) per bookmark, therefore
27
+  `searchproviders2html` will retain only the *first* keyword from the
28
+  `.desktop` file.

+ 77
- 0
misc/searchproviders2html.sh Datei anzeigen

@@ -0,0 +1,77 @@
1
+#!/bin/sh
2
+#
3
+# searchproviders2html.sh, Copyright © 2018 Matteo Cypriani
4
+#
5
+# This program is free software. It comes without any warranty, to the extent
6
+# permitted by applicable law. You can redistribute it and/or modify it under
7
+# the terms of the Do What The Fuck You Want To Public License, Version 2, as
8
+# published by Sam Hocevar. See http://sam.zoy.org/wtfpl/COPYING for more
9
+# details.
10
+#
11
+# This script converts Konqueror's search providers (a.k.a. web shortcuts) into
12
+# a Firefox-friendly HTML bookmarks file.
13
+
14
+set -e
15
+
16
+print_header()
17
+{
18
+	cat <<EOF
19
+<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
20
+<TITLE>Bookmarks</TITLE>
21
+<H1>Bookmarks Menu</H1>
22
+<DL><p>
23
+	<DT><H3>Search providers</H3>
24
+	<DL><p>
25
+EOF
26
+}
27
+
28
+print_bookmark()
29
+{
30
+	printf '\t\t<DT><A HREF="%s" SHORTCUTURL="%s">%s</A>\n' \
31
+		"$URL" "$SHORTCUT" "$TITLE"
32
+}
33
+
34
+print_footer()
35
+{
36
+	cat <<EOF
37
+	</DL><p>
38
+</DL>
39
+EOF
40
+}
41
+
42
+if [ $# -ne 0 ] ; then
43
+	cat <<EOF
44
+Usage: $0 >searchproviders.html
45
+
46
+You can define SEARCHPROVIDERS_PATH in the environment if your search provider
47
+files (.desktop) are not at the default location.
48
+EOF
49
+	exit 1
50
+fi
51
+
52
+if [ -z "$SEARCHPROVIDERS_PATH" ] ; then
53
+	SEARCHPROVIDERS_PATH="$HOME/.local/share/kde5/services/searchproviders"
54
+	printf 'SEARCHPROVIDERS_PATH not set in the environment, using "%s".' \
55
+		"$SEARCHPROVIDERS_PATH"
56
+fi
57
+
58
+print_header
59
+
60
+for FILE in "$SEARCHPROVIDERS_PATH"/*.desktop ; do
61
+	printf 'Processing "%s"...\n' "$FILE" >&2
62
+
63
+	# Get the title
64
+	TITLE=$(sed -n 's/^Name=//p' "$FILE")
65
+
66
+	# Get the URL and replace \\{@} with %s
67
+	URL=$(sed -n -e 's/^Query=//' -e 's/\\\\{@}/%s/p' "$FILE")
68
+
69
+	# Retain only the first shortcut, as Firfox only handles one
70
+	SHORTCUT=$(sed -n 's/^Keys=//p' "$FILE" | sed 's/,.*//')
71
+
72
+	# Uncomment the following line for debugging
73
+	#printf 'TITLE="%s"\nURL="%s"\nSHORTCUT="%s"\n\n' "$TITLE" "$URL" "$SHORTCUT" >&2
74
+	print_bookmark
75
+done
76
+
77
+print_footer

Laden…
Abbrechen
Speichern