]> Tony Duckles's Git Repositories (git.nynim.org) - dotfiles.git/blob - bin/ack-wrapper
Merge branch 'master' into epic
[dotfiles.git] / bin / ack-wrapper
1 #!/bin/sh
2 # Wrapper around 'ack' to crawl all directories from `pwd` to / (or $HOME)
3 # looking for a "local" .ackrc file. Useful for setting project-level
4 # --ignore-dir settings.
5
6 # Search for "local" .ackrc file in CWD or any parents
7 HOME=~
8 ackrc=""
9 match=""
10 dir=$(pwd)
11 while [ "${dir}" != "/" -a "${match}" = "" ]; do
12 if [ -e "${dir}/.ackrc" ]; then
13 if [ "${dir}" != "${HOME}" ]; then
14 match=1
15 echo "(Include: ${dir}/.ackrc)"
16 ackrc=$(egrep "^[^#]" "${dir}/.ackrc" | tr '\n' ' ')
17 else
18 match=0
19 fi
20 else
21 dir=$(dirname "${dir}")
22 fi
23 done
24
25 # Add quote-wrapping for any additional args to ensure proper passing to
26 # real 'ack'.
27 for arg in "$@"; do
28 if [ -z "${ackrc}" ]; then
29 ackrc="'${arg}'"
30 else
31 ackrc="${ackrc} '${arg}'"
32 fi
33 done
34
35 # Build command to eval
36 cmd="command ack ${ackrc}"
37 if [ ! -t 0 ]; then
38 # If stdin is a pipe, use cat to redirect stdin to stdout and pipe
39 # that data into ack.
40 cmd="cat | ${cmd}"
41 fi
42
43 # Eval the final command
44 eval "${cmd}"