在终端中使用 apt 安装 deb 时获取 ok 消息(从上下文菜单或单击)

在终端中使用 apt 安装 deb 时获取 ok 消息(从上下文菜单或单击)

我发现apt在终端中安装 deb 包中的程序是最好的方式。与其他 GUI 工具相比,我更喜欢终端,因此我希望将其放在 deb 文件的上下文菜单中或作为应用程序之间的启动器,以便通过双击执行来安装 deb。

在带有 Dolphin 的 Kubuntu 中,我创建了一个服务菜单来创建该上下文菜单,还创建了一个桌面文件,~/.local/share/applications通过执行 deb 文件来实现相同的操作。

文件~/.local/share/kservices5/ServiceMenus/install-deb.desktop

[Desktop Entry]

Actions=install
Icon=dialog-information
MimeType=application/vnd.debian.binary-package
ServiceTypes=KonqPopupMenu/Plugin
Type=Service
X-KDE-Priority=TopLevel


[Desktop Action install]
Exec=konsole --hold -e sudo apt install %f
Icon=dialog-information
Name=Install

文件~/.local/share/applications/install_deb_term.desktop

[Desktop Entry]
Name=Install in terminal with apt
Comment=Install deb files in terminal with apt
Exec=konsole --hold -e sudo apt install %f
Icon=gdebi
Terminal=false
Type=Application
StartupNotify=true
Categories=GNOME;GTK;Settings;HardwareSettings;X-GNOME-Settings-Panel;System;

一切都很好,除了没有--hold参数的情况konsole下终端会很快关闭(这在出现错误的情况下并不好),而有该参数时终端会保持打开状态并显示一条相当不确定的消息,如下所示:

 Setting up <whatever_program> ...

如果安装顺利的话,这并不是我所期望的。


我可以在安装过程结束时收到一些“OK”消息吗apt?也许通过包含命令的脚本apt


更新:

~/.bashrc按照@DKBose 的评论进行修改:回答我使用终端中的命令弹出所需的通知,例如

sudo apt install /path/to/deb; alert

不是与线

Exec=konsole --hold -e sudo apt install %f; alert

在上面的文件中(安装有效,但没有弹出)。

为了使该alert参数能够起作用,libnotify-bin需要安装。

答案1

apt install该答案解决了在 Kubuntu 18.04 中通过服务菜单安装 .deb 文件的问题。

首先,我们gcolor2使用 N0rbert 提供的链接下载一个小型的 .deb 文件,这个文件不在 bionic 仓库中这里

~/Downloads $ wget http://mirrors.kernel.org/ubuntu/pool/universe/g/gcolor2/gcolor2_0.4-2.1ubuntu1_amd64.deb

接下来,根据问题和评论中的服务菜单 .desktop 文件,穆鲁~/.local/share/kservices5/ServiceMenus/install-deb.desktop,构建了以下服务菜单.desktop文件:

[Desktop Entry]
Actions=install-deb
Icon=dialog-information
MimeType=application/vnd.debian.binary-package
Type=Service
ServiceTypes=KonqPopupMenu/Plugin
X-KDE-Priority=TopLevel

[Desktop Action install-deb]
Name=install-deb
Exec=konsole --hold -e bash -ic 'sudo apt install %f && notify-send --expire-time=50000 "DONE"'

从现在开始,如果在 Dolphin 中右键单击 .deb 文件,上下文菜单会提供“install-deb”作为选项之一。选择“install-deb”将打开konsole并运行sudo apt install %f,其中%f指的是gcolor通过 下载的 .deb wget

konsole 的输出如下:

[sudo] password for dkb: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'gcolor2' instead of '/home/dkb/Downloads/gcolor2_0.4-2.1ubuntu1_amd64.deb'
The following NEW packages will be installed:
  gcolor2
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/25.4 kB of archives.
After this operation, 112 kB of additional disk space will be used.
Get:1 /home/dkb/Downloads/gcolor2_0.4-2.1ubuntu1_amd64.deb gcolor2 amd64 0.4-2.1ubuntu1 [25.4 kB]
Selecting previously unselected package gcolor2.
(Reading database ... 257481 files and directories currently installed.)
Preparing to unpack .../gcolor2_0.4-2.1ubuntu1_amd64.deb ...
Unpacking gcolor2 (0.4-2.1ubuntu1) ...
Setting up gcolor2 (0.4-2.1ubuntu1) ...
Processing triggers for desktop-file-utils (0.23-1ubuntu3.18.04.2) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for mime-support (3.60ubuntu1) ...

安装完成后,konsole标题栏中将显示“完成”,但会一直打开,直到通过窗口管理器关闭。此外,由于位notify-send,通知将在指定的毫秒数内可见。(我不知道为什么,但--urgency=critical不会让通知持续存在。)


kdialog --passivepopup "whatever text string"似乎比 更适合此目的notify-send

相关内容