| 1 | # Copyright 1999-2005 Gentoo Foundation |
1 | # Copyright 1999-2011 Gentoo Foundation |
| 2 | # Distributed under the terms of the GNU General Public License v2 |
2 | # Distributed under the terms of the GNU General Public License v2 |
| 3 | # $Header: /var/cvsroot/gentoo-x86/eclass/bash-completion.eclass,v 1.1.1.1 2005/11/30 09:59:22 chriswhite Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/bash-completion.eclass,v 1.27 2011/08/22 04:46:31 vapier Exp $ |
| 4 | # |
4 | |
|
|
5 | # @ECLASS: bash-completion.eclass |
|
|
6 | # @MAINTAINER: |
|
|
7 | # shell-tools@gentoo.org. |
|
|
8 | # @AUTHOR: |
|
|
9 | # Original author: Aaron Walker <ka0ttic@gentoo.org> |
|
|
10 | # @BLURB: An Interface for installing contributed bash-completion scripts |
|
|
11 | # @DESCRIPTION: |
| 5 | # Simple eclass that provides an interface for installing |
12 | # Simple eclass that provides an interface for installing |
| 6 | # contributed (ie not included in bash-completion proper) |
13 | # contributed (ie not included in bash-completion proper) |
| 7 | # bash-completion scripts. |
14 | # bash-completion scripts. |
| 8 | # |
15 | |
| 9 | # Author: Aaron Walker <ka0ttic@gentoo.org> |
16 | # @ECLASS-VARIABLE: BASHCOMPLETION_NAME |
| 10 | # |
17 | # @DESCRIPTION: |
| 11 | # Please assign any bug reports to shell-tools@gentoo.org. |
18 | # Install the completion script with this name (see also dobashcompletion) |
|
|
19 | |
|
|
20 | # @ECLASS-VARIABLE: BASHCOMPFILES |
|
|
21 | # @DESCRIPTION: |
|
|
22 | # Space delimited list of files to install if dobashcompletion is called without |
|
|
23 | # arguments. |
| 12 | |
24 | |
| 13 | EXPORT_FUNCTIONS pkg_postinst |
25 | EXPORT_FUNCTIONS pkg_postinst |
| 14 | |
26 | |
| 15 | IUSE="bash-completion" |
27 | IUSE="bash-completion" |
| 16 | |
28 | |
| 17 | # bash-completion-config is deprecated in favor of eselect, |
29 | # Allow eclass to be inherited by eselect without a circular dependency |
| 18 | # however, eselect currently lacks stable keywords. |
30 | if [[ ${CATEGORY}/${PN} != app-admin/eselect ]]; then |
| 19 | RDEPEND="bash-completion? |
31 | RDEPEND="bash-completion? ( app-admin/eselect )" |
| 20 | ( || ( |
32 | fi |
| 21 | app-admin/eselect |
33 | PDEPEND="bash-completion? ( app-shells/bash-completion )" |
| 22 | app-shells/bash-completion-config |
|
|
| 23 | ) |
|
|
| 24 | )" |
|
|
| 25 | |
34 | |
| 26 | # dobashcompletion <file> <new file> |
35 | # @FUNCTION: dobashcompletion |
| 27 | # First arg, <file>, is required and is the location of the bash-completion |
36 | # @USAGE: [file] [new_file] |
| 28 | # script to install. If the variable BASH_COMPLETION_NAME is set in the |
37 | # @DESCRIPTION: |
| 29 | # ebuild, dobashcompletion will install <file> as |
38 | # The first argument is the location of the bash-completion script to install, |
| 30 | # /usr/share/bash-completion/$BASH_COMPLETION_NAME. If it is not set, |
39 | # and is required if BASHCOMPFILES is not set. The second argument is the name |
| 31 | # dobashcompletion will check if a second arg ($2) was passed, installing as |
40 | # the script will be installed as. If BASHCOMPLETION_NAME is set, it overrides |
| 32 | # the specified name. Failing both these checks, dobashcompletion will |
41 | # the second argument. If no second argument is given and BASHCOMPLETION_NAME |
| 33 | # install the file as /usr/share/bash-completion/${PN}. |
42 | # is not set, it will default to ${PN}. |
|
|
43 | dobashcompletion() { |
|
|
44 | local f |
| 34 | |
45 | |
| 35 | dobashcompletion() { |
46 | if [[ -z ${1} && -z ${BASHCOMPFILES} ]]; then |
| 36 | [[ -z "$1" ]] && die "usage: dobashcompletion <file> <new file>" |
47 | die "Usage: dobashcompletion [file] [new file]" |
| 37 | [[ -z "${BASH_COMPLETION_NAME}" ]] && BASH_COMPLETION_NAME="${2:-${PN}}" |
48 | fi |
| 38 | |
49 | |
| 39 | if useq bash-completion ; then |
50 | if use bash-completion; then |
| 40 | insinto /usr/share/bash-completion |
51 | insinto /usr/share/bash-completion |
|
|
52 | if [[ -n ${1} ]]; then |
|
|
53 | [[ -z ${BASHCOMPLETION_NAME} ]] && BASHCOMPLETION_NAME="${2:-${PN}}" |
| 41 | newins "$1" "${BASH_COMPLETION_NAME}" || die "Failed to install $1" |
54 | newins "${1}" "${BASHCOMPLETION_NAME}" || die "Failed to install ${1}" |
|
|
55 | else |
|
|
56 | set -- ${BASHCOMPFILES} |
|
|
57 | for f in "$@"; do |
|
|
58 | if [[ -e ${f} ]]; then |
|
|
59 | doins "${f}" || die "Failed to install ${f}" |
|
|
60 | fi |
|
|
61 | done |
|
|
62 | fi |
| 42 | fi |
63 | fi |
| 43 | } |
64 | } |
| 44 | |
65 | |
|
|
66 | # @FUNCTION: bash-completion_pkg_postinst |
|
|
67 | # @DESCRIPTION: |
|
|
68 | # The bash-completion pkg_postinst function, which is exported |
| 45 | bash-completion_pkg_postinst() { |
69 | bash-completion_pkg_postinst() { |
|
|
70 | local f |
|
|
71 | |
| 46 | if useq bash-completion ; then |
72 | if use bash-completion ; then |
| 47 | echo |
73 | elog "The following bash-completion scripts have been installed:" |
| 48 | einfo "To enable command-line completion for ${PN}, run:" |
74 | if [[ -n ${BASHCOMPLETION_NAME} ]]; then |
| 49 | einfo |
75 | elog " ${BASHCOMPLETION_NAME}" |
| 50 | if has_version app-admin/eselect ; then |
|
|
| 51 | einfo " eselect bashcomp enable ${BASH_COMPLETION_NAME:-${PN}}" |
|
|
| 52 | else |
76 | else |
| 53 | einfo " bash-completion-config --install ${BASH_COMPLETION_NAME:-${PN}}" |
77 | set -- ${BASHCOMPFILES} |
| 54 | einfo |
78 | for f in "$@"; do |
| 55 | einfo "to install locally, or" |
79 | elog " $(basename ${f})" |
| 56 | einfo |
80 | done |
| 57 | einfo " bash-completion-config --global --install ${BASH_COMPLETION_NAME:-${PN}}" |
|
|
| 58 | einfo |
|
|
| 59 | einfo "to install system-wide." |
|
|
| 60 | einfo "Read bash-completion-config(1) for more information." |
|
|
| 61 | fi |
81 | fi |
| 62 | echo |
82 | elog |
|
|
83 | elog "To enable command-line completion on a per-user basis run:" |
|
|
84 | elog " eselect bashcomp enable <script>" |
|
|
85 | elog |
|
|
86 | elog "To enable command-line completion system-wide run:" |
|
|
87 | elog " eselect bashcomp enable --global <script>" |
| 63 | fi |
88 | fi |
| 64 | } |
89 | } |