forked from gentoo-perl/genlop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
genlop.bash-completion
60 lines (57 loc) · 1.8 KB
/
genlop.bash-completion
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
# -*- shell-script -*-
# If you have bash completion installed and want genlop to auto-complete
# packages, save this file as /etc/bash_completion.d/genlop
#
# Copyright 1999-2002 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License, v2 or later
#
# Author: Geert Bevin <[email protected]>
# Author: Zach Forrest <[email protected]>
#
# Adapted for genlop by Giorgio Mandolfo <[email protected]>
#
_genlop()
{
local cur grepcmd sedcmd systemactions setsma setbig portagedir origdir args
origdir="${PWD}"
COMPREPLY=()
portagedir="$(portageq envvar PORTDIR 2>/dev/null)"
if [[ -z "${portagedir}" ]]; then
portagedir="/usr/portage"
fi
cur="${COMP_WORDS[COMP_CWORD]}"
builtin cd "${portagedir}"
grepcmd="grep -E ^${cur}.*"
sedcmd="sed -e /^[^-]*$/d"
case "${cur}" in
-*)
args='-c -e -f -h -i -g -l -n -p -r -s -S -t -u -v'
args="${args} --current --date --file --gmt --help \
--info --list --nocolor --pretend --rsync \
--search --time --unmerge --version"
COMPREPLY=( $( compgen -W "${args}" -- ${cur} ) )
;;
*)
if [[ "${cur}" ]]; then
if [[ $(echo "${cur}" | grep '/') ]]; then
setbig=$(compgen -G "${cur}*" | ${sedcmd})"${systemactions}"
COMPREPLY=($(echo "${setbig}" | ${grepcmd}))
else
setsma=$(compgen -S '/' -G "${cur}*" | ${sedcmd})"${systemactions}"
if [[ $(echo "${setsma}" | ${grepcmd} | grep '/' | wc -l) == 1 ]]; then
setbig=$(compgen -G "*/*" | ${sedcmd})"${systemactions}"
COMPREPLY=($(echo "${setbig}" | ${grepcmd}))
else
COMPREPLY=($(echo "${setsma}" | ${grepcmd}))
fi
fi
else
setsma=$(compgen -S '/' -G "${cur}*" | ${sedcmd})"${systemactions}"
COMPREPLY=($(echo "${setsma}"))
fi
;;
esac
builtin cd "${origdir}"
return 0
}
complete -o default -F _genlop genlop