Created
February 5, 2017 06:18
-
-
Save imaizume/5009d1395a7f1af0857650bdfe2d183b to your computer and use it in GitHub Desktop.
.git/hooks以下に"pre-commit"で置いておくとcommit時に「、」と「。」を「,」と「.」に変換してくれるスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Tex files to be committed | |
tex_files_changed = `git diff --cached --name-only HEAD | grep -E '.*\.tex$'` | |
# Replace into commas and periods | |
THE_ENCODING = 'utf-8' | |
tex_files_changed.each_line do |texname| | |
puts "Replace into commas and periods in #{texname}" | |
texname.chomp! | |
begin | |
# FIXME: Preferable to automatically detect proper file encoding | |
s = File.read(texname, encoding: THE_ENCODING) | |
s.gsub!('、', ',') | |
s.gsub!('。', '.') | |
File.open(texname, 'w', encoding: THE_ENCODING) { |f| f.puts(s) } | |
rescue SystemCallError => e | |
puts %Q(class=[#{e.class}] message=[#{e.message}]) | |
rescue IOError => e | |
puts %Q(class=[#{e.class}] message=[#{e.message}]) | |
end | |
system("git add #{texname}") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ファイルエンコーディングを指定しないと正しく動作しないのが難点