Meld Nautilus 上下文菜单的 Shell 脚本
Beyond Compare 通过使用两个 nautilus 脚本(存储在在 /home/user/.gnome2/nautilus-scripts
中)。
脚本 1:选择进行比较
#!/bin/sh
quoted=$(echo "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" | awk 'BEGIN { FS = "\n" } { printf "\"%s\" ", $1 }' | sed -e s#\"\"##)
echo "$quoted" > $HOME/.beyondcompare/nautilus
脚本 2:与选定的比较
#!/bin/sh
arg2=$(cat $HOME/.beyondcompare/nautilus)
arg1=$(echo "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" | awk 'BEGIN { FS = "\n" } { printf "\"%s\" ", $1 }' | sed -e s#\"\"##)
bcompare $arg1 $arg2
我正在尝试为 Meld 执行类似的脚本,但它不工作。
我对 shell 脚本不熟悉。谁能帮助我理解这一点:
quoted=$(echo "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" | awk 'BEGIN { FS = "\n" } { printf "\"%s\" ", $1 }' | sed -e s#\"\"##)
以便我能够适应融合。
Beyond Compare provides "Select for compare" and "Compare to Selected" by using two nautilus scripts (stored in /home/user/.gnome2/nautilus-scripts
).
Script 1: Select for compare
#!/bin/sh
quoted=$(echo "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" | awk 'BEGIN { FS = "\n" } { printf "\"%s\" ", $1 }' | sed -e s#\"\"##)
echo "$quoted" > $HOME/.beyondcompare/nautilus
Script 2: Compare to Selected
#!/bin/sh
arg2=$(cat $HOME/.beyondcompare/nautilus)
arg1=$(echo "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" | awk 'BEGIN { FS = "\n" } { printf "\"%s\" ", $1 }' | sed -e s#\"\"##)
bcompare $arg1 $arg2
I am trying to do similar scripts for Meld, but it is not working.
I am not familiar with shell scripts. Can anyone help me understand this:
quoted=$(echo "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" | awk 'BEGIN { FS = "\n" } { printf "\"%s\" ", $1 }' | sed -e s#\"\"##)
so that I can adapt to meld.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您不是为了学习而推出自己的解决方案,我建议您将
diff-ext
扩展安装到 nautilus。它是跨平台的,如果您运行的是 Debian/Ubuntu,安装它应该像sudo apt-get install diff-ext
一样简单。在这里查看一些屏幕截图 - http://diff-ext.sourceforge.net/screenshots.shtml
If you are not rolling your own solution for the sake of learning, I would suggest installing the
diff-ext
extension to nautilus. It is cross platform and if you are running Debian/Ubuntu installing it should be as simple assudo apt-get install diff-ext
.Check out some screenshots here - http://diff-ext.sourceforge.net/screenshots.shtml
quote=$( ...) 将任何输出分配给名为quoted 的变量,并且可以稍后在脚本中用作 $quoted OR ${quoted} OR "${quoted}" OR "$quoted
" |' char 在 unix/linux 中被称为“管道”,它将前面命令的输出连接到后面的命令中。
所以你只需一次将脚本拆开一小部分,看看它做了什么,
我不知道 $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS 中应该有什么,所以很难在这里向你展示。并且,该变量未在您在此处指定的任何代码中定义,因此当您
echo
其值时,您可能只会得到一个空行。准备好研究如何设置该值以及什么是正确的值。我还注意到您的代码“前缀”为
#!/bin/sh
。如果它确实是 /bin/sh,那么像quoted=$(....)
这样的命令替换将不起作用,并且应该生成错误消息。也许您的系统实际上正在使用 bash 来执行 /bin/sh。您可以通过将 'shebang' 更改为#! 来消除将来可能出现的任何混乱(当更改为 /bin/sh = bourne shell 的系统时)。 /bin/bash
。我希望这有帮助。
The quoted=$( ...) assigns whatever output there is to the variable named quoted, and can be used later in the script as $quoted OR ${quoted} OR "${quoted}" OR "$quoted"
The '|' char is called a 'pipe' in unix/linux and it connects the output of the preceding command to feed into the following command.
So you just take the script apart 1 piece at a time and see what it does,
I don't know what is supposed to be in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS, so it is hard to show you here. AND, that variable is not defined in any of the code you specify here, so you may only get a blank line when you
echo
its value. Be prepared to do some research on how that value get set AND what are the correct values.Also I notice that your code is 'prefixed' as
#!/bin/sh
. If it is truly /bin/sh then command substitution likequoted=$(....)
will not work and should generate an error message. Persumably your system is really using bash for /bin/sh. You can eliminate any possible confusion in the future (when changing to a system where /bin/sh = bourne shell), by changing the 'shebang' to#! /bin/bash
.I hope this helps.
感谢这篇文章,我刚刚发现了 diff-ext,太棒了!
我的第一次尝试失败了:默认情况下 diff-ext 不处理备份文件(*~ 和 *.bak)。要启用此功能,请运行:
并在
Mime types
窗格中,选中application/x-trash
。现在您可以比较文件及其备份。
I just discovered diff-ext thanks to this post, excellent!
The first try I did failed: by default diff-ext does not handle backup files (*~ and *.bak). To enable this, run:
and in the
Mime types
pane, checkapplication/x-trash
.Now you can compare a file and its backup.