2020-02-24
------------------------------------------------------------------


       Some time ago someone here somewhere was lamenting
       the lack of contextual search for bookmarks. I thought
       it was a good idea and I happened to have a setup
       for bookmarking that made this quite an easy addon.
       It's a bit of a hacky solution, but works pretty
       well. It uses dmenu and xsel.

       Here's the setup:


------------------------------------------------------------------

       1) Script for adding a bookmark

------------------------------------------------------------------

#!/bin/bash

paste="$(xsel -o)"

dmenu_search=$(echo | dmenu -i -l 19 -p 'Bookmark name: ')

if [ -n "${dmenu_search}" ]; then

       echo $paste > $HOME/bkm/"${dmenu_search}"

       elinks -dump -dump-width 140 -dump-charset us-ascii \
       -no-numbering -no-references "$paste" > \
       $HOME/bkm/.context/"${dmenu_search}"

fi


------------------------------------------------------------------

       2) Script for searching bookmarks

------------------------------------------------------------------

#!/bin/bash

cd $HOME/bkm/.context/

word=`cat * | fold -sw 175 | dmenu -l 19 -i $* -p "Find phrase "`

if [ "$word" != '' ]
then

choose=$(grep -Ril "$word" | dmenu -i -l 19 -p "Bookmark name ")


       if [ "$choose" != '' ]
       then
               cd $HOME/bkm/
               link=$(cat "$choose")
               firefox "$link"
       fi

fi


------------------------------------------------------------------

       3) Script for loading a bookmark without context search

------------------------------------------------------------------

#!/bin/bash

input="$(ls $HOME/bkm/ | dmenu -i -l 19 -p 'Load bookmark ' )"

if [ "$input" != '' ]
then

       link="$(cat $HOME/bkm/"$input")"
       firefox "$link"

fi


------------------------------------------------------------------


       The way it is used:

       1) You copy a link you want to save

       2) You open the saving script

       3) You type a name for the bookmark

------------------------------------------------------------------


       And when searching:

       1) You open the search script

       2) Type search term

       3) Pick any line with the search term

       4) It presents you with the name of the bookmark
       corresponding to the line you picked

------------------------------------------------------------------


       The way it saves the bookmarks is like this:

       1) There is a folder with text files that have the
       name that you picked and the url inside the
       document.

       2) There is also a hidden context folder with
       a site dump. This context is searched with
       the search script.

------------------------------------------------------------------


       Possible improvements:

       1) Some sed and awk magic on search results

       2) Actual indexing instead of just dumps?

       3) "Offline Mode" (Meaning: Just read the dump files)

       4) Secondary context (Dumps of linked pages)?

       5) Update the context

------------------------------------------------------------------


 Well, it's nothing special but I thought to put it here in case
 someone will be inspired to make something for themselves. I
 only made this today, but I am finding stuff from the bookmarks
 that I had forgotten all about.

 I also made a similar script for gopher links, of course. For
 some reason elinks wouldn't give a dump, so I used lynx.

 I am toying with the idea of taking a secondary dump. This would
 eventually collect into a sort of a database of context "around"
 the sites I have deemed worthy. Maybe it could even be turned
 into a custom search term for duckduckgo? You know, search all
 the sites I have bookmarked and all the sites those sites refer
 to. That would be awesome.


------------------------------------------------------------------