From dc41e6c152bc377568b170d3bc6127fa417de2e1 Mon Sep 17 00:00:00 2001 From: Tony Duckles Date: Sun, 3 Mar 2013 15:59:08 -0600 Subject: [PATCH] bin/ack-wrapper: Use ack-wrapper Creating a bridge script for allowing directory-level additional .ackrc settings but without overriding the default $HOME/.ackrc settings. This allows for directory/project-specific .ackrc files, e.g. for project-specific --ignore-dir settings. --- .ackrc | 2 ++ .bashrc | 7 +++---- bin/ack-wrapper | 26 ++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) create mode 100755 bin/ack-wrapper diff --git a/.ackrc b/.ackrc index 443c757..34763f2 100644 --- a/.ackrc +++ b/.ackrc @@ -12,6 +12,8 @@ # no grouping --noheading --break +# always use a PAGER +--pager=less # Ack Type Settings # #################################################################### diff --git a/.bashrc b/.bashrc index 891f80c..d9defe0 100644 --- a/.bashrc +++ b/.bashrc @@ -141,10 +141,6 @@ else fi export PAGER MANPAGER -# ack -ACK_PAGER="$PAGER" -ACK_PAGER_COLOR="$PAGER" - # ---------------------------------------------------------------------- # PROMPT # ---------------------------------------------------------------------- @@ -268,6 +264,9 @@ settitle() { printf "\033k%s\033\\" "$@" } +# ack-wrapper +alias ack="ack-wrapper" + # ---------------------------------------------------------------------- # BASH COMPLETION # ---------------------------------------------------------------------- diff --git a/bin/ack-wrapper b/bin/ack-wrapper new file mode 100755 index 0000000..49e5386 --- /dev/null +++ b/bin/ack-wrapper @@ -0,0 +1,26 @@ +#!/bin/sh +# Wrapper around 'ack' to crawl all directories from $PWD to / (or $HOME) +# looking for a "local" .ackrc file. Useful for setting project-level +# --ignore-dir settings. + +PWD=$(pwd) +HOME=~ +ACKARGS="" + +match="" +dir="$PWD" +while [ "$dir" != "/" -a "$match" = "" ]; do + if [ -e "$dir/.ackrc" ]; then + if [ "$dir" != "$HOME" ]; then + match=1 + echo "(Include: ${dir}/.ackrc)" + ACKARGS="$(egrep "^[^#]" "${dir}/.ackrc" | xargs) $ACKARGS" + else + match=0 + fi + else + dir=$(dirname "$dir") + fi +done + +command ack $ACKARGS $* -- 2.47.1