Midnight Commander (MC) is a lean, but powerful, two-panel file manager that, admittedly, promotes productivity while working from a console. Among other features, it implements a user menu with pre-defined actions that can be performed on the selected files or directories. This menu can be further customized by the user on a directory-, user- or system-basis. While searching for ready-made actions for MC‘s user menu, I came across an excellent set, which adds the ability to display the differences (diff output) between two versions of a file or directory in color.
Add the necessary code
The code that needs to be added to the user menu is the following:
+ t r & ! t t d Diff against file of same name in other directory if [ "%d" = "%D" ]; then echo "The two directores must be different" exit 1 fi if [ -f %D/%f ]; then # if two of them, then diff -up %f %D/%f | sed -e 's/\(^-.*\)/\x1b[1;31m\1\x1b[0m/g' \ -e 's/\(^\+.*\)/\x1b[1;32m\1\x1b[0m/g' \ -e 's/\(^@.*\)/\x1b[36m\1\x1b[0m/g' | less -R else echo %f: No copy in %D/%f fi D Diff current directory against other directory if [ "%d" = "%D" ]; then echo "The two directores must be different" exit 1 fi diff -up %d %D | sed -e 's/\(^-.*\)/\x1b[1;31m\1\x1b[0m/g' \ -e 's/\(^\+.*\)/\x1b[1;32m\1\x1b[0m/g' \ -e 's/\(^@.*\)/\x1b[36m\1\x1b[0m/g' | less -R fi
Here are the instructions on how to add this code to the user menu:
- Having launched Midnight Commander, press F9
- Go to the Command menu and hit the Edit menu file
- MC lets you customize the user menu for the current directory [
Local], current user [
Home] or make the modification system-wide. You will need to be root to change the latter. Most probably the Home choice is what you need.
- You can now paste the code block between two other user-defined commands.
How to use these actions
In order to show the differences between two versions of the same file, browse to the directories that contain each version, so that the directory in panel A contains the A version of
some.file and the directory in panel B contains the B version of
some.file. Then press F2 and lowercase d.
In order to show the differences between the contents of the directories in the two panels, just press F2 and then uppercase D.
The File and Directory diff in color in Midnight Commander by George Notaras, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.