-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathack
85 lines (80 loc) · 3.18 KB
/
ack
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Bash completion for ack:
# ack <tab>
#
# Github: https://github.com/jonasbn/bash_completion_ack
# Copyright Jonas B. Nielsen (jonasbn) 2017
# Extentions Copyright Robert P. Goldman (rpgoldman) and SIFT, LLC (siftech) 2022
# MIT License
_acktypes=$(ack --help-types | tail -n +10 | awk '{gsub(/^[ \t]+/,"",$1); print$1;}')
_acktypeargs=$(echo "${_acktypes}" | perl -ne 'chomp; print("--${_} ");')
_negacktypes=$(echo "${_acktypes}" | perl -ne 'chomp; print("no${_} ");')
_acktypes=$(echo "${_acktypes}" | perl -ne 'chomp; print("${_} ");')
_ack()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
local opts="${_acktypeargs}"
# File select actions:
opts+=" -f -g -l"
# File listing actions
opts+=" --files-with-matches -L --files-without-matches -c --count"
# Searching
opts+=" -i --ignore-case -S --smart-case --nosmart-case -I --no-ignore-case -v --invert-match -w --word-regexp"
opts+=" -Q --literal"
opts+=" --range-start --range-end --match"
# Search output
opts+=" --output -o --passthru -1 -H --with-filename -h --no-filename --column --nocolumn --print0"
opts+=" -A --after-context -B --before-context -C --context"
# File presentation
opts+=" -s --pager --nopager --heading --noheading --break --nobreak --group --nogroup -p --proximate --underline --nounderline"
opts+=" --nocolor --color --help-colors --help-rgb-colors --flush"
opts+=" --color-filename --color-match --color-colno --color-lineno"
# File finding
opts+=" --sort-files --show-types -x"
# File inclusion/exclusion:
opts+=" --ignore-dir --noignore-dir --ignore-directory --noignore-directory --ignore-file"
opts+="-r -R --recurse -n --no-recurse --follow --nofollow"
# File type inclusion/exclusion:
opts+=" -k --known-types --help-types --type -t -T"
# miscellaneous args
opts+=" --version --env --noenv --dump --filter --nofilter --help --man"
opts+=" --thpppt --bar --cathy"
case $prev in
# searching commands require patterns, count arguments require numbers
-m | --max-count | -A | --after-context | \
-B | --before-context | -C | --context | \
-p | --proximate | \
--range-start | --range-end | -match | --output | \
--pager | \
--color-filename | --color-match | --color-colno | --color-lineno | \
--ignore-file | \
--type-set | --type-add | --type-del)
# argument required but no completions available
return
;;
--files-from )
COMPREPLY=($(compgen -f))
return
;;
--ignore-dir | --noignore-dir | --ignore-directory | --noignore-directory )
COMPREPLY=($(compgen -d))
return
;;
-t | -T)
COMPREPLY=($(compgen -W "${_acktypes}"))
return
;;
--type)
COMPREPLY=($(compgen -W "${_acktypes}${_negacktypes}"))
return
;;
esac
if [[ "$cur" == -* ]]; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
else
compopt -o default
fi
}
complete -F _ack ack -o default