Handy Addition to bash scripts for Divmod

"David Giffin" <[email protected]> Fri, 16 May 2008 15:48:01 -0400
Newsgroups gmane.comp.python.quotient.dev
Message-ID <[email protected]>
--===============1998906418==
Content-Type: multipart/alternative; 
	boundary="----=_Part_7950_21825612.1210967281147"

------=_Part_7950_21825612.1210967281147
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi there,

I have an addition to Divmod/trunk/Combinator/bash/completion that I have
been using for a while. It provides the "cdbranch" command to change
directory to the various branches that I have checked out.

Usage:

cdbranch <project> <branch> = Change directory to a specific project branch
cdbranch <project>    = Change directory to the project branch shown in
whbranch

Let me know what you think.

Thanks,
David


Here is the script:

cdbranch ()
{
    eval cd $(_combinator_branchDir $@)
}

_cdbranch ()
{
    local cur=${COMP_WORDS[$COMP_CWORD]};
    case ${COMP_CWORD} in
        1)
            _completeproject;
            return $?
        ;;
        2)
            local project=$3;
            local blist=`svn ls --non-interactive "$(_combinator_branchURI
$project)"`;
            blist=`echo "$blist" | sed -e 's,/,,g'`;
            COMPREPLY=($(compgen -W "$blist" -- $cur));
            return 0
        ;;
    esac
}

function _combinator_branchDir() {
    local projectName=$1;
    local branchName=$2;
    if [ ! $branchName ] ; then
        local buri=`python -c "\

import sys
from combinator.branchmgr import theBranchManager as bm
branch = 'trunk'
for k, v in bm.getCurrentBranches():
    if k.lower() == sys.argv[1].lower():
        branch = v
        break
print bm.projectBranchDir(sys.argv[1], branch)

" "$projectName"`

    else
        local buri=`python -c "\

import sys
from combinator.branchmgr import theBranchManager as bm
print bm.projectBranchDir(sys.argv[1], sys.argv[2])

" "$projectName" "$branchName"`

    fi
    echo -n "$buri"
}

complete -F _cdbranch cdbranch

------=_Part_7950_21825612.1210967281147
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

<br>Hi there, <br><br>I have an addition to Divmod/trunk/Combinator/bash/completion that I have been using for a while. It provides the &quot;cdbranch&quot; command to change directory to the various branches that I have checked out.<br>
<br>Usage:<br><br>cdbranch &lt;project&gt; &lt;branch&gt; = Change directory to a specific project branch<br>cdbranch &lt;project&gt;&nbsp;&nbsp;&nbsp; = Change directory to the project branch shown in whbranch<br><br>Let me know what you think.<br>
<br>Thanks,<br>David<br><br><br>Here is the script:<br><br>cdbranch ()<br>{<br>&nbsp;&nbsp;&nbsp; eval cd $(_combinator_branchDir $@)<br>}<br><br>_cdbranch ()<br>{<br>&nbsp;&nbsp;&nbsp; local cur=${COMP_WORDS[$COMP_CWORD]};<br>&nbsp;&nbsp;&nbsp; case ${COMP_CWORD} in<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _completeproject;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return $?<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local project=$3;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local blist=`svn ls --non-interactive &quot;$(_combinator_branchURI $project)&quot;`;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; blist=`echo &quot;$blist&quot; | sed -e &#39;s,/,,g&#39;`;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; COMPREPLY=($(compgen -W &quot;$blist&quot; -- $cur));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 0<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;;<br>&nbsp;&nbsp;&nbsp; esac<br>}<br><br>function _combinator_branchDir() {<br>
&nbsp;&nbsp;&nbsp; local projectName=$1;<br>&nbsp;&nbsp;&nbsp; local branchName=$2;<br>&nbsp;&nbsp;&nbsp; if [ ! $branchName ] ; then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local buri=`python -c &quot;\<br><br>import sys<br>from combinator.branchmgr import theBranchManager as bm<br>branch = &#39;trunk&#39;<br>
for k, v in bm.getCurrentBranches():<br>&nbsp;&nbsp;&nbsp; if k.lower() == sys.argv[1].lower():<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; branch = v<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break<br>print bm.projectBranchDir(sys.argv[1], branch)<br><br>&quot; &quot;$projectName&quot;`<br><br>&nbsp;&nbsp;&nbsp; else<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local buri=`python -c &quot;\<br><br>import sys<br>from combinator.branchmgr import theBranchManager as bm<br>print bm.projectBranchDir(sys.argv[1], sys.argv[2])<br><br>&quot; &quot;$projectName&quot; &quot;$branchName&quot;`<br>
<br>&nbsp;&nbsp;&nbsp; fi<br>&nbsp;&nbsp;&nbsp; echo -n &quot;$buri&quot;<br>}<br><br>complete -F _cdbranch cdbranch<br><br><br>

------=_Part_7950_21825612.1210967281147--


--===============1998906418==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline