]> Tony Duckles's Git Repositories (git.nynim.org) - dotfiles.git/blob - bin/ack-wrapper
bin/ack-wrapper: Correctly escape user-supplied args
[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 PWD=$(pwd)
7 HOME=~
8 ack=$(type -P ack)
9 ackrc=""
10
11 match=""
12 dir="$PWD"
13 while [ "$dir" != "/" -a "$match" = "" ]; do
14 if [ -e "$dir/.ackrc" ]; then
15 if [ "$dir" != "$HOME" ]; then
16 match=1
17 echo "(Include: ${dir}/.ackrc)"
18 ackrc=$(egrep "^[^#]" "${dir}/.ackrc" | tr '\n' ' ')
19 else
20 match=0
21 fi
22 else
23 dir=$(dirname "$dir")
24 fi
25 done
26
27 # Add quote-wrapping for any additional args to ensure proper passing to
28 # real 'ack'.
29 for arg in "$@"; do ackrc="${ackrc} '${arg}'"; done
30
31 # Run the final command
32 eval "${ack} ${ackrc}"