Permalink
Browse files

Add a custom git-grep command for my site-lisp

  • Loading branch information...
abo-abo committed Aug 4, 2016
1 parent da3aef5 commit c7effdb94749dc600b1204ea7a9db319ebdb0f00
Showing with 67 additions and 0 deletions.
  1. +28 −0 etc/elisp.py
  2. +36 −0 etc/git-grep
  3. +3 −0 modes/ora-ivy.el
View
@@ -0,0 +1,28 @@
import subprocess
import os
import re
def shell_command_to_string (cmd):
return subprocess.check_output (cmd.split (" "))
def file_name_directory (f):
return os.path.dirname (f)
def file_exists_p (f):
return os.path.exists (f)
def file_directory_p (f):
return os.path.isdir (f)
def abbreviate_file_name (f, d):
m = re.match (d, f)
if m:
return f[m.end () + 1:]
def expand_file_name (f, directory = None):
if not directory:
directory = os.getcwd ()
return os.path.join (directory, f)
def directory_files (d):
return os.listdir (d)
View
@@ -0,0 +1,36 @@
#!/usr/bin/python
"""This script will grep for a regex in ./site-lisp and ./site-lisp/git/*.
Prints the matches relative to ./site-lisp."""
import os
import sys
from elisp import *
def git_grep (regex):
return "git --no-pager grep --full-name -n --no-color -i -e %s" % regex
def git_p (f):
if file_directory_p (f):
return file_exists_p (expand_file_name (".git", f))
def print_git (cmd, d = ''):
try:
res = shell_command_to_string (cmd)[:-1]
for match in res.split ("\n"):
print d + match
except:
pass
regex = sys.argv[1]
cmd = git_grep (regex)
base_dir = "/home/oleh/Dropbox/source/site-lisp"
git_dir = expand_file_name ("git", base_dir)
dirs = [expand_file_name (f, git_dir) for f in directory_files (git_dir)]
dirs = filter (git_p, dirs)
dirs = [abbreviate_file_name (d, base_dir) for d in dirs]
os.chdir (base_dir)
print_git (cmd)
for d in dirs:
os.chdir (expand_file_name (d, base_dir))
print_git (cmd, d + '/')
View
@@ -35,4 +35,7 @@
t
'(("I" ivy-insert-action "insert")))
(setq counsel-git-grep-projects-alist
'(("/home/oleh/Dropbox/source/site-lisp/" . "/home/oleh/Dropbox/source/site-lisp/etc/git-grep %S")))
(provide 'ora-ivy)

0 comments on commit c7effdb

Please sign in to comment.