buku
is a powerful bookmark manager written in Python3 and SQLite3. When I started writing it, I couldn't find a flexible cmdline solution with a private, portable, merge-able database along with browser integration. Hence, Buku
(after my son's nickname, meaning close to the heart in my language).
buku
fetches the title of a bookmarked web page and stores it along with any additional comments and tags. You can use your favourite editor to compose and update bookmarks. With multiple search options, including regex and a deep scan mode (particularly for URLs), it can find any bookmark instantly. Multiple search results can be opened in the browser at once.
Though a terminal utility, it's possible to add bookmarks to buku
without touching the terminal! Refer to the section on GUI integration. If you prefer the terminal, thanks to the shell completion scripts, you don't need to memorize any of the options. There's an Easter egg to revisit random forgotten bookmarks too.
Buku is too busy to track you - no history, obsolete records, usage analytics or homing.
There are several projects based on buku
, including a browser plug-in.
PRs are welcome. Please visit #174 for a list of TODOs.
deep
, regex
)Feature | Dependency |
---|---|
Scripting language | Python 3.3+ |
HTTP(S) | urllib3 |
Encryption | cryptography |
Import browser exported html | beautifulsoup4 |
Shorten URL, check latest release | requests |
To install package dependencies using pip3, run:
$ sudo pip3 install urllib3 cryptography beautifulsoup4 requests
or on Ubuntu:
$ sudo apt-get install python3-urllib3 python3-cryptography python3-bs4 python3-requests
sudo pip3 install buku
)sudo xbps-install -S buku
)sudo nix-env -i buku
)If you have git installed, clone this repository. Otherwise download the latest stable release or development version (risky).
Install to default location (/usr/local
):
$ sudo make install
To remove, run:
$ sudo make uninstall
PREFIX
is supported. You may need to use sudo
with PREFIX
depending on your permissions on destination directory.
buku
is a standalone utility. From the containing directory, run:
$ chmod +x buku.py
$ ./buku.py
If you are on a Debian (including Ubuntu) based system visit the latest stable release and download the .deb
package. To install, run:
$ sudo dpkg -i buku-$version-all.deb
Please substitute $version
with the appropriate package version.
Shell completion scripts for Bash, Fish and Zsh can be found in respective subdirectories of auto-completion/. Please refer to your shell's manual for installation instructions.
usage: buku [OPTIONS] [KEYWORD [KEYWORD ...]]
Powerful command-line bookmark manager. Your mini web!
POSITIONAL ARGUMENTS:
KEYWORD search keywords
GENERAL OPTIONS:
-a, --add URL [tag, ...]
bookmark URL with comma-separated tags
-u, --update [...] update fields of an existing bookmark
accepts indices and ranges
refresh the title, if no edit options
if no arguments:
- update results when used with search
- otherwise refresh all titles
-w, --write [editor|index]
open editor to edit a fresh bookmark
to update by index, EDITOR must be set
-d, --delete [...] remove bookmarks from DB
accepts indices or a single range
if no arguments:
- delete results when used with search
- otherwise delete all bookmarks
-h, --help show this information and exit
-v, --version show the program version and exit
EDIT OPTIONS:
--url keyword bookmark link
--tag [+|-] [...] comma-separated tags
clear bookmark tagset, if no arguments
'+' appends to, '-' removes from tagset
--title [...] bookmark title; if no arguments:
-a: do not set title, -u: clear title
-c, --comment [...] notes or description of the bookmark
clears description, if no arguments
--immutable N disable title fetch from web on update
N=0: mutable (default), N=1: immutable
SEARCH OPTIONS:
-s, --sany find records with ANY search keyword
this is the default search option
-S, --sall find records with ALL search keywords
special keywords -
"blank": entries with empty title/tag
"immutable": entries with locked title
--deep match substrings ('pen' matches 'opens')
-r, --sreg run a regex search
-t, --stag search bookmarks by a tag
list all tags, if no search keywords
ENCRYPTION OPTIONS:
-l, --lock [N] encrypt DB file with N (> 0, default 8)
hash iterations to generate key
-k, --unlock [N] decrypt DB file with N (> 0, default 8)
hash iterations to generate key
POWER TOYS:
-e, --export file export bookmarks in Firefox format html
export markdown, if file ends with '.md'
format: [title](url), 1 entry per line
use --tag to export only specific tags
-i, --import file import Firefox or Chrome bookmarks html
import markdown, if file ends with '.md'
-m, --merge file add bookmarks from another buku DB file
-p, --print [...] show record details by indices, ranges
print all bookmarks, if no arguments
-n shows the last n results (like tail)
-f, --format N limit fields in -p or Json search output
N=1: URL, N=2: URL and tag, N=3: title,
N=4: URL, title and tag
-j, --json Json formatted output for -p and search
--nc disable color output
--np do not show the prompt, run and exit
-o, --open [...] browse bookmarks by indices and ranges
open a random bookmark, if no arguments
--oa browse all search results immediately
--replace old new replace old tag with new tag everywhere
delete old tag, if new tag not specified
--shorten index|URL fetch shortened url from tny.im service
--expand index|URL expand a tny.im shortened url
--suggest show similar tags when adding bookmarks
--tacit reduce verbosity
--threads N max network connections in full refresh
default N=4, min N=1, max N=10
-V check latest upstream version available
-z, --debug show debug information and verbose logs
SYMBOLS:
> url
+ comment
# tags
keys:
1-N browse search result indices and/or ranges
a open all results in browser
s keyword [...] search for records with ANY keyword
S keyword [...] search for records with ALL keywords
d match substrings ('pen' matches 'opened')
r expression run a regex search
t [...] search bookmarks by a tag or show tag list
g [...][>>|>|<<][...] append, remove tags to/from indices and/or ranges
o [...] browse bookmarks by indices and/or ranges
p [...] print bookmarks by indices and/or ranges
w [editor|index] edit and add or update a bookmark
(tag list index fetches bookmarks by tag)
? show this help
q, ^D, double Enter exit buku
;
, &
or brackets they may be interpreted specially by the shell. To avoid it, add the URL within single or double quotes ('
/"
).(L)
after the title.,
) is the tag delimiter in DB. A tag cannot have comma(s) in it. Tags are filtered (for unique tags) and sorted. Tags are stored in lower case and can be replaced, appended or deleted.--fixtags
is introduced to modify the older tags. It also fixes another issue where the same tag appears multiple times in the tagset of a record. Run buku --fixtags
once.>>
(append), >
(overwrite) and <<
(remove) symbols. The LHS of the operands denotes the indices and ranges of tags to apply (as listed by --tag or key t
at prompt) and the RHS denotes the actual DB indices and ranges of the bookmarks to apply the change to.match
matches rematched
) in URL, title and tags.[]
after the title.place:
, file://
and apt:
are ignored during import.buku
and locked (-l) afterwards. Between these 2 operations, the database file lies unencrypted on the disk, and NOT in memory. Also, note that the database file is unencrypted on creation.Proxy support: environment variable https_proxy, if defined, is used to tunnel data for both http and https connections. The supported format is:
http[s]://[username:password@]proxyhost:proxyport/
buku
can be integrated in a GUI environment with simple tweaks.
With support for piped input, it's possible to add bookmarks to buku
using keyboard shortcuts on Linux and OS X. CLIPBOARD (plus PRIMARY on Linux) text selections can be added directly this way. The additional utility required is xsel
(on Linux) or pbpaste
(on OS X).
The following steps explore the procedure on Linux with Ubuntu as the reference platform.
To install xsel
on Ubuntu, run:
$ sudo apt install xsel
Create a new script bukuadd
with the following content:
xsel | buku -a
-a
is the option to add a bookmark.
3. Make the script executable:
$ chmod +x bukuadd
PATH
.<Alt-b>
.Copy or select a URL with mouse and press the keyboard shortcut to add it to the buku
database. The addition might take a few seconds to reflect depending on your internet speed and the time buku
needs to fetch the title from the URL. To avoid title fetch from the web, add the --title
option to the script.
To verify that the bookmark has indeed been added, run:
$ buku -p -1
and check the entry.
buku
, use the following script:1 2 3 |
|
If you want to tag these bookmarks, look them up later using:
$ buku -S blank
Use option -u
to tag these bookmarks.
buku
can export (or import) bookmarks in HTML format recognized by Firefox, Google Chrome and Internet Explorer.
To export all bookmarks, run:
$ buku --export path_to_bookmarks.html
To export specific tags, run:
$ buku --export path_to_bookmarks.html --tag tag 1, tag 2
Once exported, import the html file in your browser.
buku
has the capability to import records from another buku
database file. However, users with a cloud service client installed on multiple systems can keep the database synced across these systems automatically. To achieve this store the actual database file in a synced directory and create a symbolic link to it in the location where the database file would exist otherwise. For example, $HOME/.local/share/buku/bookmarks.db
can be a symbolic link to ~/synced_dir/bookmarks.db
.
buku
is developed as a powerful python library for bookmark management. All functionality are available through carefully designed APIs. main()
is a good usage example. It's also possible to use a custom database file in multi-user scenarios. Check out the documentation for the following APIs which accept an optional argument as database file:
BukuDb.initdb(dbfile=None)
BukuCrypt.encrypt_file(iterations, dbfile=None)
BukuCrypt.decrypt_file(iterations, dbfile=None)
NOTE: This flexibility is not exposed in the program.
The api directory has several example wrapper web APIs, not necessarily updated. Feel free to update if you need them.
An example to print the http status code of urls saved in buku
goes below. To run, install grequests.
import buku
import grequests
bdb = buku.BukuDb()
recs = bdb.get_rec_all()
recs[0]
# output: (1, 'example.com', 'example', 'tag1,tag2', 'page description', 0)
# Records have following structure:
# - id,
# - url,
# - metadata,
# - tags,
# - description,
# - flags
urls = [x[1] for x in recs]
rs = (grequests.get(u) for u in urls)
gr_results = grequests.map(rs)
for resp, url in zip(gr_results, urls):
stat_code = None if resp.status_code is None else resp.status_code
print('{}: {}'.format(stat_code, url))
# output
# 200: http://example.com
# None: http://website1.com/
# 200: http://website2.com/
# ...
$ buku -w
$ buku -w 'macvim -f' -a https://ddg.gg search engine, privacy
The first command picks editor from the environment variable EDITOR
. The second command will open macvim with option -f and the URL and tags populated in template.
2. Add a bookmark with tags search engine
and privacy
, comment Search engine with perks
, fetch page title from the web:
$ buku -a https://ddg.gg search engine, privacy -c Search engine with perks
336. DuckDuckGo
> https://ddg.gg
+ Alternative search engine with perks
# privacy,search engine
where, >: url, +: comment, #: tags
3. Add a bookmark with tags search engine
& privacy
and immutable custom title DDG
:
$ buku -a https://ddg.gg search engine, privacy --title 'DDG' --immutable 1
336. DDG (L)
> https://ddg.gg
# privacy,search engine
Note that URL must precede tags.
4. Add a bookmark without a title (works for update too):
$ buku -a https://ddg.gg search engine, privacy --title
Edit and update a bookmark from editor:
$ buku -w 15012014
This will open the existing bookmark's details in the editor for modifications. Environment variable EDITOR
must be set.
6. Update existing bookmark at index 15012014 with new URL, tags and comments, fetch title from the web:
$ buku -u 15012014 --url http://ddg.gg/ --tag web search, utilities -c Private search engine
7. Fetch and update only title for bookmark at 15012014:
$ buku -u 15012014
8. Update only comment for bookmark at 15012014:
$ buku -u 15012014 -c this is a new comment
Applies to --url, --title and --tag too.
9. Export bookmarks tagged tag 1
or tag 2
to HTML and markdown:
$ buku -e bookmarks.html --tag tag 1, tag 2
$ buku -e bookmarks.md --tag tag 1, tag 2
All bookmarks are exported if --tag is not specified.
10. Import bookmarks from HTML and markdown:
$ buku -i bookmarks.html
$ buku -i bookmarks.md
11. Delete only comment for bookmark at 15012014:
$ buku -u 15012014 -c
Applies to --title and --tag too. URL cannot be deleted without deleting the bookmark.
12. Update or refresh full DB with page titles from the web:
$ buku -u
$ buku -u --tacit (show only failures and exceptions)
This operation does not modify the indexes, URLs, tags or comments. Only title is refreshed if fetched title is non-empty.
13. Delete bookmark at index 15012014:
$ buku -d 15012014
Index 15012020 moved to 15012014
The last index is moved to the deleted index to keep the DB compact.
14. Delete all bookmarks:
$ buku -d
15. Delete a range or list of bookmarks:
$ buku -d 100-200
$ buku -d 100 15 200
16. Search bookmarks for ANY of the keywords kernel
and debugging
in URL, title or tags:
$ buku kernel debugging
$ buku -s kernel debugging
17. Search bookmarks with ALL the keywords kernel
and debugging
in URL, title or tags:
$ buku -S kernel debugging
18. Search bookmarks tagged general kernel concepts
:
$ buku --stag general kernel concepts
19. List all unique tags alphabetically:
$ buku --stag
20. Run a search and update the results:
$ buku -s kernel debugging -u --tag + linux kernel
21. Run a search and delete the results:
$ buku -s kernel debugging -d
22. Encrypt or decrypt DB with custom number of iterations (15) to generate key:
$ buku -l 15
$ buku -k 15
The same number of iterations must be specified for one lock & unlock instance. Default is 8, if omitted.
23. Show details of bookmarks at index 15012014 and ranges 20-30, 40-50:
$ buku -p 20-30 15012014 40-50
24. Show details of the last 10 bookmarks:
$ buku -p -10
25. Show all bookmarks with real index from database:
$ buku -p
$ buku -p | more
26. Replace tag 'old tag' with 'new tag':
$ buku --replace 'old tag' 'new tag'
27. Delete tag 'old tag' from DB:
$ buku --replace 'old tag'
28. Append (or delete) tags 'tag 1', 'tag 2' to (or from) existing tags of bookmark at index 15012014:
$ buku -u 15012014 --tag + tag 1, tag 2
$ buku -u 15012014 --tag - tag 1, tag 2
29. Open URL at index 15012014 in browser:
$ buku -o 15012014
30. List bookmarks with no title or tags for bookkeeping:
$ buku -S blank
31. List bookmarks with immutable title:
$ buku -S immutable
32. Shorten URL www.google.com and the URL at index 20:
$ buku --shorten www.google.com
$ buku --shorten 20
33. Append, remove tags at prompt (taglist index to the left, bookmark index to the right):
// append tags at taglist indices 4 and 6-9 to existing tags in bookmarks at indices 5 and 2-3
buku (? for help) g 4 9-6 >> 5 3-2
// set tags at taglist indices 4 and 6-9 as tags in bookmarks at indices 5 and 2-3
buku (? for help) g 4 9-6 > 5 3-2
// remove all tags from bookmarks at indices 5 and 2-3
buku (? for help) g > 5 3-2
// remove tags at taglist indices 4 and 6-9 from tags in bookmarks at indices 5 and 2-3
buku (? for help) g 4 9-6 << 5 3-2
34. More help:
$ buku -h
$ man buku
buku
waits until its input is closed when not started in a tty. For example, the following hangs:$ cat | buku
This is the intended behaviour as the primary reason behind supporting piped input is to add bookmarks with a keyboard shortcut. Third-party applications should explicitly close the input stream or use a wrapper script like the following one:
1 2 3 |
|
Copyright © 2015-2017 Arun Prakash Jana