如何用Nautilus“区分”两个文件?

我已经安装了Meld,发现它是一个很棒的比较工具。 不幸的是,没有与Nautilus 3.2集成。 这意味着,我无法右键单击文件并选择一个选项以在Meld中打开它们进行比较。

我在工具评论中看到该工具需要安装diff-ext软件包。 这个包已经从Ubuntu宇宙中删除了,我猜是因为gtk 3.0。 即使我手动从源代码下载伪造diff-ext包,当我尝试配置它时,检查失败并显示以下消息:

checking for DIFF_EXT... configure: error: Package requirements (libnautilus-extension >= 2.14.0 gconf-2.0 >= 2.14.0 gnome-vfs-module-2.0 >= 2.14) were not met: No package 'libnautilus-extension' found No package 'gconf-2.0' found No package 'gnome-vfs-module-2.0' found 

好的,所以从这个输出我收集到确实需要gtk 2来安装diff扩展到nautilus。

现在,我的问题是:是否有可能将Meld整合到Nautilus? 或者,还有其他基于差异的工具与现有的Nautilus集成吗? 所以基于gtk3。

如果到目前为止有任何疑问,我正在使用Ubuntu 11.10。

有一个有用的python扩展,将Meld整合到Nautilus中

在此处输入图像描述

在此处输入图像描述

如何安装

从作者网站获取源包或deb包。

 wget http://www.giuspen.com/software/nautilus-pyextensions_3.4.1-1_all.deb sudo apt-get install python-nautilus sudo dpkg -i nautilus-pyextensions_3.4.1-1_all.deb 

在Dash中搜索pyextension并运行Nautilus PyExtension

激活meld扩展(如果询问则安装它)并单击重新启动Nautilus工具栏选项。

GConf错误

如果您在尝试打开Nautilus PyExtension时发现GConf相关错误,请安装“gobject-introspection”和“gir1.2-gconf-2.0”:

 sudo apt-get install gobject-introspection sudo apt-get install gir1.2-gconf-2.0 

您还可以从标准Ubuntu软件包存储库中安装nautilus-compare软件包(从Ubuntu 12.04开始) – 从终端运行以下命令:

 sudo apt-get install nautilus-compare 

这为双向和三向比较提供了nautilus菜单选项。 默认情况下使用Meld,但可以使用任何用户定义的diff应用程序。

这个解决方案的一个显着优点是可以比较位于不同目录中的文件或文件夹(例如/home/user/a/b/c/file.txt/home/user/d/e/f/otherfile.txt可以在不同的Nautilus窗口打开,并相互比较)。

Nautilus脚本

安装专用扩展的更简单,更有效的替代方法是使用Nautilus脚本,如下所示:

 #!/bin/bash meld "$@" 

安装说明: 如何安装Nautilus脚本?

使用Nautilus将文件与包含文本的剪贴板进行比较

此答案主要用于将文件与剪贴板中从Internet复制的文本进行比较。 可以从系统上的另一个文件复制剪贴板文本 – 使其成为符合条件的答案。

使用bash的native diff命令突出显示文件差异,然后使用gedit显示。 这可以修改为meld或任何其他第三方包。

这个答案使用Nautilus的内置函数在选择文件后运行自定义脚本:

 #!/bin/bash # NAME: clipboard-diff # PATH: $HOME/.local/share/nautilus/scripts # DESC: Find differences bewteen selected file on disk and clipboard. # CALL: Called from Nautilus file manager. # DATE: March 18, 2017. Modified: March 31, 2017. # NOTE: The clipboard would contain text highlighted on website and copied # with +. Requires command `xclip` to be installed. # Must have the xclip package. On Ubuntu 16.04, not installed by default command -v xclip >/dev/null 2>&1 || { zenity --error --text "Install xclip using: 'sudo apt install xclip' to use this script. Aborting."; exit 99; } # strip new line char passed by Nautilus FILENAME=$(echo $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS | sed -e 's/\r//g') # Multiple files can't be selected. LINE_COUNT=$(wc -l <<< "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS") LINE_COUNT=$((LINE_COUNT-1)) if [[ $LINE_COUNT > 1 ]] ; then zenity --error --text "Ony one file can be selected at a time! " exit 1 fi # Object type must be "file..." (ie no directories, etc.) if [ -d "${FILENAME}" ] ; then zenity --error --text "$FILENAME is a directory!"; exit 1 else if [ -f "${FILENAME}" ]; then : # Bash noop else zenity --error --text "${FILENAME} is not a file!"; exit 2 fi fi # Get clipboard contents into working file workfile="/tmp/clipboard-work-"$(date +%s) xclip -o > $workfile # Create temporary file name so two or more open instances won't clash differences="/tmp/clipboard-diff-"$(date +%s) # Compare file differences # -q brief -B ignore blank lines, -u only differences diff --unified=2 -w -b -B -I --suppress-blank-empty \ --suppress-common-lines --ignore-all-space \ ${FILENAME} $workfile > $differences # If file doesn't exist, errors in diff parameters # If file size =0 there were no differences if [[ -f $differences ]] ; then if [[ -s $differences ]] ; then # File not empty. gedit $differences else zenity --info --text "$workfile matches $differences" fi else zenity --error --text "cliboard-diff - error in diff parameters." fi # clean up /tmp directory rm $workfile rm $differences exit 0 

注意:几周前我开发了这个Nautilus脚本,并且意味着将其作为一个新的问答发布但是时间紧迫,并且不确定是否有人真的对它感兴趣。

样本输出

clipboard-diff 1

在此示例中,我们将2017年3月31日之前在AU发布的实际脚本与2017年3月31日修订的版本进行比较。请注意如何设置新信息和错误消息。

diff命令非常强大,因此具有无数的控制参数。 在终端中键入man diff以获取手册页或info diff以获得更多命令用法详细信息。