Skip to content

Instantly share code, notes, and snippets.

@maeharin
Created January 4, 2013 08:51
Show Gist options
  • Save maeharin/4450996 to your computer and use it in GitHub Desktop.
Save maeharin/4450996 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/ruby
if ARGV.count < 1 || ARGV.count >= 2
raise '引数が不正です!第1引数に比較したいファイル名を指定してください'
end
file_name = ARGV[0]
full_path = {}
full_path[:a] = File::expand_path(file_name)
full_path[:b] = ''
case full_path[:a]
when %r!/xxx/(.+)!
puts <<-EOS
*************************************************************
あなたは今xxxにいます
+ はxxxで追加された部分
- はxxxで削除された部分
*************************************************************
EOS
full_path[:b] = "~/yyy/#{$~[1]}"
when %r!/yyy/(.+)!
puts <<-EOS
*************************************************************
あなたは今yyyにいます
+ はyyyで追加された部分
- はyyyで削除された部分
*************************************************************
EOS
full_path[:b] = "~/xxx/#{$~[1]}"
else
raise 'error!あなたのいる位置が不明です'
exit
end
begin
exec("diff -u #{full_path[:b]} #{full_path[:a]} | nkf -w8")
rescue
puts 'シェルスクリプトdiffが実行できませんでした'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment