Buku: A Bookmark Manager in the Command Line

1
13744

Managing bookmarks is an important aspect of improving our experience on the Web. When used judiciously, bookmarks can save us a lot of time, effort and resources. This article familiarises readers with Buku, a command line bookmark manager.

Bookmarks are like shortcuts to Web pages. Browsers are adequate when it comes to bookmarks but to access the latter again, you have to open your browser. There’s no independent solution for bookmarks that protects your privacy and safeguards your data, which is why you need to try Buku.

Buku is a lightweight and flexible bookmark manager that comes with a command line interface (CLI). It possesses all the necessary functionalities of the typical bookmark manager and it also has some unique features like being self-hosted, having manual encryption support, the capability to shorten and expand URLs; the auto import of bookmarks from Firefox, Google Chrome and Chromium; automatic updates of the bookmarks, integrated text editor support for adding the bookmarks, and much more.

In this article, we’re going to see how Buku works its magic through the CLI in Linux, but if you prefer a GUI version of Buku, the GUI integration is explained in its GitHub project page.

Installation

Let’s install Buku in Debian based systems. Before installation, take a look at some of the system requirements.

Buku is a Python based package; so let’s use the Python-Pip package to install the necessary packages.

As I prefer Python3, let’s use the Python-pip3 package, which won’t be available in the system by default; so you’ll have to install this package manually using the following command:

$sudo apt-get install python3-pip
Figure 1: Bookmark added output
Figure 2: Bookmark editor

Once you’re done, use Python-pip3 to install the following packages in the system:

$sudo pip3 install urllib3 cryptography beautifulsoup4 requests

After completion, proceed with the Buku installation by adding the Buku PPA by using the following command:

$sudo add-apt-repository ppa:twodopeshaggy/jarun

Now update the system, as follows:

$sudo apt-get update

Finally, install the Buku package with the command shown below:

$sudo apt-get install buku
Figure 3: Bookmark view all
Figure 4: Search all keywords

The basics

Each bookmark in Buku contains the following four parts:

  • URL
  • Title
  • Tags
  • Comments

URL: This holds the address of the particular Web page that you want to bookmark. Do note that all the URLs are unique in Buku, and if your URL contains special characters such as ‘;’, ‘,’, ‘&’ and ‘()’ please enclose such URLs with single or double quotes, so that special characters in the URL don’t get interpreted by the shell.

Title: A title is optional in Buku because as soon as you have added a bookmark in Buku, it will automatically fetch the title from the URL through the Web and insert it into the corresponding bookmark. But if you want to set the title by yourself, you can use the –title option to do so.

By default, all the titles are changeable (N=0), but if you want to make a title constant, you can set the title immutable value (N=1).

Tags: These are essential in Buku because, through their effective use, bookmarks can be identified, searched and linked with other relevant bookmarks. Buku uses the comma to separate tags, so you cannot place a comma within a tag.

Comments: Comments are additional information you give to the bookmarks for your own convenience. These can be changed anytime you wish. Comments can be brief and unique so that each bookmark can be recognised easily.

Buku stores all the bookmarks in a single database file. Each URL is unique in the database. Besides, bookmarks are accessed through their index in the database. So whenever we want to add, delete or update bookmarks, we need to provide the index of the bookmark in the database.

Adding a bookmark

To add a bookmark, you need to use the (-a) option along with the Buku command, followed by the URL, tags and comments.

For example, the following command will add a bookmark on the Wikipedia page for ‘Free Software’:

$buku -a https://en.wikipedia.org/wiki/Free_software wiki,free_software,wikipedia -c Wikipedia article on Free Software

In the above example, we can see the URL of the Wikipedia page that we want to bookmark. After that, we have tags as ‘wiki’, ‘free_software’ and ‘wikipedia’ separated by the comma and finally, the ‘-c’ option will show the comment for the bookmark.

Figure 1 illustrates the output in the terminal after the bookmark has been successfully added to the Buku database.

If you’re uncomfortable with this structure, you can add your bookmarks using the editor with the ‘-w’ option, as shown below:

$buku -w ‘nano-w’

The above command will open the nano editor along with the skeleton structure for adding a bookmark. All you need to do is fill in the blanks in the editor and save it.

Figure 5: Search one keyword
Figure 6: File encrypted

Updating a bookmark

We can update a bookmark by using the (-u) option. Buku is so flexible that even individual elements of the bookmark can be updated separately while the others remain intact.

For each update, you need to provide the index of that bookmark. If you’re not sure of the index number of the bookmarks, you can view all the bookmarks along with their index numbers by using the following command:

$buku -p

For instance, if a website has changed its name, we can update our bookmark to use the site’s most recent name from the Web, by using the following command:

$buku -u 2

In the above command, the number ‘2’ denotes the index of the bookmark in the database.

If you prefer only to update the comment of a particular bookmark, you can use the ‘-c’ option along with the updated comment.

The comment section of the Wikipedia article that was added earlier can be updated by using the following command:

$buku -u 7 -c this a Wikipedia article on Free Software

Similarly, you can update the URL, title and tags with any one of the options ‘–url’, ‘–title’ and ‘–tags’, along with their relevant data.

Deleting a bookmark

To delete a bookmark, you need to use the -d option along with its index number, as shown below:

$buku -d 5

The above command will delete the bookmark in Index 5 and the last bookmark will take the deleted bookmark’s place so that no void space exists in the database.

To delete all the bookmarks, no index numbers are to be given:

$buku -d

If you want to delete bookmarks from a specific range, provide the range as an argument, as follows:

$buku -d 5 10

Searching

To search for a bookmark, you can use tags as your primary source, because as long as your tags are relevant to your bookmarks, they will help you greatly in finding the relevant bookmarks.

$buku --stag privacy, search_engine

The above command will list the bookmarks that have either ‘privacy’ or ‘search engine’ in their tags. You can refine your search by making all the tag inputs match a bookmark.

$buku --stag privacy + search_engine

You can also run a search based on the keywords of the bookmarks.

$buku -S privacy search_engine

The above command will list the bookmarks that have a match for the keywords ‘privacy’ and ‘search_engine’ in their URL, tags and comments.

If you want to search bookmarks with any one of the keywords matching words in the URL, tags, and comments, use the following command:

$buku -s privacy search_engine
Figure 7: File decrypted
Figure 8: Shortened URL

Encryption

Encryption is an important feature of Buku, since all the bookmarks are controlled and maintained by the user itself. Encryption makes sure that only authorised personnel access the bookmarks so that the privacy and integrity of the bookmarks remain pristine.

Buku uses the AES256 algorithm for encrypting the database but to use encryption, first the database needs to be locked by supplying a password of your choice.

$buku -l

The above command will ask for a password to lock the database. Once you supply the password, you will see that the file is encrypted. When you try to view the bookmarks, you will get an error message that the database needs to be unlocked first.

To decrypt the database file, you need to issue the command with the option -k so that you can access the bookmark database, as shown below:

$buku -k

After you have provided the right password, you will see the database is decrypted.

Please note that after decryption, the bookmark database will remain in the unencrypted state, so please lock the database when not in use.

Importing and exporting

Buku supports HTML, Markdown and DB formats for importing and exporting bookmarks. And you can export all the bookmarks to one of the supported formats by using the ‘-e’ option.

$buku -e bookmarks.html

The above command will export the bookmarks in the HTML format.

If you want to export only specific bookmarks from Buku, you can use tags. That way, only the bookmarks that have those particular tags get exported.

For example, if you want to export the bookmarks that have the tags ‘privacy’, you may modify the above command as follows:

$buku -e bookmarks.html --tag privacy

For importing bookmarks, you can either use the automatic import option to import all the bookmarks from your browser, or you can import the bookmarks from one of the supported formats mentioned in the above sections.

To use the automatic import, use –ai along with the Buku command, as shown below:

$buku --ai

You will be asked if the parent folder from the browser can be used for tags; choose the ‘Yes’ or ‘No’ option, as you wish.

The next question will be: Which browser can be used to import bookmarks? For example, I have Google Chrome and Firefox on my system. I wish to import bookmarks from Chrome, so I will give the response ‘y’ to Chrome, after which it will import the bookmarks from Google Chrome and add them to the Buku database.

To manually import the bookmarks from HTML or any of the supported formats, use the following command:

$buku -i bookmarks_frm_chrome.html

Based on your responses to the questions, the bookmarks will be added in the Buku database.

Do note that in both cases, auto-generated tags will be incorporated in the bookmarks, but you can always change the tags or comments via the update option.

Shortening and expanding URLs

Buku can shorten a URL by explicitly supplying it as an argument. You can also use the index of a bookmark you want to shorten. By default, Buku uses the tny.im URL shortening service to shorten URLs.

For example, if you want to shorten the URL of the Wikipedia article ‘https://en.wikipedia.org/wiki/Battle_of_Warsaw_(1920)’, as mentioned earlier, if any special characters are included in the URL, do remember to enclose them within the quotes.

$buku --shorten ‘https://en.wikipedia.org/wiki/Battle_of_Warsaw_(1920)’

The above method will work if you supply the index number of a bookmark instead of the URL.

In the same way, we can expand the URL by using the —expand option and supplying the tiny.im URL as an argument:

$buku --expand http://tny.im/xO0us

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here