Scratchpad/kdesrc-build-autocompletion

Jump to: navigation, search

IMPORTANT: Feel free to fix this in any way necessary, I'll leave it here for a bit of time and then move it to https://techbase.kde.org/Getting_Started/Build/kdesrc-build

Copy the script below and paste it into /etc/bash_completion.d/kdesrc-build (this is on *buntu, your distro may vary).

You must have xml2 installed for this to work.

#!/bin/bash

_kdesrc_build()
{
#first try if there's kdesrc-buildrc in current path
    FILE=$PWD/kdesrc-buildrc
    if [ ! -f $FILE ]; then
#if not, try the path of kdesrc-build
        TEMP=$1
        FILE=${TEMP%/*}/kdesrc-buildrc
    fi

#finally try the default ~/.kdesrc-buildrc
    if [ ! -f $FILE ]; then
        FILE="~/.kdesrc-buildrc"
    fi

    if [ ! -f $FILE ]; then
        echo "Cannot find kdesrc-buildrc"
        return 1
    else
#get the source-dir from the config, which contains the kde_projects.xml file
        XMLFILE=`grep "source-dir" $FILE | awk -F" " '{ print $2 }'`
        XMLFILE="$XMLFILE/kde_projects.xml"
    fi

    COMPREPLY=()
    COMPLETION=(`xml2 < $XMLFILE | grep "project/@identifier" | sed 's/^\/.*[=]\(.*\)$/\1/'`)
    COMPREPLY=($(compgen -W "${COMPLETION[*]}" -- ${COMP_WORDS[COMP_CWORD]}))
    return 0
}

complete -F _kdesrc_build kdesrc-build
complete -F _kdesrc_build ./kdesrc-build

This page was last modified on 27 December 2014, at 16:28. Content is available under Creative Commons License SA 4.0 unless otherwise noted.