Skip to content

Instantly share code, notes, and snippets.

@imaizume
Created February 5, 2017 06:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imaizume/5009d1395a7f1af0857650bdfe2d183b to your computer and use it in GitHub Desktop.
Save imaizume/5009d1395a7f1af0857650bdfe2d183b to your computer and use it in GitHub Desktop.
.git/hooks以下に"pre-commit"で置いておくとcommit時に「、」と「。」を「,」と「.」に変換してくれるスクリプト
#!/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
@imaizume
Copy link
Author

imaizume commented Feb 5, 2017

ファイルエンコーディングを指定しないと正しく動作しないのが難点

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment