|
[Sponsors] |
![]() |
![]() |
#1 |
Member
Johan Spång
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 35
Rep Power: 18 ![]() |
Hi, I created a simple python script (40 lines..) for generating bash complete bindings for application arguments. Example:
~/OpenFOAM/OpenFOAM-1.6.x/applications/bin> foamToVTK - [TAB] -allPatches -case -constant -excludePatches -fields -latestTime -noFaceZones -noLinks -noZero -pointSet -srcDoc -time -ascii -cellSet -doc -faceSet -help -nearCellValue -noInternal -noPointValues -parallel -region -surfaceFields -useTimeName To get foamToVTK -latestTime, only foamToVTK -l [TAB] has to be typed in. The bindings are really basic and only concerns arguments starting with a ' - ' Code:
#basic script for generating bash complete bindings. import os, subprocess rootdirs=['/home/josp/OpenFOAM/OpenFOAM-1.6.x/applications/bin/linux64GccDPOpt/', '/home/josp/OpenFOAM/josp-1.6.x/applications/bin/linux64GccDPOpt'] outFile='./complete_OpenFOAM' def createFunction(file, arguments): return '_OpenFOAMcomplete'+file+'()\n{\n local cur prev opts\n COMPREPLY=()\n cur="${COMP_WORDS[COMP_CWORD]}"\n \ prev="${COMP_WORDS[COMP_CWORD-1]}"\n opts="' + arguments+'"\n if [[ ${cur} == -* ]] ; then\n COMPREPLY\ =( $(compgen -W "${opts}" -- ${cur}) )\n return 0\n fi\n\ if [[ ${prev} == * ]] ; then\n COMPREPLY=( $(compgen -f ${cur}) )\n return 0\n fi\n}\n' text = [] execs = [] all=[] # Grab executable output on -help argument for rootdir in rootdirs: for subdir, dirs, files in os.walk(rootdir): for file in files: print file p =subprocess.Popen([file, '-help'], stdout = subprocess.PIPE) if p.wait() == 0: # Check that the executable makes a clean exit, otherwise skip execs.append(file) text.append(p.communicate()[0].strip('\n')) # Parse options, really messy. It's probably better to use an xml parser but this works for now.. for i in execs: parsed = text[execs.index(i)].split(i)[-1].split('>')[-1].lstrip(' ').replace(' ', ' ').split('] ') result = '' for k in parsed: j = k.split(' ')[0] for q in j: result += q.lstrip('[').rstrip(']').strip(' ') all.append([i, result.replace('-', ' -').lstrip(' '), len(result)]) # Write the bindings to specified outFile f = open(outFile, 'w') for i in all: f.write(createFunction(str(all.index(i)), i[1])+"complete -F _OpenFOAMcomplete"+str(all.index(i)) + " " + i[0] + "\n\n") f.close() Feel free to modify and improve. Last edited by josp; May 3, 2010 at 10:00. Reason: The script was blocking file completion |
|
![]() |
![]() |
![]() |
![]() |
#2 |
Senior Member
Anton Kidess
Join Date: May 2009
Location: Germany
Posts: 1,377
Rep Power: 30 ![]() |
Great, thanks for sharing! Instead of having to manually specify the rootdirs, you can use the environment variables $FOAM_APPBIN and $FOAM_USER_APPBIN.
|
|
![]() |
![]() |
![]() |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
mesh a complete plane | horsee | FLUENT | 13 | April 17, 2010 20:20 |
how to view the complete results | shokry | FLOW-3D | 5 | February 3, 2009 13:56 |
FLOW OVER COMPLETE AIRCRAFT | MATT | Phoenics | 11 | November 1, 2005 11:07 |
Ask for complete theory of T-omega formulation! | Hongtao Wang | Main CFD Forum | 0 | May 11, 2005 21:26 |
Star-HPC, Bash | Wak | Siemens | 1 | June 2, 2004 15:44 |