Package: ack-grep
Version: 1.92-1
Severity: normal
Tags: patch

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The bash auto-completion bundled with ack-grep adds an extra space after the 
slash. E.g., if _ is the cursor:
$ ack-grep foo /home_<tab>
results in
$ ack-grep foo /home/ _

This means that pressing tab again will give auto-complete options from the 
current working directory instead of /home/. Compare with the auto-completion 
for ls:
$ ls /ho_<tab>
$ ls /home/_

Apparently the fix is as simple as changing the two lines at the bottom for 
this:
complete -F _ack $filenames ack
complete -F _ack $filenames ack-grep

And then:
$ source /etc/bash_completion

However before I found that simple solution I spent some time cleaning up this 
file and I ended up with the attached file. I believe it works as the previous 
one, if not better, but this is the second time I play with Bash 
auto-completion, so I cannot be sure. I based my changes on 
/etc/bash_completion.d/findutils and the completion for ls, rmdir, etc in 
/etc/bash_completion. One small advantage of my version is that when Bash shows 
the alternative completions for a directory it only shows one slash at the end, 
where the current version (with the $filenames fix) shows two, which works but 
looks ugly. E.g., mine:
$ ack-grep foo /etc/<tab>
acpi//                   group-                   papersize

Current:
/etc/acpi                     /etc/localtime

Note that my proposed version shows relative paths, which saves screen state.


- -- System Information:
Debian Release: squeeze/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (1, 'experimental')
Architecture: i386 (x86_64)

Kernel: Linux 2.6.32-trunk-amd64 (SMP w/2 CPU cores)
Locale: LANG=es_AR.UTF-8, LC_CTYPE=es_AR.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages ack-grep depends on:
ii  libfile-next-perl             1.06-1     file-finding iterator
ii  perl                          5.10.1-8   Larry Wall's Practical Extraction 

ack-grep recommends no packages.

Versions of packages ack-grep suggests:
ii  bash-completion               1:1.1-3    programmable completion for the ba

- -- no debconf information

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iEYEARECAAYFAks0mCgACgkQ823633cP2P9NDACeMtC1XjMWSWqxgUQeDClzwPb6
B+gAnReS1Ie8i0mDJVih2d7sM67kBtPX
=g4n8
-----END PGP SIGNATURE-----
# vim: et ft=sh sts=2 sw=2 ts=2
#
# Copyright 2008-2009 Adam James <a...@pulsewidth.org.uk>
# All rights reserved.
# This program is free software; you can redistribute it and/or modify it
# under the same terms as ack itself.

# ack-grep on Debian distros
type ack &>/dev/null || type ack-grep &>/dev/null && {

shopt -s extglob

_ack()
{
  COMPREPLY=()
  # --help, --man, --thpppt and --version are final 
  # so we return here if they are present
  [[ "${comp_wor...@]}" == \
    *+([[:space:]])--@(help|man|th+(p)t|version)+([[:space:]])* ]] && return 0

  local cur prev lngopt shtopt fnlopt typeopt nopattern
  cur=`_get_cword`
  prev=${COMP_WORDS[COMP_CWORD-1]}

  lngopt='
    --all-types --after-context= --before-context= --context= 
    --count --color --nocolor --env --noenv --flush
    --follow --nofollow --group --nogroup --with-filename
    --no-filename --ignore-case --ignore-dir=
    --noignore-dir= --line= --files-with-matches
    --files-without-matches --match --max-count=
    --output= --pager= --nopager --passthru --print0
    --literal --smart-case --nosmart-case --rc=
    --sort-files --type --type-add --type-set
    --unrestricted --invert-match --word-regexp
    --heading --noheading --break --nobreak --sort-files
  '
  shtopt='
    -a -A -B -C -c
    -f -G -g -H -h
    -i -l -L -m -n
    -o -Q -u -w -1
  '
  fnlopt='--help --man --thpppt --version'

  # try ack-grep first as Debian distributions contain a completely
  # different program called ack.
  typeopt=$(ack-grep --help=types 2>/dev/null || \
            ack --help=types 2>/dev/null |perl -ne \
    'print "--$1 --no$1 " if /^\s+--\[no\](\S+)\s+/' 2>/dev/null)

  # set nopattern to 1 if only listing files
  for i in ${comp_wor...@]}; do
      [[ "$i" = "-f" ]] && nopattern=1 && break
  done

  case "${cur}" in
    # option with argument
    -*=*)
            # split the option and the argument
            opt=${cur%%=*}
            cur=${cur#*=}

            # special cases
            case "${opt}" in
              --?(no)ignore-dir)  # directory matching
                        #COMPREPLY=( $(compgen -d -- "${cur}") )
                        _filedir -d
                        return 0;;
              --rc)     # file matching
                        #COMPREPLY=( $(compgen -f -- "${cur}") )
                        _filedir
                        return 0;;
              --pager)  # command matching
                        COMPREPLY=( $(compgen -c -- "${cur}") )
                        return 0;;
              *)
                        return 0;;
            esac;;
    # option without argument
    -*)
            [[ "${COMP_CWORD}" == 1 ]] && lngopt="${lngopt} ${fnlopt}"

            COMPREPLY=( $(compgen -W \
              "${lngopt} ${shtopt} ${typeopt}" -- "${cur}") )
            return 0;;
    *)
            [[ "$prev" != -* || "$nopattern" == 1 ]] && \
              _filedir
              return 0;;
  esac
}
complete -F _ack $filenames ack
complete -F _ack $filenames ack-grep
}

Reply via email to