chromium-bookmarks.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env bash
  2. # Script to list bookmarks from Chromium profile.
  3. # Should also work with Chromium based browsers like Iridium, Brave etc.
  4. # by Adnan Shameem (adnan360); License: MIT (Expat)
  5. #
  6. # Usage:
  7. # - Change the 'profile_dir=' line below to match your browser/setup
  8. # - Run the script to get bookmarks: ./chromium-bookmarks.sh
  9. # Prints bookmarks when provided a Chromium/based browser profile directory.
  10. # Params:
  11. # $1: Profile dir, where "Bookmarks" file lives
  12. function extract_chromium_bookmarks() {
  13. if [ -f "${1}/Bookmarks" ]; then
  14. # This brings in name (title), type and url - separated by a line of "--"
  15. grep -EB2 '"url":' "$1/Bookmarks" | \
  16. # We don't need the type line
  17. sed '/"type":/d' | \
  18. # We don't need the '--' line either
  19. sed '/^--$/d' | \
  20. # Join lines into one single line, so that it can be processed by grep
  21. sed -e ':a' -e 'N' -e '$!ba' -e 's/\n//g' | \
  22. # Find the title and url and show them on output
  23. sed -n -e 's|\s*"name": "\([^"]*\)"[^"]*"url": "\([^"]*\)"|\1 -> \2\n|pg'
  24. else
  25. echo "Error: The bookmark file ${1}/Bookmarks doesn't exist"; exit 4284
  26. fi
  27. }
  28. # Holds the profile directory. The directory where the "Bookmarks" file lives.
  29. # Set it to your Chromium/based browser's profile directory.
  30. # For example:
  31. # - Iridium: "$HOME/.config/iridium/Default/"
  32. # - Brave: "$HOME/.config/BraveSoftware/Brave-Browser/Default/"
  33. # - Chromium: "$HOME/.config/chromium/Default/"
  34. profile_dir="$HOME/.config/iridium/Default/"
  35. # Finally, show the bookmarks!
  36. extract_chromium_bookmarks "$profile_dir"