Conflicting type flags in ack

0

I have added a custom type to my .ackrc and it does just what I want.

--type-set=test:match:/_test\b/

It matches unit test files. Since I don't want to see test usages more often than I do, I also set

--notest

However, when I want to search tests, I try adding --test to the command line, but I get no results. My hope was that --test would overwrite --notest, but they combine to give nothing. The man page confirms that they are ORed together.

Any suggestions for what I'm trying to do?

Chris Connett

Posted 2016-03-24T00:07:15.073

Reputation: 3

Answers

0

Since ack's behavior is to OR all the type expressions together, there isn't a way to do this directly in the .ackrc without changing ack.

However, I was able to write a bash function wrapping ack that adds --notest unless --test is passed.

function ack {
  test_flag='--notest'
  for arg in "$*"; do
    case "$arg" in
      --test)
        test_flag=''
        ;;
    esac
  done
  command ack "$*" $testflag
}

Chris Connett

Posted 2016-03-24T00:07:15.073

Reputation: 3