Info:
By Ruslan Osmanov, 2 Years ago, written in Bash. This post will never expire.
- #!/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
- # COMPANY:
- # 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
- find $DIR -name *.php -exec \
- sed -i -e 's%set expandtab:%set noexpandtab:%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 \
- {} \;
