views:

46

answers:

3

I have a find command that I would like to sort such that entries for certain directories are sorted last. The reason is that this list is to be passed to etags to create a tags table and I would like certain third-party tool directories to be after all the code I actively edit.

Can someone suggest a good easy way in to sort the list as a change to my makefile rule? Here is the current rule:

tags:
 rm -f ../TAGS
 find .. \( -not -regex '.*include/.*' \)   \
  -a \( -name '*.h' -o -name '*.hh' -o -name '*.y' \
   -o -name '*.l' -o -name '*.cc' -o -name '*.cpp' \
   -o -name '*.c' -o -name '*.inl' \)  \
  | xargs etags -o ../TAGS --append

For example, entries that begin "../flexlm/" or "../src/librsync" should come after entries that don't match one of these patterns.

+1  A: 

Well assuming you can afford to run multiple find queries and you have your project set up in such a way that it is possible to find your own source files with one query and any libraries with other queries...

... That'd be what I'd do.

@user268396 How would you concatenate the multiple find queries into a single result for xargs?
WilliamKF
Pipe both through xargs and append both to the same file; or if it is not possible to append both to the same file through etags you can make two temp files and cat them together to the result file.
+2  A: 

Put multiple find commands in a brace block and pipe that into xargs:

# the single quotes take care of the escaping
pattern='( -not -regex ".*include/.*" )
         -a ( -name "*.h" -o -name "*.hh" -o -name "*.y"
         -o -name "*.l" -o -name "*.cc" -o -name "*.cpp"
         -o -name "*.c" -o -name "*.inl" )'

{
  find ! -path "../flexlm/*" ! -path "../src/librsync/*" $pattern
  find -path "../flexlm/*" $pattern
  find -path "../src/librsync/*" $pattern
} | xargs etags -o ../TAGS --append
Dennis Williamson
A: 

Here is what worked for me by combining the above answers and tweaking them:

PATTERN := \( -not -regex '.*include/.*' \)             \
        -a \( -name '*.h' -o -name '*.hh' -o -name '*.y'    \
            -o -name '*.l' -o -name '*.cc' -o -name '*.cpp' \
            -o -name '*.c' -o -name '*.inl' \)

.PHONY: tags
tags:
    rm -f ../TAGS
    find ..                             \
        ! -path "../src/librsync/*"             \
        ! -path "../flexlm/*"                   \
         $(PATTERN) | xargs etags -o ../TAGS --append
    find .. -path "../src/librsync/*"               \
         $(PATTERN) | xargs etags -o ../TAGS --append
    find .. -path "../flexlm/*"                 \
         $(PATTERN) | xargs etags -o ../TAGS --append
WilliamKF