Thursday, November 08, 2007

vim + Qt

A handy script that open your projects files in vim tabs.


#!/bin/sh
# $Id: work.sh 168 2007-10-31 00:11:24Z bsergean $
# Author: bsergean@gmail.com
#
# Open your favorite editor (vi) using relevant information from the current folder Qt project file
# - Passing the list of source and header files, plus the .pro project file as args
# - Listing the includes list and setting vim path to find those include file using vim 'gf'
#
# The magic number 21 and 26 might depends on your qmake version (works fine with QMake version 2.01a (4.3.0))
#
# TODO: Maybe extract the sources dir from SOURCES (and HEADERS) and run ctags on it
# Open the resource file ?
#
# If you have shell variables evaluated within qmake variables,
# it won't work.
# Replace
# SOURCES = $HOME/foo.c
# with:
# HOME=$$system(echo $HOME)
# SOURCES = $${HOME}/foo.c
#

tmp=/tmp/work.$$
qmake -d -d -d > $tmp 2>&1

# DEBUG 1: SOURCES ===
getVar()
{
egrep 'DEBUG 1: SOURCES' $tmp | cut -c 21- | tr -d ':'
egrep 'DEBUG 1: HEADERS' $tmp | cut -c 21- | tr -d ':'

# Project file
echo `basename $PWD`.pro
}

getInc()
{
egrep 'DEBUG 1: INCLUDEPATH' $tmp | cut -c 26- | tr -d ':'
}
files=`getVar`
incs=`getInc | sed 's/ /,/g'`

rm -f $tmp

## Uncomment this to update tags at each startup
# find src include | ctags -L - --c++-kinds=+p --fields=+iaS --extra=+q
gvim -p --cmd "set path=$incs" --cmd "set tags=$HOME/path/to/my/tags,/another/one/tags" $files

0 Comments:

Post a Comment

<< Home