blob: d7800993039a8c18962f8ac0bbd3c11bb9d90792 (
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/eclass/bash-completion-r1.eclass,v 1.9 2013/07/23 13:48:00 mgorny Exp $
# @ECLASS: bash-completion-r1.eclass
# @MAINTAINER:
# mgorny@gentoo.org
# @BLURB: A few quick functions to install bash-completion files
# @EXAMPLE:
#
# @CODE
# EAPI=5
#
# src_configure() {
# econf \
# --with-bash-completion-dir="$(get_bashcompdir)"
# }
#
# src_install() {
# default
#
# newbashcomp contrib/${PN}.bash-completion ${PN}
# }
# @CODE
inherit toolchain-funcs
case ${EAPI:-0} in
0|1|2|3|4|5) ;;
*) die "EAPI ${EAPI} unsupported (yet)."
esac
# @FUNCTION: _bash-completion-r1_get_bashdir
# @INTERNAL
# @DESCRIPTION:
# First argument is name of the string in bash-completion.pc
# Second argument is the fallback directory if the string is not found
# @EXAMPLE:
# _bash-completion-r1_get_bashdir completionsdir /usr/share/bash-completion/completions
_bash-completion-r1_get_bashdir() {
debug-print-function ${FUNCNAME} "${@}"
if $(tc-getPKG_CONFIG) --exists bash-completion; then
local path="$($(tc-getPKG_CONFIG) --variable=$1 bash-completion)"
# we need to return unprefixed, so strip from what pkg-config returns
# to us, bug #477692
echo "${path#${EPREFIX}}"
else
echo $2
fi
}
# @FUNCTION: _bash-completion-r1_get_bashcompdir
# @INTERNAL
# @DESCRIPTION:
# Get unprefixed bash-completion completions directory.
_bash-completion-r1_get_bashcompdir() {
debug-print-function ${FUNCNAME} "${@}"
if has_version '<app-shells/bash-completion-2.1-r1'; then
_bash-completion-r1_get_bashdir completionsdir /usr/share/bash-completion
else
_bash-completion-r1_get_bashdir completionsdir /usr/share/bash-completion/completions
fi
}
# @FUNCTION: _bash-completion-r1_get_helpersdir
# @INTERNAL
# @DESCRIPTION:
# Get unprefixed bash-completion helpers directory.
_bash-completion-r1_get_bashhelpersdir() {
debug-print-function ${FUNCNAME} "${@}"
_bash-completion-r1_get_bashdir helpersdir /usr/share/bash-completion/helpers
}
# @FUNCTION: get_bashcompdir
# @DESCRIPTION:
# Get the bash-completion completions directory.
get_bashcompdir() {
debug-print-function ${FUNCNAME} "${@}"
echo "${EPREFIX}$(_bash-completion-r1_get_bashcompdir)"
}
# @FUNCTION: get_bashhelpersdir
# @INTERNAL
# @DESCRIPTION:
# Get the bash-completion helpers directory.
get_bashhelpersdir() {
debug-print-function ${FUNCNAME} "${@}"
echo "${EPREFIX}$(_bash-completion-r1_get_bashhelpersdir)"
}
# @FUNCTION: dobashcomp
# @USAGE: file [...]
# @DESCRIPTION:
# Install bash-completion files passed as args. Has EAPI-dependant failure
# behavior (like doins).
dobashcomp() {
debug-print-function ${FUNCNAME} "${@}"
(
insinto "$(_bash-completion-r1_get_bashcompdir)"
doins "${@}"
)
}
# @FUNCTION: newbashcomp
# @USAGE: file newname
# @DESCRIPTION:
# Install bash-completion file under a new name. Has EAPI-dependant failure
# behavior (like newins).
newbashcomp() {
debug-print-function ${FUNCNAME} "${@}"
(
insinto "$(_bash-completion-r1_get_bashcompdir)"
newins "${@}"
)
}
|