You could use vim in ex and command mode, from the terminal.
To indent a single file:
vim -c "normal gg=G" -e <file-to-indent> <<'EOF'
:wq
EOF
To indent files recursively, create the following script:
indent-with-vim.sh
vim -c "normal gg=G" -e $1 <<'EOF'
:wq
EOF
Now, type:
$ chmod u+x indent-with-vim.sh
$ find . | xargs -I {} ./indent-with-vim.sh {}
Vim will do its best to reindent the files. You may improve some specific file types.
For XML:
To improve PHP formatting:
Download http://www.vim.org/scripts/download_script.php?src_id=15001
(it will download a file named php.vim)
Create the following directories on your home:
~/.vim/indent
And copy php.vim
to ~/.vim/indent
If you are not satisfied with the result for any file type, you may look for alternatives on the web (like htb for HTML, https://github.com/vim-ruby/vim-ruby for improvements for Ruby, and so on).
Either way, you'd use or the .vimrc technique or the foo.vim indent file to improve the indentation.
Also, you can change the find parameters to apply to some specific types only, such as:
find . -iname "*.html" -or -iname "*.xml"
Command substitution `…`
substitutes the output of the command into the command line, so diff
sees the list of files in both directories as arguments. What you want is for diff
to see two file names on its command line, and have the contents of these files be the directory listings. That's what process substitution does.
diff <(ls old) <(ls new)
The arguments to diff
will look like /dev/fd/3
and /dev/fd/4
: they are file descriptors corresponding to two pipes created by bash. When diff
opens these files, it'll be connected to the read side of each pipe. The write side of each pipe is connected to the ls
command.
Best Answer
Meld
Meld is a tool that can compare and merge files and directories. It is a GUI analog to the standard
and
command line tools. (See man diff and man patch for more details on those)
diff
patch
Also, lots of source control systems (such as
or
) have the ability to create diffs between versions.
bzr
git