0e947252dd46

Merge pull request #10 from llimllib/master

Add an option to print the abspath instead of relative path
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Wed, 09 Dec 2015 11:55:13 +0000
parents b9310be6f582 (diff) 81501b0cf30f (current diff)
children 4602c8a6735a
branches/tags (none)
files ffind

Changes

--- a/.hgtags	Wed Aug 14 20:02:33 2013 -0400
+++ b/.hgtags	Wed Dec 09 11:55:13 2015 +0000
@@ -2,3 +2,4 @@
 46cb98ff7fe08c1a70af90d4a92d427d50000d4d v0.2.0
 0f88e9f35bf1f2acab75065f46766976ecdb7d7b v0.3.0
 aef3e059452cf2ed2299b044906bc2823c90f552 v0.3.1
+f7ec69fb5eb5ffac255e081646c73e8e95bc698b v0.3.2
--- a/README.markdown	Wed Aug 14 20:02:33 2013 -0400
+++ b/README.markdown	Wed Dec 09 11:55:13 2015 +0000
@@ -40,7 +40,7 @@
 Usage
 -----
 
-Eventuall I'll make a man page, but for now:
+Eventually I'll make a man page, but for now:
 
 ### Command Line Program
 
--- a/ffind	Wed Aug 14 20:02:33 2013 -0400
+++ b/ffind	Wed Dec 09 11:55:13 2015 +0000
@@ -189,7 +189,7 @@
     # If you can't tell what the hell this means you're not alone, because git's
     # documentation is fucking inscrutable.  Here's what I've come up with from
     # trial and error:
-    # 
+    #
     # 0. Patterns ending in a slash will only match directories, and then you
     #    can ignore that slash for the rest of these rules.
     # 1. Patterns are shell globs, except * doesn't match / and there's no **.
@@ -381,6 +381,9 @@
             ignorers.extend(parse_hgignore_file(target))
     return ignorers
 
+def parse_ignore_args():
+    return [compile_ff_glob(pattern) for pattern in options.ignore]
+
 
 def get_initial_ignorers():
     if '.ffignore' in options.ignore_files:
@@ -460,9 +463,13 @@
 
 
 def _search(query, dir, depth, ignorers):
-    ignorers = ignorers + parse_ignore_files(dir)
+    ignorers = ignorers + parse_ignore_files(dir) + parse_ignore_args()
 
-    contents = os.listdir(dir)
+    try:
+        contents = os.listdir(dir)
+    except OSError:
+        err('Error: `' + dir + '`: Permission denied')
+        return
     next = []
 
     for item in contents:
@@ -571,7 +578,7 @@
                  help="don't ignore anything (ALL files can match)")
 
     g.add_option('-I', '--ignore', metavar='PATTERN',
-                 action='append',
+                 action='append', default=[],
                  help="add a pattern to be ignored (can be given multiple times)")
 
     p.add_option_group(g)
@@ -652,6 +659,19 @@
 
     result = set()
     for c in types:
+        if c not in 'aexcyfdrs':
+            die("invalid type specification\n\n"
+                "valid types:\n\n"
+                "  a (all)\n"
+                "  f (files)\n"
+                "  d (dirs)\n"
+                "  r (real)\n"
+                "  s (symlinked)\n"
+                "  e (real files)\n"
+                "  c (real dirs)\n"
+                "  x (symlinked files)\n"
+                "  y (symlinked dirs)")
+
         result = result | {
             'a': TYPES_ALL,
 
@@ -705,7 +725,7 @@
 
     """
 
-    return not all(c.lower() in string.letters + '_-' for c in s)
+    return not all(c.lower() in string.ascii_letters + '_-' for c in s)
 
 
 def clean_ago_piece(n, unit):