1 ;;; pcmpl-ack.el --- completion for ack tool
3 ;; Copyright (C) 2012 Leo Liu
5 ;; Author: Leo Liu <sdl.web@gmail.com>
6 ;; Keywords: tools, processes, convenience
9 ;; This program is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
24 ;; Provide pcompletion support for the cli tool `ack' which can be
25 ;; downloaded from http://betterthangrep.com.
28 ;; (autoload 'pcomplete/ack "pcmpl-ack")
31 ;; - To complete short options type '-' first
32 ;; - To complete long options type '--' first
33 ;; - Color name completion is also supported following
34 ;; --color-filename=, --color-match= and --color-lineno=.
40 (defvar pcmpl-ack-short-options
41 (mapconcat (lambda (o) (substring o 1))
42 '("-a" "-A" "-B" "-C" "-c" "-f" "-G" "-g"
43 "-H" "-h" "-i" "-l" "-L" "-m" "-n"
47 "Short options for the `ack' command.")
49 (defvar pcmpl-ack-long-options
67 "--files-with-matches"
68 "--files-without-matches"
106 "Long options for the `ack' command.")
108 (defvar pcmpl-ack-color-options
132 "Color names for the `ack' command.")
135 (defun pcomplete/ack ()
136 "Completion for the `ack' command.
137 Start an argument with '-' to complete short options and '--' for
140 (add-to-list 'pcomplete-suffix-list ?=)
142 (if (pcomplete-match "^-" 0)
144 ((pcomplete-match "^--color-\\w+=\\(\\S-*\\)" 0)
145 (pcomplete-here* pcmpl-ack-color-options
146 (pcomplete-match-string 1 0) t))
147 ((pcomplete-match "^--\\(?:no\\)?ignore-dir=\\(\\S-*\\)" 0)
148 (pcomplete-here* (pcomplete-dirs)
149 (pcomplete-match-string 1 0) t))
150 ((pcomplete-match "^--" 0)
151 (pcomplete-here* pcmpl-ack-long-options))
152 (t (pcomplete-opt pcmpl-ack-short-options)))
153 (pcomplete-here* (pcomplete-dirs-or-entries)))))
156 (defalias 'pcomplete/ack-grep 'pcomplete/ack)
159 ;;; pcmpl-ack.el ends here