关于 Buku
Buku 是一个强大的书签管理器,提供搜索、标记、导入和导出功能。所有书签存储在本地数据库中,可从命令行快速访问。
主要功能
- 01添加、搜索和检索书签
- 02使用标签组织和分类书签
- 03从浏览器导入或导出书签列表
适用场景
- 01开发人员整理技术文档和参考资料
- 02编码 Agent 存储和检索工作流相关的资源链接
安装
选择你的系统或包管理器,复制命令到终端运行。
安装完成后运行buku --version确认安装成功。
命令示例
常用命令按使用顺序排列。
详细介绍
buku
buku 实际运行效果!
简介
buku 是一款功能强大的书签管理器,也是一个个人文本迷你网络。
如果你更喜欢图形界面,bukuserver 会在本地 Web 主机服务上提供一个可浏览的前端。配置和截图请参阅 bukuserver 页面。
开始编写它时,我找不到一种灵活的命令行解决方案,既能提供私密、可移植、可合并的数据库,又能与图形界面无缝集成。因此,我开发了 buku。
buku 可以从浏览器导入书签,也可以从网络获取 URL 的标题、标签和描述。使用你喜欢的编辑器添加、撰写和更新书签。利用多种搜索选项即时搜索书签,包括正则表达式和深度扫描模式(对于 URL 很有用)。
它可以在 Wayback Machine 上查找失效链接。还有一个复活节彩蛋,可以重新浏览随机书签。
它不会跟踪你、隐藏历史记录、保留过时记录、分析使用情况或向外发送数据。
要立即开始使用,请跳转到快速入门部分。buku 拥有一流的文档。手册页附有示例。有关内部细节,请参阅运行说明。
buku 也是一个库!还有多个相关项目,包括一个浏览器插件。
目录
功能
- 保存书签,并自动获取标题、标签和描述
- 自动从 Firefox、Google Chrome、Chromium、Vivaldi、Vivaldi Beta (Internal)、Brave 和 MS Edge 导入
- 在浏览器中打开书签和搜索结果
- 浏览 Wayback Machine 缓存的网页
- 集成文本编辑器
- 轻量、简洁的界面,支持自定义颜色
- 强大的搜索选项(正则表达式、子字符串……)
- 持续搜索,可即时切换模式
- 可移植、可合并的数据库,可在不同系统间同步
- 从/向 HTML、XBEL、Markdown、RSS/Atom 或 Orgfile 导入/导出书签
- 使用重定向(>>、>、<<)进行智能标签管理
- 多线程刷新完整数据库
- 支持手动加密
- Shell 补全脚本、附带实用示例的 man 手册页
- 注重隐私(不收集未经确认的用户数据)
- 可用作 Python 库(API 文档)
- 附带一个紧凑的 Web 应用(Bukuserver),提供基于 HTTP 的 API(仅供个人使用)
安装
依赖项
| 功能 | 依赖项 |
|---|---|
| 语言、SQLite | Python 3.10+ |
| HTTPS | certifi、urllib3 |
| 加密 | cryptography |
| HTML | beautifulsoup4、html5lib |
要将 URL 复制到剪贴板,buku 在 Linux 上使用 xsel(或 xclip),在 OS X 上使用 pbcopy(默认已安装),在 Windows 上使用 clip(默认已安装),在 Termux(Android 终端模拟器)上使用 termux-clipboard,在 Wayland 上使用 wl-copy。如果缺少 X11,则会识别 GNU Screen 或 tmux 的复制粘贴缓冲区。
使用包管理器安装
要从 PyPI 安装 buku 及其所有依赖项,请运行:
# pip3 install buku
你也可以通过包管理器安装 buku。如果提供的版本较旧,请尝试其他安装方式。
发布包
Arch Linux、CentOS、Debian、Fedora、openSUSE Leap 和 Ubuntu 的自动生成包(仅包含 CLI 组件)可在最新稳定版本中获取。
注意:CentOS 的软件源中可能没有 python3-beautifulsoup4 包。请使用 pip3 安装。
从源代码安装
如果已安装 git,请克隆此仓库。否则,请下载最新稳定版本或开发版本(有风险)。
安装依赖项。例如,在 Ubuntu 上:
$ apt-get install ca-certificates python3-urllib3 python3-cryptography python3-bs4
将 CLI 组件安装到默认位置(/usr/local):
$ sudo make install
要卸载,请运行:
$ sudo make uninstall
支持使用 PREFIX,以便安装到其他位置。
独立运行
buku 是一个独立工具。在其所在目录中运行:
$ chmod +x buku.py
$ ./buku.py
Shell 补全
Bash、Fish 和 Zsh 的 Shell 补全脚本位于 auto-completion/ 的相应子目录中。安装说明请参阅所用 Shell 的手册。
用法
命令行选项
usage: buku [OPTIONS] [KEYWORD [KEYWORD ...]]
Bookmark manager like a text-based mini-web.
POSITIONAL ARGUMENTS:
KEYWORD search keywords
GENERAL OPTIONS:
-a, --add URL [+|-] [tag, ...]
bookmark URL with comma-separated tags
(prepend tags with '+' or '-' to use fetched tags)
-u, --update [...] update fields of an existing bookmark
accepts indices and ranges
refresh title and desc if no edit options
if no arguments:
- update results when used with search
- otherwise refresh all titles and desc
-w, --write [editor|index]
edit and add a new bookmark in editor
else, edit bookmark at index in EDITOR
edit last bookmark, if index=-1
if no args, edit new bookmark in EDITOR
-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
--retain-order prevents reordering after deleting a bookmark
-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 web-fetch during auto-refresh
N=0: mutable (default), N=1: immutable
--swap N M swap two records at specified indices
SEARCH OPTIONS:
-s, --sany [...] find records with ANY matching keyword
this is the default search option
-S, --sall [...] find records matching ALL the keywords
special keywords -
"blank": entries with empty title/tag
"immutable": entries with locked title
--deep match substrings ('pen' matches 'opens')
--markers search for keywords in specific fields
based on (optional) prefix markers:
'.' - title, '>' - description, ':' - URL,
'#' - tags (comma-separated, PARTIAL matches)
'#,' - tags (comma-separated, EXACT matches)
'*' - any field (same as no prefix)
-r, --sreg expr run a regex search
-t, --stag [tag [,|+] ...] [- tag, ...]
search bookmarks by tags
use ',' to find entries matching ANY tag
use '+' to find entries matching ALL tags
excludes entries with tags after ' - '
list all tags, if no search keywords
-x, --exclude [...] omit records matching specified keywords
--random [N] output random bookmarks out of the selection (default 1)
--order fields [...] comma-separated list of fields to order the output by
(prepend with '+'/'-' to choose sort direction)
ENCRYPTION OPTIONS:
-l, --lock [N] encrypt DB in N (default 8) # iterations
-k, --unlock [N] decrypt DB in N (default 8) # iterations
POWER TOYS:
--ai auto-import bookmarks from web browsers
Firefox, Chrome, Chromium, Vivaldi, Vivaldi
Internal, Brave, Edge
(Firefox profile can be specified using
environment variable FIREFOX_PROFILE;
Firefox profiles directory can be specified using
environment variable FIREFOX_PROFILES_DIR)
-e, --export file export bookmarks to Firefox format HTML
export XBEL, if file ends with '.xbel'
export Markdown, if file ends with '.md'
format: [title](url)
export Orgfile, if file ends with '.org'
format: *[[url][title]] :tags:
export rss feed if file ends with '.rss'/'.atom'
export buku DB, if file ends with '.db'
combines with search results, if opted
-i, --import file import bookmarks from file
supports .html .xbel .json .md .org .rss .atom .db
(.json = Firefox backup; .db = another Buku DB)
-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, tag; N=3: title;
N=4: URL, title, tag; N=5: title, tag;
N0 (10, 20, 30, 40, 50) omits DB index
-j, --json [file] JSON formatted output for -p and search.
prints to stdout if argument missing.
otherwise writes to given file
--colors COLORS set output colors in five-letter string
--nc disable color output
-n, --count N show N results per page (default 10)
--np do not show the subprompt, run and exit
-o, --open [...] browse bookmarks by indices and ranges
open a random bookmark, if no arguments
--oa browse all search results immediately
--default-scheme S if scheme is missing from uri, assume S
when opening in browser (default http)
--replace old new replace old tag with new tag everywhere
delete old tag, if new tag not specified
--url-redirect when fetching an URL, use the resulting
URL from following *permanent* redirects
(when combined with --export, the old URL
is included as additional metadata)
--tag-redirect [tag] when fetching an URL that causes permanent
redirect, add a tag in specified pattern
(using 'http:{}' if not specified)
--tag-error [tag] when fetching an URL that causes an HTTP
error, add a tag in specified pattern
(using 'http:{}' if not specified)
--del-error [...] when fetching an URL causes any (given)
HTTP error, delete/do not add it
--export-on [...] export records affected by the above
options, including removed info
(requires --update and --export; specific
HTTP response filter can be provided)
--reorder order... update DB indices to match specified order
--cached index|URL browse a cached page from Wayback Machine
--offline add a bookmark without connecting to web
--suggest show similar tags when adding bookmarks
--tacit reduce verbosity, skip some confirmations
--nostdin do not wait for input (must be first arg)
--threads N max network connections in full refresh
default N=4, min N=1, max N=10
-V check latest upstream version available
-g, --debug show debug information and verbose logs
SYMBOLS:
> url
+ comment
# tags
PROMPT KEYS:
1-N browse search result indices and/or ranges
R [N] print out N random search results
(or random bookmarks if negative or N/A)
^ id1 id2 swap two records at specified indices
O [id|range [...]] open search results/indices in GUI browser
toggle try GUI browser if no arguments
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')
m search with markers - search string is split
into keywords by prefix markers, which determine
what field the keywords is searched in:
'.', '>' or ':' - title, description or URL
'#'/'#,' - tags (comma-separated, partial/full match)
'*' - all fields (can be omitted in the 1st keyword)
note: tag marker is not affected by 'd' (deep search)
v fields change sorting order (default is '+index')
multiple comma/space separated fields can be specified
v! fields update indices in DB to match specified order
r expression run a regex search
t [tag, ...] search by tags; show taglist, if no args
g taglist id|range [...] [>>|>|<<] [record id|range ...]
append, set, remove (all or specific) tags
search by taglist id(s) if records are omitted
n show next page of search results
N show previous page of search results
o id|range [...] browse bookmarks by indices and/or ranges
p id|range [...] print bookmarks by indices and/or ranges
w [editor|id] edit and add or update a bookmark
c id copy URL at search result index to clipboard
DB [name] check existing DB list or switch to another DB
(use full/dir path to switch folders)
'~.' can be used as shortcut for default DB
? show this help
q, ^D, double Enter exit buku
颜色
buku 支持自定义颜色。有关详情,请参阅 Wiki 页面,了解如何自定义颜色。
快速入门
-
设置
VISUAL或EDITOR,指向你喜欢的编辑器。请注意,VISUAL的优先级高于EDITOR。 -
创建一个更顺手的快捷命令。
alias b='buku --suggest' -
从浏览器自动导入书签。请先退出相关浏览器,以确保数据库未被锁定。
b --ai对于 Chrome、Chromium、Vivaldi(包括 Internal)和 Brave,如果文件可用,自动导入会同时读取明文
Bookmarks和AccountBookmarks文件。不支持加密的书签文件;请从浏览器将书签导出为 HTML,然后使用buku -i bookmarks.html导入导出的文件。 -
手动添加书签(动手操作)。
b -w -
列出书签及其数据库索引。
b -p -
有关 GUI 和浏览器集成(或将书签与喜欢的书签管理服务同步),请参阅 wiki 页面系统集成。
-
使用 fzf 进行模糊搜索并在 Firefox 中打开所选内容的快捷命令(bash/zsh):
firefox $(buku -p -f 10 | fzf) firefox $(buku -p -f 40 | fzf | cut -f1)同时显示书签预览的 POSIX 脚本:
#!/usr/bin/env sh url=$(buku -p -f4 | fzf -m --reverse --preview "buku -p {1}" --preview-window=wrap | cut -f2) if [ -n "$url" ]; then echo "$url" | xargs firefox fi
示例
-
使用编辑器编辑并添加书签:
$ buku -w $ buku -w 'gedit -w' $ buku -w 'macvim -f' -a https://ddg.gg search engine, privacy第一个命令从环境变量
EDITOR中选择编辑器。第二个命令以阻塞模式打开 gedit。第三个命令使用选项 -f 打开 macvim,并在模板中填入 URL 和标签。 -
添加一个简单书签:
$ buku --nostdin -a https://github.com/ 2648. GitHub: Let’s build from here · GitHub > https://github.com/ + GitHub is where over 94 million developers shape the future of software, together. Contribute to the open source community, manage your Git repositories, review code like a pro, track bugs and features, power your CI/CD and DevOps workflows, and secure code before you commit it. $ buku --nostdin -a https://github.com/ [ERROR] URL [https://github.com/] already exists at index 2648>:URL,+:备注,#:标签标题、描述和标签将从网站获取。Buku 只存储唯一的 URL;如果数据库中已存在该 URL,就会报错:
-
添加带有标签
search engine和privacy、备注Search engine with perks,并从网络获取网页标题的书签:$ 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其中,
>:URL,+:备注,#:标签 -
添加带有标签
search engine和privacy,且自定义标题不可修改的书签:DDG$ buku -a https://ddg.gg search engine, privacy --title 'DDG' --immutable 1 336. DDG (L) > https://ddg.gg # privacy,search engine请注意,URL 必须放在标签之前。
-
添加一个没有标题的书签(更新时也适用):
$ buku -a https://ddg.gg search engine, privacy --title -
使用编辑器编辑并更新书签:
$ buku -w 15012014这会在编辑器中打开现有书签的详情以供修改。必须设置环境变量
EDITOR。 -
更新索引为 15012014 的现有书签,设置新的 URL、标签和备注,并从网络获取标题:
$ buku -u 15012014 --url http://ddg.gg/ --tag web search, utilities -c Private search engine -
仅获取并更新索引为 15012014 的书签标题:
$ buku -u 15012014 -
仅更新索引为 15012014 的书签备注:
$ buku -u 15012014 -c this is a new comment--url、--title和--tag也适用。 -
将带有
tag 1或tag 2标签的书签导出为 HTML、XBEL、Markdown、Orgfile 或新的数据库: $ buku -e bookmarks.html --stag tag 1, tag 2 $ buku -e bookmarks.xbel --stag tag 1, tag 2 $ buku -e bookmarks.md --stag tag 1, tag 2 $ buku -e bookmarks.org --stag tag 1, tag 2 $ buku -e bookmarks.db --stag tag 1, tag 2 如果未指定搜索条件,则导出所有书签。 -
导入 HTML、XBEL、Markdown 或 Orgfile 格式的书签:
$ buku -i bookmarks.html $ buku -i bookmarks.xbel $ buku -i bookmarks.md $ buku -i bookmarks.org $ buku -i bookmarks.db -
仅删除索引为 15012014 的书签的备注:
$ buku -u 15012014 -c--title和--tag也适用。无法在不删除书签的情况下删除 URL。 -
使用网页标题更新或刷新整个数据库:
$ buku -u $ buku -u --tacit (仅显示失败和异常)此操作会解析获取的网页,更新非不可变书签的标题或描述字段。只有获取到的字段非空时才会更新。标签保持不变。
-
删除索引为 15012014 的书签:
$ buku -d 15012014 索引 15012020 移至 15012014为保持数据库紧凑,会将最后一个索引移至被删除的索引。添加
--tacit可在不确认的情况下删除。 -
删除所有书签:
$ buku -d -
删除书签的范围或列表:
$ buku -d 100-200 $ buku -d 100 15 200 -
在 URL、标题或标签中搜索包含关键字
kernel和debugging任意一个的书签:$ buku kernel debugging $ buku -s kernel debugging -
在 URL、标题或标签中搜索包含关键字
kernel和debugging全部的书签:$ buku -S kernel debugging -
搜索带有标签
general kernel concepts的书签:$ buku --stag general kernel concepts -
搜索带有标签
kernel、debugging、general kernel concepts任意一个的书签:$ buku --stag kernel, debugging, general kernel concepts -
搜索带有标签
kernel、debugging、general kernel concepts全部的书签:$ buku --stag kernel + debugging + general kernel concepts -
搜索包含关键字
hello或world、不包含关键字real和life、同时带有标签kernel和debugging,但不带有标签general kernel concepts和books的书签:$ buku hello world --exclude real life --stag 'kernel + debugging - general kernel concepts, books' -
搜索每个字段均匹配不同标记的书签,并按标签(升序)和 URL(降序)排序后打印
$ buku --order +tags,-url --markers --sall 'global substring' '.title substring' ':url substring' :https '> description substring' '#partial,tags:' '#,exact,tags' '*another global substring' -
按字母顺序列出所有不重复的标签:
$ buku --stag -
搜索并更新结果:
$ buku -s kernel debugging -u --tag + linux kernel -
搜索并删除结果:
$ buku -s kernel debugging -d -
使用自定义迭代次数(15)生成密钥,以加密或解密数据库:
$ buku -l 15 $ buku -k 15同一次锁定和解锁操作必须指定相同的迭代次数。若未指定,默认值为 8。
-
显示索引为 15012014 以及范围 20-30、40-50 内的书签详情:
$ buku -p 20-30 15012014 40-50 -
显示最后 10 个书签的详情:
$ buku -p -10 -
显示数据库中的所有书签及其真实索引:
$ buku -p $ buku -p | more -
将标签「old tag」替换为「new tag」:
$ buku --replace 'old tag' 'new tag' -
从数据库中删除标签「old tag」:
$ buku --replace 'old tag' -
为索引为 15012014 的书签**追加(或删除)**标签「tag 1」「tag 2」: $ buku -u 15012014 --tag + tag 1, tag 2 $ buku -u 15012014 --tag - tag 1, tag 2
-
在浏览器中打开索引为 15012014 的网址:
$ buku -o 15012014 -
列出没有标题或标签的书签,以便进行簿记:
$ buku -S blank -
列出标题不可更改的书签:
$ buku -S immutable -
在提示符中追加、移除标签(左侧为标签列表索引,右侧为书签索引):
// 将标签列表中索引为 4 和 6-9 的标签追加到索引为 5 和 2-3 的书签现有标签中 buku (? for help) g 4 9-6 >> 5 3-2 // 将标签列表中索引为 4 和 6-9 的标签设为索引为 5 和 2-3 的书签标签 buku (? for help) g 4 9-6 > 5 3-2 // 移除索引为 5 和 2-3 的书签的所有标签 buku (? for help) g > 5 3-2 // 从索引为 5 和 2-3 的书签标签中移除标签列表中索引为 4 和 6-9 的标签 buku (? for help) g 4 9-6 << 5 3-2 -
以彩色输出列出书签:
$ buku --colors oKlxm -p -
添加书签前,跟随所有永久重定向;仅当服务器没有返回错误(且没有网络故障)时才添加
$ buku --add http://wikipedia.net --url-redirect --del-error 2. Wikipedia > https://www.wikipedia.org/ + Wikipedia is a free online encyclopedia, created and edited by volunteers around the world and hosted by the Wikimedia Foundation. -
如果服务器返回永久重定向,则添加标签
http redirect;如果返回错误响应,则添加形如http 404的标签:$ buku --add http://wikipedia.net/notfound --tag-redirect 'http redirect' --tag-error 'http {}' [ERROR] [404] Not Found 3. Not Found > http://wikipedia.net/notfound # http 404,http redirect -
更新所有匹配搜索条件的书签:如果服务器返回永久重定向,则更新网址;如果服务器返回 HTTP 错误 400、401、402、403、404 或 500,则删除书签;如果发生任何其他 HTTP 错误,则添加形如
http:{}的标签。然后将因这些更改而受影响的书签导出到 HTML 文件,并标记已删除的记录以及因重定向而被替换的旧网址。$ buku -S ://wikipedia.net -u --url-redirect --tag-error --del-error 400-404,500 --export-on --export backup.html -
打印一条随机书签:
$ buku --random --print -
打印 3 条按 netloc(倒序)、标题和网址排序的随机书签:
$ buku --random 3 --order ,-netloc,title,+url --print -
打印一条符合搜索条件的随机书签,并按数据库中的顺序导出到 Markdown 文件:
$ buku --random -S kernel debugging --export random.md -
交换记录 #4 和 #5 的位置:
$ buku --swap 4 5 -
按指定顺序更新所有书签的索引:
$ buku --reorder ,-netloc,title,+url -
更多帮助:
$ buku -h $ man buku
自动化
可以使用 expect 自动化交互式工作流。议题 #368 提供了一个自动执行自动导入的可用示例。
故障排除
编辑器集成
你可能会遇到 GUI 编辑器相关问题:这些编辑器默认只保留一个实例,并会在其他实例中打开文档后立即返回。请使用相应的编辑器选项,在打开新文档时阻塞调用方。有关 gedit,请参阅议题 #210。
协作者
版权所有 © 2015-2026 Arun Prakash Jana
贡献
缺少某项功能?这里有一份持续更新的待办事项列表,列出了已确定的任务。欢迎贡献!请遵循 PR 指南。
相关项目
- bukubrow,用于浏览器集成的 WebExtension
- oil,边输入边搜索的 CLI 前端
- buku_run,rofi 前端
- pinku,用于将 Pinboard 导入 buku 的工具
- buku-dmenu,一个简单的 bash dmenu 包装器
- poku,在 Pocket 和 buku 之间同步
- Ebuku,buku 的 Emacs 接口
- diigoku,用于 Diigo 的 buku 导入工具
- BukuBot,适用于 XMPP 的聊天机器人,带有扩展的可视化界面