Various scripts in various languages.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

searchproviders2html.sh 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. set -e
  14. print_header()
  15. {
  16. cat <<EOF
  17. <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
  18. <TITLE>Bookmarks</TITLE>
  19. <H1>Bookmarks Menu</H1>
  20. <DL><p>
  21. <DT><H3>Search providers</H3>
  22. <DL><p>
  23. EOF
  24. }
  25. print_bookmark()
  26. {
  27. printf '\t\t<DT><A HREF="%s" SHORTCUTURL="%s">%s</A>\n' \
  28. "$URL" "$SHORTCUT" "$TITLE"
  29. }
  30. print_footer()
  31. {
  32. cat <<EOF
  33. </DL><p>
  34. </DL>
  35. EOF
  36. }
  37. if [ $# -ne 0 ] ; then
  38. cat <<EOF
  39. Usage: $0 >searchproviders.html
  40. You can define SEARCHPROVIDERS_PATH in the environment if your search provider
  41. files (.desktop) are not at the default location.
  42. EOF
  43. exit 1
  44. fi
  45. if [ -z "$SEARCHPROVIDERS_PATH" ] ; then
  46. SEARCHPROVIDERS_PATH="$HOME/.local/share/kde5/services/searchproviders"
  47. printf 'SEARCHPROVIDERS_PATH not set in the environment, using "%s".' \
  48. "$SEARCHPROVIDERS_PATH"
  49. fi
  50. print_header
  51. for FILE in "$SEARCHPROVIDERS_PATH"/*.desktop ; do
  52. printf 'Processing "%s"...\n' "$FILE" >&2
  53. # Get the title
  54. TITLE=$(sed -n 's/^Name=//p' "$FILE")
  55. # Get the URL and replace \\{@} with %s
  56. URL=$(sed -n -e 's/^Query=//' -e 's/\\\\{@}/%s/p' "$FILE")
  57. # Retain only the first shortcut, as Firfox only handles one
  58. SHORTCUT=$(sed -n 's/^Keys=//p' "$FILE" | sed 's/,.*//')
  59. # Uncomment the following line for debugging
  60. #printf 'TITLE="%s"\nURL="%s"\nSHORTCUT="%s"\n\n' "$TITLE" "$URL" "$SHORTCUT" >&2
  61. print_bookmark
  62. done
  63. print_footer