aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/bookmarks
diff options
context:
space:
mode:
Diffstat (limited to '.local/bin/bookmarks')
-rwxr-xr-x.local/bin/bookmarks69
1 files changed, 69 insertions, 0 deletions
diff --git a/.local/bin/bookmarks b/.local/bin/bookmarks
new file mode 100755
index 0000000..58ad8f5
--- /dev/null
+++ b/.local/bin/bookmarks
@@ -0,0 +1,69 @@
+#!/bin/sh -eu
+
+date=$(date +%s)
+program=$(basename "$0")
+key="QdUEdQBncNzJgIJqTA30"
+hxnormalize="hxnormalize -l 99999999 -x"
+items=/tmp/bookmarks_items_$key
+titles=/tmp/bookmarks_titles_$key
+anchors=/tmp/bookmarks_anchors_$key
+dependencies="$(command -V xmlstarlet hxnormalize paste \
+ hxselect hxincl xdg-open rofi basename \
+ | awk '{ print $1, $3 }' | column -t)"
+base=\
+"<!DOCTYPE NETSCAPE-Bookmark-file-1>
+<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">
+<title>Bookmarks</title>
+<h1>Bookmarks</h1>
+<dl>
+<!-- include $items --></dl>
+"
+
+bookmarks_help() {
+{ [ "${1:-}" = "-h" ] || [ "${1:-}" = "--help" ] || [ "$#" = 0 ]; } && printf \
+"
+Usage: %s [FLAGS]... [ARGUMENTS]...
+
+The program $program shall execute basic operations
+on Netscape Bookmark HTML files.
+
+ Command List:
+
+ $program compile [FILES]... Combine two or more bookmark.html files.
+ $program show [FILE] Show list of bookmarks.
+ $program check Check dependencies.
+ $program -h --help Show this help menu.
+" "$program" && exit;
+printf "Error: Unknown argument '%s'.\n" "$@" && exit 1;
+}
+
+bookmarks_combine () {
+ for file in "$@"
+ do $hxnormalize "$file" | sed 's/&/&amp;/g' \
+ | xmlstarlet edit -S \
+ --delete '//a/@add_date' \
+ --delete '//a/@icon' \
+ --delete '//a/@icon_uri' \
+ --delete '//a/@last_charset' \
+ --delete '//a/@last_modified' \
+ --delete '//a/@last_modified' \
+ --delete '//a/@tags' \
+ | $hxnormalize | hxselect -i -s '\n' dt;
+ done | sort | awk '!removeDuplicates[$0]++' >> "$items";
+ printf "%s" "$base" | hxincl -f -x > "bookmarks-$date.html";
+ realpath "bookmarks-$date.html";
+}
+
+bookmarks_show () {
+ $hxnormalize "${1:-}" | hxselect -c -i -s '\n' 'a::attr(href)' > "$anchors"
+ $hxnormalize "${1:-}" | hxselect -c -i -s '\n' 'a' > "$titles"
+ xdg-open "$(paste -d' ' "$anchors" "$titles" \
+ | rofi -font "sans 12" -matching regex -padding 20 -dmenu -i -p 'Bookmarks' \
+ | awk '{ print $1 }')";
+}
+
+[ "${1:-}" = "show" ] && shift 1 && bookmarks_show "$@" && exit;
+[ "${1:-}" = "combine" ] && shift 1 && bookmarks_combine "$@" && exit;
+[ "${1:-}" = "check" ] && shift 1 && printf '%s\n' "$dependencies" && exit;
+
+bookmarks_help "$@";