Created
May 15, 2017 09:08
-
-
Save louisswarren/7f0d1dd6c19d9c599f749b7ef1613708 to your computer and use it in GitHub Desktop.
Search for a file and open it with xdg-open
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/env python3 | |
import re | |
import subprocess | |
import sys | |
if len(sys.argv) < 2: | |
print("Usage: {} <findregex> [pythonregex]...") | |
sys.exit() | |
_, fregex, *refinements = sys.argv | |
find_call = ['find', '.', '-iregex', '.*{}.*'.format(fregex)] | |
files = subprocess.check_output(find_call).decode().split('\n')[:-1] | |
for refinement in refinements: | |
files = (f for f in files if re.search(refinement, f, re.IGNORECASE)) | |
subprocess.call(['xdg-open', next(iter(files))]) | |
# Example: | |
# open ftplugin python |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment