summaryrefslogtreecommitdiff
blob: ad03d86c88c914112bea5e5b70cdc5d4f9a76cba (plain)
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 plop to auto-complete 
# packages, save this file as /etc/bash_completion.d/plop
#
# Copyright 1999-2002 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License, v2 or later
#
# Author: Geert Bevin  <gbevin@theleaf.be>
# Author: Zach Forrest <zach@disinformation.ca>
#
# Adapted for genlop by Giorgio Mandolfo <giorgio@pollycoke.org>
# Adapted for plop by Tobias Hommel <software@genoetigt.de>
#
_plop()
{
        local cur grepcmd sedcmd systemactions setsma setbig portagedir origdir

        origdir="${PWD}"
	COMPREPLY=()
# whoa, what a funny construction
	portagedir="$( echo `eval echo $(grep '^location' /etc/paludis/repositories/gentoo.conf|sed 's/^location = \(.*\)/\1/')` )"
        if [ -z "${portagedir}" ]; then
            portagedir=/usr/portage
        fi
        cur="${COMP_WORDS[COMP_CWORD]}"

        cd "${portagedir}"
        grepcmd="grep -E ^${cur}.*"
        sedcmd="sed -e /^[^-]*$/d"
	case "$cur" in
		-*)
			COMPREPLY=( $( compgen -W '--current --file --help \
			--info --gmt --list --nocolor --pretend --rsync \
			--search --time --unmerge --version' -- $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
	
        cd "${origdir}"
        return 0
}
complete -o default -F _plop plop