开发者

Shell scripts for Meld Nautilus context menu

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"开发者_JAVA百科 } { printf "\"%s\" ", $1 }' | sed -e s#\"\"##)

so that I can adapt to meld.


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 as sudo apt-get install diff-ext.

Check out some screenshots here - http://diff-ext.sourceforge.net/screenshots.shtml


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,

quoted=$(
# I would execute below by itself first
echo "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS"
# then add on this piped program to see how data gets transformed
| awk 'BEGIN { FS = "\n" } { printf "\"%s\" ", $1 }' 
# then add this
| sed -e s#\"\"##
# the capturing of the output to the var 'quoted' is the final step of code
)

# you **cannot** copy paste this whole block of code and expect it to work ;-)

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 like quoted=$(....) 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.


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:

$ diff-ext-setup

and in the Mime types pane, check application/x-trash.

Now you can compare a file and its backup.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜