Quantcast
Channel: Vimタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 5608

BOM無しUTF-8のファイルをBOM付きで一括で保存し直す

$
0
0

BOM判定用rubyスクリプトを用意

参考: BOMチェック君 - 俺の基地

bomcheck.rb
dirs=["./trunk/unity/Assets/Source/**/*.cs","./trunk/unity/Assets/Editor/**/*.cs"]dirs.eachdo|dir|Dir.glob(dir).eachdo|f|nextunlessFile.file?(f)hoge=open(f)hoge.binmodebeginifhoge.read(3).unpack("h*")[0]!="febbfb"putsf.to_s#+ " is *NOT* BOM file"endrescueendendend

以下のとおり実行

$ for f in $(ruby bomcheck.rb); do vim -c "set fenc=utf-8 bomb" -c "x" $f; done

Viewing all articles
Browse latest Browse all 5608

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>