Skip to content

Instantly share code, notes, and snippets.

@rsky
Created July 25, 2012 02:52
Show Gist options
  • Save rsky/3174111 to your computer and use it in GitHub Desktop.
Save rsky/3174111 to your computer and use it in GitHub Desktop.
UTF-8のShellでEUC-JPのキーワードでgit grepするプラグインgit-euc-grep
#!/usr/bin/python
# vim: syn=python fileencoding=utf-8 ai et ts=4 sts=4 sw=4
import sys, subprocess
args = ['git', 'grep']
argv = sys.argv[1:]
if argv[0] == 'grep':
argv = argv[1:]
for arg in argv:
args.append(unicode(arg, 'utf-8').encode('euc-jp'))
p = subprocess.Popen(args,
stdout=subprocess.PIPE,
stderr=sys.stderr,
stdin=sys.stdin)
encodings = ('euc-jp', 'utf-8')
while True:
line = p.stdout.readline()
if not line:
break
uline = u''
for encoding in encodings:
try:
uline = unicode(line, encoding)
break
except UnicodeDecodeError:
pass
uline = uline.rstrip()
if len(uline) > 0:
print(uline.encode('utf-8'))
p.wait()
#!/bin/sh
if [ "x$1" = "xgrep" ]; then
git-euc-grep "$@"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment