following script.
#!/bin/bash -
#===============================================================================
# FILE: fixtab.sh
# USAGE: ./fixtab.sh <directory>
# DESCRIPTION: Convert expanded tabs into tabs with 4 space width
# OPTIONS: $1 directory
# AUTHOR: Ruslan Osmanov
# CREATED: 04/08/2011 03:26:00 PM UZT
#===============================================================================
set -o nounset # Treat unset variables as an error
DIR=$1
function usage(){
echo "bash $0 <directory>"
}
[[ ! -d $DIR ]] && usage
# Correct existing modelines I used to include modelines beginning from set
# expandtab, so this worked for me. If you don't use modelines, comment it out
find $DIR -name *.php -exec \
sed -i -e 's%# vim: set expandtab:%# vim: set noet:%g' {} \;
# Retab & format source code
find $DIR -name *.php -exec \
vim -u NONE \
-c 'set ft=php' \
-c 'set shiftwidth=4' \
-c 'set tabstop=4' \
-c 'set noexpandtab!' \
-c 'set noet' \
-c 'retab!' \
-c 'bufdo! "execute normal gg=G"' \
-c wq \
{} \;
For example:
$ bash ./fixtab.sh /srv/www/myprojectI would be glad, if this helped somebody.
Got it!I will continue to catch up with this information.
ReplyDelete------------------------------------
Discount Ray Ban Sunglasses
Helped me a lot, i wasn't sure how to do it in vim, and this worked one time in my script call. :-) Thanks
ReplyDelete