安装

快贴是一款非常优秀的国产剪贴板管理软件,当然它的优秀功能远远不止剪贴板管理。笔者最常用的就是其中的跨平台剪贴板同步功能了,这里将以 HarmonyOS 和 Windows 及 Linux (Ubuntu 22.04) 之间同步剪贴板进行举例,并着重记录在 Ubuntu 22.04 安装和配置快贴的方法。

根据官方网站的描述,需要执行以下步骤来安装:

wget -qO - https://apt.clipber.com/clipd.key | sudo apt-key add -
sudo sh -c 'echo "deb [arch=amd64] https://apt.clipber.com/debian focal main" >> /etc/apt/sources.list'
sudo apt update
sudo apt install clipd

不过,上述步骤在 Ubuntu 20.04 中能够正常安装,在 22.04 却遇到了缺少依赖项的问题:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 clipd : Depends: libicu66 (>= 66.1) but it is not installable
         Depends: libssl1.1 (>= 1.1.1f) but it is not installable
         Depends: libzip5 (>= 1.5.1) but it is not installable
E: Unable to correct problems, you have held broken packages.

这是因为 libicu66libssl1.1libzip5 三个依赖项已经在 Ubuntu 22.04 弃用了。

此时需要单独安装这三个包。在 Ubuntu Packages 搜索上述三个包,可以找到它们在 focal (20.04) 的包下载地址:

下载到本地后,依次执行:

sudo dpkg -i Downloads/libssl1.1_1.1.1f-1ubuntu2.16_amd64.deb
sudo dpkg -i Downloads/libzip5_1.5.1-0ubuntu1_amd64.deb
sudo dpkg -i Downloads/libicu66_66.1-2ubuntu2.1_amd64.deb

安装完成后,可以再次安装 clipd 程序:

sudo apt install clipd

配置

根据官方网站的使用说明,我们在跨平台使用前需要先启动 Daemon 程序 clipd。为了方便自启动和后台使用,可以添加一个 systemd 服务:

sudo cat > /etc/systemd/system/clipd.service <<EOF
[Unit]
Description=Clipd
Requires=network.target
After=systemd-user-sessions.service

[Service]
Type=simple
ExecStart=/usr/local/bin/clipd
KillMode=mixed
TimeoutStopSec=30
User=<你的用户名>
LimitNOFILE=100000

[Install]
WantedBy=multi-user.target
EOF

sudo systemctl daemon-reload
sudo systemctl enable --now

成功启动后,便可以按照说明登录和设置端到端加密了:

clipctl -U login
clipctl -e active

使用

向快贴发送内容的方式很简单,只需要通过下列命令就能存入内容了:

# 方式一:直接存入简单文本
clipctl -s '<文本内容>'

# 方式二:通过管道符存入简单文本
echo '<文本内容>' | clipctl -t

# 方式三:存入多行文本
clipctl -t <<EOF
<多行内容>
EOF

# 方式四:发送图片到剪贴板
cat '<图片路径>' | clipctl -i

另一方面,如果想要从中取出数据,可以执行:

clipctl -l

以 JSON 的格式显示历史记录(从新到旧),然后使用

clipctl -g <id>

获取对应 <id> 的剪贴板内容。

技巧:可以通过 Python3 的 json.tool 工具来格式化历史记录输出:

clipctl -l | python3 -m json.tool --no-ensure-ascii --indent 2