Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
with
67 additions
and 0 deletions.
- +28 −0 etc/elisp.py
- +36 −0 etc/git-grep
- +3 −0 modes/ora-ivy.el
@@ -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) |
@@ -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 + '/') |