summaryrefslogtreecommitdiff
blob: b74f95ef6d340dc82afa9b0502c0beb3bc5cf7ac (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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/eclass/bash-completion.eclass,v 1.29 2013/07/05 17:39:10 ulm Exp $

# DEPRECATED
# This eclass has been superseded by bash-completion-r1 eclass.
# Please modify your ebuilds to use that one instead.

# @ECLASS: bash-completion.eclass
# @MAINTAINER:
# shell-tools@gentoo.org.
# @AUTHOR:
# Original author: Aaron Walker <ka0ttic@gentoo.org>
# @BLURB: An Interface for installing contributed bash-completion scripts
# @DESCRIPTION:
# Simple eclass that provides an interface for installing
# contributed (ie not included in bash-completion proper)
# bash-completion scripts.
#
# Note: this eclass has been deprecated in favor of bash-completion-r1. Please
# use that one instead.

# @ECLASS-VARIABLE: BASHCOMPLETION_NAME
# @DESCRIPTION:
# Install the completion script with this name (see also dobashcompletion)

# @ECLASS-VARIABLE: BASHCOMPFILES
# @DESCRIPTION:
# Space delimited list of files to install if dobashcompletion is called without
# arguments.

inherit eutils

EXPORT_FUNCTIONS pkg_postinst

IUSE="bash-completion"

# Allow eclass to be inherited by eselect without a circular dependency
if [[ ${CATEGORY}/${PN} != app-admin/eselect ]]; then
	RDEPEND="bash-completion? ( app-admin/eselect )"
fi
PDEPEND="bash-completion? ( app-shells/bash-completion )"

# @FUNCTION: dobashcompletion
# @USAGE: [file] [new_file]
# @DESCRIPTION:
# The first argument is the location of the bash-completion script to install,
# and is required if BASHCOMPFILES is not set. The second argument is the name
# the script will be installed as. If BASHCOMPLETION_NAME is set, it overrides
# the second argument. If no second argument is given and BASHCOMPLETION_NAME
# is not set, it will default to ${PN}.
dobashcompletion() {
	local f

	eqawarn "bash-completion.eclass has been deprecated."
	eqawarn "Please update your ebuilds to use bash-completion-r1 instead."

	if [[ -z ${1} && -z ${BASHCOMPFILES} ]]; then
		die "Usage: dobashcompletion [file] [new file]"
	fi

	if use bash-completion; then
		insinto /usr/share/bash-completion
		if [[ -n ${1} ]]; then
			[[ -z ${BASHCOMPLETION_NAME} ]] && BASHCOMPLETION_NAME="${2:-${PN}}"
			newins "${1}" "${BASHCOMPLETION_NAME}" || die "Failed to install ${1}"
		else
			set -- ${BASHCOMPFILES}
			for f in "$@"; do
				if [[ -e ${f} ]]; then
					doins "${f}" || die "Failed to install ${f}"
				fi
			done
		fi
	fi
}

# @FUNCTION: bash-completion_pkg_postinst
# @DESCRIPTION:
# The bash-completion pkg_postinst function, which is exported
bash-completion_pkg_postinst() {
	local f

	if use bash-completion ; then
		elog "The following bash-completion scripts have been installed:"
		if [[ -n ${BASHCOMPLETION_NAME} ]]; then
			elog "	${BASHCOMPLETION_NAME}"
		else
			set -- ${BASHCOMPFILES}
			for f in "$@"; do
				elog "	$(basename ${f})"
			done
		fi
		elog
		elog "To enable command-line completion on a per-user basis run:"
		elog "	eselect bashcomp enable <script>"
		elog
		elog "To enable command-line completion system-wide run:"
		elog "	eselect bashcomp enable --global <script>"
	fi
}