Compare commits
2 Commits
e43320bcbf
...
783a9fc3d4
Author | SHA1 | Date | |
---|---|---|---|
783a9fc3d4 | |||
f89a5e9624 |
@ -8,6 +8,6 @@ points.each_line do |line|
|
|||||||
x, y = $1, $2
|
x, y = $1, $2
|
||||||
Open3.capture3("xdotool mousemove #{x} #{y}")
|
Open3.capture3("xdotool mousemove #{x} #{y}")
|
||||||
Open3.capture3("xdotool click 1")
|
Open3.capture3("xdotool click 1")
|
||||||
sleep(0.2)
|
sleep(0.1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
99
grepid
99
grepid
@ -1,97 +1,6 @@
|
|||||||
#!/usr/bin/env python2
|
#!/bin/sh
|
||||||
|
|
||||||
import os
|
pattern="$1"
|
||||||
import sys
|
shift
|
||||||
import re
|
|
||||||
from subprocess import Popen, PIPE
|
|
||||||
|
|
||||||
COLORS = {
|
exec grep --exclude-dir=.svn --exclude-dir=.git --exclude=tags --color=auto -HIrn "\<$pattern\>" "$@"
|
||||||
'black': 0,
|
|
||||||
'red': 1,
|
|
||||||
'green': 2,
|
|
||||||
'yellow': 3,
|
|
||||||
'blue': 4,
|
|
||||||
'magenta': 5,
|
|
||||||
'cyan': 6,
|
|
||||||
'white': 7,
|
|
||||||
}
|
|
||||||
using_color = sys.stdout.isatty()
|
|
||||||
|
|
||||||
def usage(prog_name):
|
|
||||||
sys.stdout.write('Usage: %s <identifier> [grep flags/location...]\n' % prog_name)
|
|
||||||
|
|
||||||
def ansi_color(out, fg=None, bg=None, bold=False):
|
|
||||||
if using_color:
|
|
||||||
bc = 1 if bold else 0
|
|
||||||
if fg is not None:
|
|
||||||
out.write('\033[%d;%dm' % (bc, 30 + COLORS[fg]))
|
|
||||||
if bg is not None:
|
|
||||||
out.write('\033[%d;%dm' % (bc, 40 + COLORS[bg]))
|
|
||||||
|
|
||||||
def ansi_reset(out):
|
|
||||||
if using_color:
|
|
||||||
out.write('\033[0m')
|
|
||||||
|
|
||||||
def display_lines(lines, ident):
|
|
||||||
line_no_width = len(lines[-1][0])
|
|
||||||
for line_no, content in lines:
|
|
||||||
ansi_color(sys.stdout, 'magenta')
|
|
||||||
sys.stdout.write('%%%ds: ' % line_no_width % line_no)
|
|
||||||
ansi_reset(sys.stdout)
|
|
||||||
while content != '':
|
|
||||||
m = re.match('(.*?)(%s)(.*)$' % ident, content)
|
|
||||||
if m is None:
|
|
||||||
sys.stdout.write(content)
|
|
||||||
break
|
|
||||||
sys.stdout.write(m.group(1))
|
|
||||||
ansi_color(sys.stdout, 'red')
|
|
||||||
sys.stdout.write(m.group(2))
|
|
||||||
ansi_reset(sys.stdout)
|
|
||||||
content = m.group(3)
|
|
||||||
sys.stdout.write('\n')
|
|
||||||
|
|
||||||
def main(argv):
|
|
||||||
if len(argv) < 2:
|
|
||||||
usage(argv[0])
|
|
||||||
return 1
|
|
||||||
flags = ['.']
|
|
||||||
ident = argv[1]
|
|
||||||
if len(argv) >= 3:
|
|
||||||
flags = argv[2:]
|
|
||||||
|
|
||||||
try:
|
|
||||||
process = Popen(['grep', '--exclude-dir=.svn', '--exclude-dir=.git',
|
|
||||||
'--exclude=tags',
|
|
||||||
'--color=never', '-HIrn', '\<%s\>' % ident] + flags, stdout=PIPE)
|
|
||||||
|
|
||||||
last_file_name = ''
|
|
||||||
lines = []
|
|
||||||
for line in iter(process.stdout.readline, ''):
|
|
||||||
line = line.strip()
|
|
||||||
m = re.match('(.*?):(\d+):(.*)$', line)
|
|
||||||
if m is None:
|
|
||||||
last_file_name = ''
|
|
||||||
sys.stdout.write(m)
|
|
||||||
sys.stdout.write('\n')
|
|
||||||
continue
|
|
||||||
file_name, line_no, content = m.group(1, 2, 3)
|
|
||||||
if file_name != last_file_name:
|
|
||||||
if len(lines) > 0:
|
|
||||||
display_lines(lines, ident)
|
|
||||||
sys.stdout.write('\n')
|
|
||||||
last_file_name = file_name
|
|
||||||
ansi_color(sys.stdout, 'yellow')
|
|
||||||
sys.stdout.write(last_file_name)
|
|
||||||
sys.stdout.write(':')
|
|
||||||
ansi_reset(sys.stdout)
|
|
||||||
sys.stdout.write('\n')
|
|
||||||
lines = []
|
|
||||||
lines.append((line_no, content))
|
|
||||||
if len(lines) > 0:
|
|
||||||
display_lines(lines, ident)
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
pass
|
|
||||||
return 0
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
sys.exit(main(sys.argv))
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user