# -*-eselect-*- vim: ft=eselect # Copyright 2005-2013 Gentoo Foundation # Distributed under the terms of the GNU GPL version 2 or later DESCRIPTION="Manage contributed bash-completion scripts" MAINTAINER="eselect@gentoo.org" COMPLETIONS_DIR=${EROOT%/}/usr/share/bash-completion/completions COMPLETIONS_BLACKLIST=${EROOT%}/etc/bash/completion.blacklist find_targets() { local bc # Note: safe to cd, we're in a subshell cd "${COMPLETIONS_DIR}" || die for bc in *; do [[ -f ${bc} && ${bc} != *~ ]] && echo "${bc}" done | sort -u } is_enabled() { ! grep -q -s "^${1}$" "${COMPLETIONS_BLACKLIST}" } post_update() { # adjust permissions if necessary chmod a+r "${COMPLETIONS_BLACKLIST}" || die echo "For the changes to apply to open shells, you may need to run:" echo " complete -r ${*}" echo "in each of them." } ### list action ### describe_list() { echo "List available completions" } do_list() { local targets i targets=( $(find_targets) ) for (( i = 0; i < ${#targets[@]}; i++ )); do is_enabled ${opts} "${targets[i]}" \ && targets[i]=$(highlight_marker "${targets[i]}") done write_list_start "Available completions:" write_numbered_list -m "(none found)" "${targets[@]}" } ### enable action ### describe_enable() { echo "Enable specified completion(s)" } describe_enable_parameters() { echo "" } describe_enable_options() { echo " : Target name or number (from 'list' action)" } do_enable() { [[ $# -eq 0 ]] && die -q "You didn't specify any completions to enable." local bc target targets=( $(find_targets) ) changed=() for bc; do target=${bc} is_number "${target}" && target=${targets[target-1]} [[ -z ${target} || ${target} == */* ]] \ && die -q "Target \"${bc}\" doesn't appear to be valid!" bc=${target} # not on blacklist? if is_enabled "${bc}"; then # does it exist? if ! has "${bc}" "${targets[@]}"; then write_error_msg "${bc} doesn't exist" continue fi write_warning_msg "${bc} is not disabled" continue fi # enable it sed -i -e "/^${bc}$/d" "${COMPLETIONS_BLACKLIST}" || die changed+=( "${bc}" ) done post_update "${changed[@]}" } ### disable action ### describe_disable() { echo "Disable specified completion(s)" } describe_disable_parameters() { echo "" } describe_disable_options() { echo " : Target name or number (from 'list' action)" } do_disable() { [[ $# -eq 0 ]] && die -q "You didn't specify any completions to enable." local bc target targets=( $(find_targets) ) changes=() for bc; do target=${bc} is_number "${target}" && target=${targets[target-1]} [[ -z ${target} || ${target} == */* ]] \ && die -q "Target \"${bc}\" doesn't appear to be valid!" bc=${target} # already disabled? if ! is_enabled "${bc}"; then write_warning_msg "${bc} is not enabled" continue fi # does it exist? if ! has "${bc}" "${targets[@]}"; then write_error_msg "${bc} doesn't exist" continue fi # disable it echo "${bc}" >> "${COMPLETIONS_BLACKLIST}" || die changes+=( "${bc}" ) done post_update "${changes[@]}" }