Experimental tab completion for ack, the CLI tool going beyond grep
.
$ ack -<tab>
--actionscript
--ada
--after-context
--asm
--asp
--aspx
--bar
--batch
--bazel
--before-context
--break
--cathy
--cc
--cfmx
--clojure
--cmake
--coffeescript
--color
--color-colno
--color-filename
--color-lineno
--color-match
--column
--conf
--context
--count
--cpp
--csharp
--css
--dart
--delphi
--dump
--elisp
--elixir
--elm
--env
--erlang
--files-with-matches
--files-without-matches
--filter
--flush
--follow
--fortran
--go
--groovy
--group
--gsp
--haskell
--heading
--help
--help-colors
--help-rgb-colors
--help-types
--hh
--hpp
--html
--ignore-case
--ignore-dir
--ignore-directory
--ignore-file-r
--invert-match
--jade
--java
--js
--json
--jsp
--known-types
--kotlin
--less
--lisp
--literal
--lua
--make
--man
--markdown
--match
--matlab
--mojo
--no-filename
--no-ignore-case
--no-recurse
--nobreak
--nocolor
--nocolumn
--noenv
--nofilter
--nofollow
--nogroup
--noheading
--noignore-dir
--noignore-directory
--nopager
--nosmart-case
--nounderline
--objc
--objcpp
--ocaml
--output
--pager
--passthru
--pconf
--perl
--perltest
--php
--plone
--pod
--print0
--proximate
--purescript
--python
--rake
--range-end
--range-start
--recurse
--rr
--rst
--ruby
--rust
--sass
--scala
--scheme
--shell
--show-types
--smalltalk
--smart-case
--smarty
--sort-files
--sql
--stylus
--svg
--swift
--tcl
--tex
--thpppt
--toml
--ts
--ttml
--type
--underline
--vb
--verilog
--version
--vhdl
--vim
--with-filename
--word-regexp
--xml
--yaml
-1
-A
-B
-c
-C
-f
-g
-h
-H
-i
-I
-k
-l
-L
-n
-o
-p
-Q
-R
-s
-S
-t
-T
-v
-w
-x
It also supports definitions from your $HOME/.ackrc
, so the above list might look different in your local environment.
The example ackrc
based on my TIL
--type-set=mojo=.css,.pl,.pm,.html,.js,.tt,.ep,.conf
--type-set=conf=.conf
--type-set=conf=.pconf
Would work as follows, listing your custom types among ALL of the other options:
$ ack -<tab>
--mojo --conf --pconf
$ ack <tab>
.editorconfig CONTRIBUTING.md bash_completion_ack.code-workspace
.git/ LICENSE bash_completion_ack.sublime-project
.gitattributes README.md bash_completion_ack.sublime-workspace
.gitignore ack
List contents of directory as default for bash
.
If you tab after your completion has been made the contents of the current directory is displayed:
$ ack --mojo <tab>
.editorconfig CONTRIBUTING.md bash_completion_ack.code-workspace
.git/ LICENSE bash_completion_ack.sublime-project
.gitattributes README.md bash_completion_ack.sublime-workspace
.gitignore ack
curl https://raw.githubusercontent.com/jonasbn/bash_completion_ack/master/ack > ack
When downloaded you have to install the completion implementation. Where your completions are located might vary.
If you want to install them for your personal use, do the following.
Create the file: ~/.bash_completion
, containing the code below:
for bcfile in ~/.bash_completion.d/* ; do
. $bcfile
done
Ref: ServerFault.com: Standard place for user defined bash_completion.d scripts?
Create a directory for your completions:
mkdir ~/.bash_completion.d
Copy your completions into the newly created directory:
cp ack ~/.bash_completion.d/
Start a new shell and you should be good to go.
Based on an introduction to bash
completions on Debian.
sudo cp ack /etc/bash_completion.d/
This assumes you are using Homebrew
Do note that paths vary based on whether you are using bash
3 or 4
cp ack /usr/local/etc/bash_completion.d/
And to activate right away:
source /usr/local/etc/bash_completion.d/ack
cp ack /usr/local/share/bash-completion/completions/
And to activate right away:
source /usr/local/share/bash-completion/completions/ack
The programmatic capabilities discovered while implementing my first bash
completions intrigued me. This is a highly experimental feature, which nevertheless was lots of fun to implement.
-
2.2.1
- Bug fix release, addressing issue introduced in 2.2.0, making the defaults not work
-
2.2.0
- Major contribution from @rpgoldman expanding the capabilities of this tool extensively
-
2.1.0
- Minor adjustment to behaviour, post completions, the contents of the current directory is listed
-
2.0.0
- Initial version working with
bash
version 4. - Change to behaviour,
-
have to be entered for detected options to be listed
- Initial version working with
-
1.0.0
- Initial version working with
bash
version 3.
- Initial version working with
A more elaborate piece of documentation on bash
completions is available from The Linux Documentation Project in the Advanced Bash-Scripting Guide.
From the GNU Documentation.
Please note that this experimental implementation has only been tested with bash
version 3 (see version 1.0.0).
Versions after version 1.0.0 have been tested with bash
version 4.
The most comprehensive collection of bash
completions I have come across is the one from the Debian Linux distribution. It is also the one offered for OSX via Homebrew.
This is made available under the MIT license, see separate license file.
©️ jonasbn 2016-2022