Created
July 25, 2012 02:52
-
-
Save rsky/3174111 to your computer and use it in GitHub Desktop.
UTF-8のShellでEUC-JPのキーワードでgit grepするプラグインgit-euc-grep
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/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() |
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
#!/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