aerospace-toolbox

aerospace-toolbox Git Source Tree

Root/helper.sh

1#!/bin/bash
2
3projectName=aerospace_toolbox
4
5function usage {
6cat << EOF
7Options:
8p
9set project path as pwd
10c
11create a new class
12s
13create a new scilab .sce file
14f
15format source code
16r
17refactor
18t
19generate tags for stl, project libraries, and local code
20u
21display usage
22Examples:
23Format all of the source code:
24$0 -f
25EOF
26}
27
28function setProjectPath
29{
30if [ ! -e $projectPath ]
31then
32echo please run
33echo . $0 -s
34echo to set the project path to the pwd
35exit 0
36fi
37}
38
39if [ $# == 0 ]
40then
41usage
42fi
43
44while getopts "ps:c:difrtun:p:vx" opt; do
45case ${opt} in
46p) echo setting project path to $(pwd)
47export projectPath=$(pwd)
48;;
49s) file=${OPTARG}
50setProjectPath
51echo helper: creating scilab script ${file}
52echo first name:; read firstName
53echo last name:; read lastName
54echo email:; read email
55year=$(date +%G)
56cp ${projectPath}/templates/template.sce ${file}.sce
57sed -i "
58s/@FILE@/${file}/g ;
59s/@FIRSTNAME@/${firstName}/g ;
60s/@LASTNAME@/${lastName}/g ;
61s/@EMAIL@/${email}/g ;
62s/@YEAR@/${year}/g ;" \
63${file}.sce
64;;
65c) class=${OPTARG}
66setProjectPath
67echo helper: creating class ${class}
68echo first name:; read firstName
69echo last name:; read lastName
70echo email:; read email
71echo namespace:; read namespace
72year=$(date +%G)
73cp ${projectPath}/templates/template.cpp ${class}.cpp
74cp ${projectPath}/templates/template.hpp ${class}.hpp
75find . -regex ".*${class}.\(cpp\|hpp\)" \
76-exec sed -i "
77s/@CLASS@/${class}/g;
78s/@FIRSTNAME@/${firstName}/g;
79s/@LASTNAME@/${lastName}/g;
80s/@EMAIL@/${email}/g;
81s/@YEAR@/${year}/g;
82s/@NAMESPACE@/${namespace}/g;" {} \;
83;;
84f) echo helper: formatting source code
85astyle --style=ansi $(find . -regex '.*\.\(cpp\|c\|cc\|h\|hpp\)')
86rm -f $(find . -regex '.*\.orig')
87;;
88r) echo helper: refactoring
89echo -n "original name: "; read orig
90echo -n "new name: "; read new
91find . -regex '.*\.\(cpp\|c\|cc\|h\|hpp\|.am\)' \
92-exec sed -i "s|$orig|$new|g" {} \;
93;;
94t) echo autogen: generating tags
95vimrc=~/.vimrc
96tagFile="~/.vim/tags/${projectName}Tags"
97
98# Create the directory
99if [ -f ~/.vim/tags ]
100then
101rm ~/.vim/tags
102fi
103mkdir -p ~/.vim/tags
104
105# Generate the tags
106ctags -RV --language-force=C++ --c++-kinds=+p --fields=+iaS \
107--extra=+q -f ~/.vim/tags/${projectName}Tags \
108/usr/include/pango* \
109/usr/include/gtk* \
110/usr/include/cairo* \
111/usr/include/boost/numeric \
112/usr/include/boost/asio \
113/usr/include/osg* \
114/usr/include/Serial*
115
116# Add tags to .vimrc
117if grep -q "set tags+=$tagFile" $vimrc; then
118echo "Tags found in .vimrc"
119else
120echo "set tags+=$tagFile" >> $vimrc
121echo "I added them to .vimrc"
122fi
123;;
124u) usage
125;;
126?) usage
127;;
128esac
129done
130
131# vim:ts=4:sw=4

Archive Download this file

Branches