deanishe / alfred-firefox

Search and control Firefox from Alfred
Other
345 stars 19 forks source link

add bookmark search by tag #15

Open viggin543 opened 4 years ago

viggin543 commented 4 years ago

I'm a heavy user of firefox bm tags

It's an awesome feature that helps group bookmarks. Currently, firefox allows searching for a bm by tag in its search bar by starting the query with an asterisk * banana will search for all bookmarks tagged with a banana tag.


I'll be more than happy to help to add this functionality to your awesome workflow. Given some instructions. I've tried to figure it for myself but it seems there are many things going on in there a client that communicates with a local service over gRPC which communicates with a firefox extension process via STDIN/STOUT. lots of fun :)

gr8 work.

cheers.

p.s adding favicons of bookmarks to the alfred output will be awesome.

in addition. https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Work_with_the_Bookmarks_API I can't find anything related to bookmarks in the mozila extensions API docs....

The only thing ive managed to do in order to find bookmarks by tag is this ugly bash script

BOOKMARKS="/Users/domrevigor/Library/Application Support/Firefox/Profiles/current.profile/bookmarks.html"

lines=($(egrep -no 'TAGS="[^"]+' "${BOOKMARKS}"  | grep $1 | cut -d ":" -f1))

links=($(for i in ${lines[@]}; do sed -n ${i}p "${BOOKMARKS}" ;done | egrep -o 'HREF="[^"]*' | cut -d '"' -f2))

tags=($(for i in ${lines[@]}; do sed -n ${i}p "${BOOKMARKS}" ;done | egrep -o 'TAGS="[^"]*' | cut -d '"' -f2))

IFS=$(echo -en "\n\b")
titles=($(for i in ${lines[@]}; do sed -n ${i}p "${BOOKMARKS}" ;done | egrep -o '.*' | egrep -o ">[^<]+" | cut -d '>' -f2))

for i in `seq ${#lines}`;do /usr/local/bin/jq -n "{\"title\":\"${titles[$i]}\","arg":\"${links[$i]}\",\"subtitle\":\"${tags[$i]}\",\"id\":\"${titles[$i]}\"}"; done | /usr/local/bin/jq -s '{"items":map(.)}'

which just greps over bookmarks.html file. however, this file is updated only after browser restart, which sucks.

deanishe commented 4 years ago

https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Work_with_the_Bookmarks_API I can't find anything related to bookmarks in the mozila extensions API docs....

It's linked on that page: bookmarks.search(). As you can see, the search doesn't include tags. The data type returned by the API also doesn't include tags.

So I'm afraid it's not possible to search bookmarks using tags, at least not without searching bookmarks.html or digging around in Firefox's SQLite databases.

I don't want to do that because grubbing around in the SQLite databases is hacky and prone to break, and bookmarks.html is only updated when Firefox quits. I'm also not sure if it's possible to get the current profile from the browser API (which would be needed to know which files the bookmarks are in).

adding favicons of bookmarks to the alfred output will be awesome.

Also doubtful. It's a lot of work to do well, and typical favicons will look shit blown up to the size of workflow icons.