Commits

Alexander Solovyov committed 19fb79a

display relative path instead of full

  • Participants
  • Parent commits 3779a90

Comments (0)

Files changed (1)

  • +8 -2
    sr
     """
 
     usage = """Usage: %prog [OPTIONS] [FILES]
-    
+
 Perform specified actions with each file in the tree from cwd on down.
 If [FILES] is specified, then only those files/directories are checked.
 
         config.search = re.compile(config.search, flags)
 
 
+def relpath(path):
+    curpath = os.getcwd() + '/'
+    if path.startswith(curpath):
+        return path[len(curpath):]
+    return path
+
 def search(path):
     """
     Search pattern in each line of file.
         number = count + 1
         if config.search.search(line):
             if not started:
-                print config.term.highlight(path, 'GREEN')
+                print config.term.highlight(relpath(path), 'GREEN')
                 started = True
             if len(line) <= LIMIT:
                 print '%d:%s' % (number, config.term.highlight(line.rstrip('\n\r'), ('BLACK', 'BG_YELLOW'), config.search))