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 "cdbranch" command to change directory to the various branches that I have checked out.<br>
<br>Usage:<br><br>cdbranch <project> <branch> = Change directory to a specific project branch<br>cdbranch <project> = 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> eval cd $(_combinator_branchDir $@)<br>}<br><br>_cdbranch ()<br>{<br> local cur=${COMP_WORDS[$COMP_CWORD]};<br> case ${COMP_CWORD} in<br>
1)<br> _completeproject;<br> return $?<br> ;;<br> 2)<br> local project=$3;<br> local blist=`svn ls --non-interactive "$(_combinator_branchURI $project)"`;<br>
blist=`echo "$blist" | sed -e 's,/,,g'`;<br> COMPREPLY=($(compgen -W "$blist" -- $cur));<br> return 0<br> ;;<br> esac<br>}<br><br>function _combinator_branchDir() {<br>
local projectName=$1;<br> local branchName=$2;<br> if [ ! $branchName ] ; then<br> local buri=`python -c "\<br><br>import sys<br>from combinator.branchmgr import theBranchManager as bm<br>branch = 'trunk'<br>
for k, v in bm.getCurrentBranches():<br> if k.lower() == sys.argv[1].lower():<br> branch = v<br> break<br>print bm.projectBranchDir(sys.argv[1], branch)<br><br>" "$projectName"`<br><br> else<br>
local buri=`python -c "\<br><br>import sys<br>from combinator.branchmgr import theBranchManager as bm<br>print bm.projectBranchDir(sys.argv[1], sys.argv[2])<br><br>" "$projectName" "$branchName"`<br>
<br> fi<br> echo -n "$buri"<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