前两天推特上@peigen推荐了一款diff工具meld,和我之前使用的diffuse相比,最大的优点是可以进行文件夹比较。但存在的共同缺点就是如果直接使用nautilus中集成关联打开方式的方法,无法直接通过选中两个待比较的文件或文件夹右键直接进行比较,而总是打开两个应用程序实例。研究了一下nautilus的右键菜单定制方法,但总感觉功能不够强大,且无法完成这个看似非常简单的需求。
研究了一下,原来可以通过定制gnome-nautilus的右键菜单执行脚本来实现我的需求。下面附上我实现好的两个nautilus脚本
用meld比较选中的文件
#!/usr/bin/perl -w # This script compares the selected file(s) with meld. use strict; my @files = split("\n", $ENV{NAUTILUS_SCRIPT_SELECTED_FILE_PATHS}); my $count = $#files + 1; if( $count != 2 ) { my @dialog = ("gdialog","--title","Error","--msgbox", "\nError: Only 2 files can be compared at once. ","200", "300"); system (@dialog); } else { foreach my $file (@files) { if ( ! -f $file && ! -l $file ) { my @dialog = ("gdialog","--title","Error","--msgbox", "\nError: Can not compare $file. \n\n Only regular files can be diffed. ","200", "300"); system (@dialog); } } system("meld $files[0] $files[1]"); }
用meld比较选中的文件夹
#!/usr/bin/perl -w # This script compares the selected dir(s) with meld. use strict; my @files = split("\n", $ENV{NAUTILUS_SCRIPT_SELECTED_FILE_PATHS}); my $count = $#files + 1; if( $count != 2 ) { my @dialog = ("gdialog","--title","Error","--msgbox", "\nError: Only 2 directories can be compared at once. ","200", "300"); system (@dialog); } else { foreach my $file (@files) { if ( ! -d $file ) { my @dialog = ("gdialog","--title","Error","--msgbox", "\nError: Can not compare $file. \n\n Only directories can be diffed. ","200", "300"); system (@dialog); } } system("meld $files[0] $files[1]"); }
原创文章,转载请注明: 转载自猪在笑 [ http://www.huangwei.me/blog/ ]
本文链接地址: http://www.huangwei.me/blog/2010/08/30/gnome-nautilus-scripts-meld/
最近评论