Difference between revisions of "Scratchpad/kdesrc-build-autocompletion"

Jump to: navigation, search
(Initial page content; autocompletion script v1.0)
 
(add comments)
 
Line 10: Line 10:
 
_kdesrc_build()
 
_kdesrc_build()
 
{
 
{
 +
#first try if there's kdesrc-buildrc in current path
 
     FILE=$PWD/kdesrc-buildrc
 
     FILE=$PWD/kdesrc-buildrc
 
     if [ ! -f $FILE ]; then
 
     if [ ! -f $FILE ]; then
 +
#if not, try the path of kdesrc-build
 
         TEMP=$1
 
         TEMP=$1
 
         FILE=${TEMP%/*}/kdesrc-buildrc
 
         FILE=${TEMP%/*}/kdesrc-buildrc
 
     fi
 
     fi
  
 +
#finally try the default ~/.kdesrc-buildrc
 
     if [ ! -f $FILE ]; then
 
     if [ ! -f $FILE ]; then
 
         FILE="~/.kdesrc-buildrc"
 
         FILE="~/.kdesrc-buildrc"
Line 24: Line 27:
 
         return 1
 
         return 1
 
     else
 
     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=`grep "source-dir" $FILE | awk -F" " '{ print $2 }'`
 
         XMLFILE="$XMLFILE/kde_projects.xml"
 
         XMLFILE="$XMLFILE/kde_projects.xml"

Latest revision as of 16:28, 27 December 2014

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 edited on 27 December 2014, at 16:28. Content is available under Creative Commons License SA 4.0 unless otherwise noted.