dotfiles/scripts/menu/menu-bookmarks
2025-09-20 17:41:35 -06:00

46 lines
998 B
Bash
Executable file

#!/bin/sh
# Echo URI from bookmark's name
BOOKMARKS="$HOME/Documents/bookmarks.json"
_folders() {
jq -r '.children[] | select(.root == "unfiledBookmarksFolder") | .children[] | select(.type == "text/x-moz-place-container") | .title' "$BOOKMARKS"
}
_bookmarks_in_folder() {
jq -r --arg title "$1" '
.. | select(.type? == "text/x-moz-place-container" and .title? == $title)
| .children[]?
| select(.type == "text/x-moz-place")
| .title
' "$BOOKMARKS"
}
_bookmarks() {
jq -r '
.. | select(.type? == "text/x-moz-place") | .title
' "$BOOKMARKS"
}
_uri_from_title() {
jq -r --arg title "$1" '
.. | select(.type? == "text/x-moz-place" and .title? == $title) | .uri
' "$BOOKMARKS"
}
opt="$1"
output=
case "$opt" in
folders)
folder="$(_folders | menu "dmenu" "Folder:")"
output="$(_bookmarks_in_folder "$folder")"
;;
*)
title="$(_bookmarks | menu "dmenu" "Bookmark:")"
output="$(_uri_from_title "$title")"
;;
esac
if [ -n "$output" ]; then
echo "$output"
fi