|
0 |
|
|
1 |
function _rossed
|
|
2 |
if test (uname) = "Darwin" -o (uname) = "FreeBSD"
|
|
3 |
sed -E $argv
|
|
4 |
else
|
|
5 |
sed -r $argv
|
|
6 |
end
|
|
7 |
end
|
|
8 |
|
|
9 |
function _rosfind
|
|
10 |
if test (uname) = "Darwin" -o (uanme) = "FreeBSD"
|
|
11 |
# BSD find needs -E for extended regexp
|
|
12 |
find -E $argv
|
|
13 |
else
|
|
14 |
find $argv
|
|
15 |
end
|
|
16 |
end
|
|
17 |
|
|
18 |
# _ros_location_find
|
|
19 |
# Takes a name of a ros location and returns it's path
|
|
20 |
function _ros_location_find
|
|
21 |
set -l homedir (echo $HOME | sed -e "s/\//\t\//g" -e "s/\t/\\\/g")
|
|
22 |
set -l ROS_LOCATION_KEYS_ARR (echo $ROS_LOCATIONS | _rossed -e 's/([^:=]*)=([^:=]*)(:*[^=])*(:|$)/\1 /g')
|
|
23 |
set -l ROS_LOCATIONS_ARR (echo $ROS_LOCATIONS | _rossed -e 's/([^:=]*)=([^:=]*)(:*[^=])*(:|$)/\2 /g' -e "s/~/{$homedir}/g")
|
|
24 |
for key in $ROS_LOCATION_KEYS_ARR
|
|
25 |
if test $argv[1] = $key
|
|
26 |
echo $key
|
|
27 |
return 0
|
|
28 |
end
|
|
29 |
end
|
|
30 |
|
|
31 |
if test $argv[1] = log
|
|
32 |
echo (roslaunch-logs)
|
|
33 |
return 0
|
|
34 |
else if test $argv[1] = test_results
|
|
35 |
echo (rosrun rosunit test_results_dir.py)
|
|
36 |
return 0
|
|
37 |
end
|
|
38 |
|
|
39 |
set -l loc (set -x ROS_CACHE_TIMEOUT -1.0; rospack find $argv[1] 2> /dev/null)
|
|
40 |
if test $status != 0
|
|
41 |
set loc (set -x ROS_CACHE_TIMEOUT -1.0; rosstack find $argv[1] 2> /dev/null)
|
|
42 |
if test $status != 0
|
|
43 |
return 1
|
|
44 |
end
|
|
45 |
echo $loc
|
|
46 |
return 0
|
|
47 |
end
|
|
48 |
echo $loc
|
|
49 |
return 0
|
|
50 |
end
|
|
51 |
|
|
52 |
function _ros_list_locations
|
|
53 |
set -l ROS_LOCATION_KEYS (echo $ROS_LOCATIONS | _rossed -e 's/([^:=]*)=([^:=]*)(:*[^=])*(:|$)/\1 /g')
|
|
54 |
set -l packages (set -x ROS_CACHE_TIMEOUT -1.0; rospack list-names)
|
|
55 |
set -l stacks (set -x ROS_CACHE_TIMEOUT -1.0; rosstack list-names)
|
|
56 |
echo $packages $stacks log test_results $ROS_LOCATION_KEYS | tr ' ' '\n'
|
|
57 |
return 0
|
|
58 |
end
|
|
59 |
|
|
60 |
function _ros_package_find
|
|
61 |
set -l loc (set -x ROS_CACHE_TIMEOUT -1.0; rospack find $1 2> /dev/null)
|
|
62 |
if test $status != 0
|
|
63 |
return 1
|
|
64 |
end
|
|
65 |
echo $loc
|
|
66 |
return 0
|
|
67 |
end
|
|
68 |
|
|
69 |
function _ros_list_packages
|
|
70 |
set -l packages (set -x ROS_CACHE_TIMEOUT -1.0; rospack list-names)
|
|
71 |
echo $packages | tr ' ' '\n'
|
|
72 |
return 0
|
|
73 |
end
|
|
74 |
|
|
75 |
function _ros_list_stacks
|
|
76 |
set -l stacks (set -x ROS_CACHE_TIMEOUT -1.0; rosstack list-names)
|
|
77 |
echo $stacks | tr ' ' '\n'
|
|
78 |
return 0
|
|
79 |
end
|
|
80 |
|
|
81 |
# takes as argument either just a package-path or just a pkgname
|
|
82 |
# returns 0 for no argument or if package (+ path) exist, 1 else
|
|
83 |
# on success with arguments returns [name, abspath, basepath, remainder]
|
|
84 |
function _ros_decode_path
|
|
85 |
if test -z $argv[1]
|
|
86 |
return 0
|
|
87 |
end
|
|
88 |
|
|
89 |
set -l rosname (echo $argv[1] | sed -n 's/\([^/]\+\).*/\1/p')
|
|
90 |
|
|
91 |
if not test -z $rosname
|
|
92 |
set remainder (echo $argv[1] | sed -n "s/$rosname"'\(.*\)/\1/p')
|
|
93 |
else
|
|
94 |
set rosname $argv[1]
|
|
95 |
if test (count $argv) != "2" -o $argv[2] != "forceeval"
|
|
96 |
echo $rosname
|
|
97 |
return 1
|
|
98 |
end
|
|
99 |
end
|
|
100 |
|
|
101 |
set -l rosdir (_ros_location_find $rosname)
|
|
102 |
if test $status != "0"
|
|
103 |
echo $rosname
|
|
104 |
return 1
|
|
105 |
end
|
|
106 |
set -l reldir (echo $remainder | sed -n 's/\(.*\/\)[^/]*/\1/p')
|
|
107 |
set -l last (echo $remainder | sed -n 's/.*\/\([^/]*\)/\1/p')
|
|
108 |
|
|
109 |
if test -z $reldir
|
|
110 |
set reldir /
|
|
111 |
end
|
|
112 |
|
|
113 |
set rosvals {$rosname} {$rosdir} {$reldir} {$last}
|
|
114 |
echo {$rosdir}{$remainder}
|
|
115 |
return 0
|
|
116 |
end
|
|
117 |
|
|
118 |
function rospython
|
|
119 |
if test -z $argv
|
|
120 |
python -i -c "import roslib; roslib.load_manifest('$1')"
|
|
121 |
return 0
|
|
122 |
end
|
|
123 |
if test (count $argv) = 1
|
|
124 |
if test $argv[1] = "--help"
|
|
125 |
echo -e "usage: rospython [package] \n\nRun python loading package manifest first."
|
|
126 |
return 0
|
|
127 |
end
|
|
128 |
end
|
|
129 |
if test -f ./manifest.xml
|
|
130 |
set pkgname (basename (pwd))
|
|
131 |
python -i -c "import roslib; roslib.load_manifest($pkgname)"
|
|
132 |
else
|
|
133 |
python
|
|
134 |
end
|
|
135 |
end
|
|
136 |
|
|
137 |
function roscd
|
|
138 |
if test -z $argv[1]
|
|
139 |
if test -n $ROS_WORKSPACE
|
|
140 |
cd $ROS_WORKSPACE
|
|
141 |
return 0
|
|
142 |
end
|
|
143 |
if test -n $CMAKE_PREFIX_PATH[1]
|
|
144 |
for ws in $CMAKE_PREFIX_PATH
|
|
145 |
ls $ws/.catkin
|
|
146 |
if test -f $ws/.catkin
|
|
147 |
cd $ws
|
|
148 |
return 0
|
|
149 |
end
|
|
150 |
end
|
|
151 |
end
|
|
152 |
echo -e "Neither ROS_WORKSPACE is set nor a catkin workspace is listed in CMAKE_PREFIX_PATH. Please set ROS_WORKSPACE or source a catkin workspace to use roscd with no arguments."
|
|
153 |
return 1
|
|
154 |
end
|
|
155 |
|
|
156 |
if test $argv[1] = "--help"
|
|
157 |
echo -e "usage: roscd package\n\nJump to target package."
|
|
158 |
return 0
|
|
159 |
end
|
|
160 |
|
|
161 |
set -l rospath (_ros_decode_path $argv[1] forceeval)
|
|
162 |
if test -z $rospath
|
|
163 |
if test -z $ROS_WORKSPACE
|
|
164 |
echo -e "No ROS_WORKSPACE set. Please set ROS_WORKSPACE to use roscd with no arguments."
|
|
165 |
return 1
|
|
166 |
end
|
|
167 |
cd $ROS_WORKSPACE
|
|
168 |
return 0
|
|
169 |
else
|
|
170 |
cd $rospath
|
|
171 |
return 0
|
|
172 |
end
|
|
173 |
end
|
|
174 |
|
|
175 |
function _is_integer
|
|
176 |
not test -z (expr $argv[1] - $argv[1] 2>/dev/null)
|
|
177 |
return $status
|
|
178 |
end
|
|
179 |
|
|
180 |
function rosd
|
|
181 |
if test (count $argv) != 0
|
|
182 |
if test $argv[1] = "--help"
|
|
183 |
echo -e "usage: rosd\n\nDisplays the list of currently remembered directories with indexes."
|
|
184 |
return 0
|
|
185 |
end
|
|
186 |
end
|
|
187 |
set count 0
|
|
188 |
for items in (dirs | sed -e 's/ /\n/g')
|
|
189 |
echo $count $items;
|
|
190 |
set count (expr $count + 1)
|
|
191 |
end
|
|
192 |
end
|
|
193 |
|
|
194 |
function rospd
|
|
195 |
if test (count $argv) != 0
|
|
196 |
if test $argv[1] = "--help"
|
|
197 |
echo -e "usage: rospd\n\nLike pushd, also accepts indexes from rosd."
|
|
198 |
return 0
|
|
199 |
end
|
|
200 |
else
|
|
201 |
echo -e "usage: rospd\n\nLike pushd, also accepts indexes from rosd."
|
|
202 |
return 0
|
|
203 |
end
|
|
204 |
set -l rospath (_ros_decode_path $argv[1] forceeval)
|
|
205 |
pushd $rospath > /dev/null
|
|
206 |
rosd
|
|
207 |
end
|
|
208 |
|
|
209 |
function rosls
|
|
210 |
if test (count $argv) != 0
|
|
211 |
if test $argv[1] = "--help"
|
|
212 |
echo -e "usage: rosls [package]\n\nLists contents of a package directory."
|
|
213 |
return 0
|
|
214 |
end
|
|
215 |
else
|
|
216 |
echo -e "usage: rosls [package]\n\nLists contents of a package directory."
|
|
217 |
return 0
|
|
218 |
end
|
|
219 |
set -l rospath (_ros_decode_path $argv[1] forceeval)
|
|
220 |
ls $rospath
|
|
221 |
end
|
|
222 |
|
|
223 |
# sets arg as return value
|
|
224 |
function _roscmd
|
|
225 |
set -l opt
|
|
226 |
if test -n $CMAKE_PREFIX_PATH
|
|
227 |
set -l catkin_package_libexec_dir (catkin_find --without-underlays --libexec $argv[1] 2> /dev/null)
|
|
228 |
end
|
|
229 |
set -l pkgdir (_ros_package_find $argv[1])
|
|
230 |
if test -z $catkin_package_libexec_dir -a -z $pkgdir
|
|
231 |
echo "Couldn't find package $argv[1]"
|
|
232 |
return 1
|
|
233 |
end
|
|
234 |
set -l exepath (find -L $catkin_package_libexec_dir $pkgdir -name $2 -type f ! -regex .*/[.].* ! -regex .*$pkgdir\/build\/.* | uniq)
|
|
235 |
if test (count $execpath) = "0"
|
|
236 |
echo "That file does not exist in that package."
|
|
237 |
return 1
|
|
238 |
else if test (expr (count $exepath) '>' 1) = "1"
|
|
239 |
echo "You have chosen a non-unique filename, please pick one of the following:"
|
|
240 |
for i in (seq (count $execpath))
|
|
241 |
echo $i") " $execpath[i]
|
|
242 |
end
|
|
243 |
read choice
|
|
244 |
set -l opt $execpath[$choice]
|
|
245 |
else
|
|
246 |
set -l opt $exepath[1]
|
|
247 |
end
|
|
248 |
arg=$opt
|
|
249 |
end
|
|
250 |
|
|
251 |
function rosed
|
|
252 |
set -l arg
|
|
253 |
if test (count $argv) = 0
|
|
254 |
echo -e "usage: rossed [package] [file]\n\nEdit a file within a package."
|
|
255 |
return 0
|
|
256 |
end
|
|
257 |
if test $argv[1] = "--help"
|
|
258 |
echo -e "usage: rossed [package] [file]\n\nEdit a file within a package."
|
|
259 |
return 0
|
|
260 |
end
|
|
261 |
_roscmd $argv[1]
|
|
262 |
if test -n $arg
|
|
263 |
if test -z $EDITOR
|
|
264 |
vi $arg
|
|
265 |
else
|
|
266 |
$EDITOR $arg
|
|
267 |
end
|
|
268 |
end
|
|
269 |
end
|
|
270 |
|
|
271 |
function roscp
|
|
272 |
set -l arg
|
|
273 |
if test (count $argv) != "3"
|
|
274 |
echo -e "usage: roscp package filename target\n\nCopy a file from a package to target location."
|
|
275 |
return 0
|
|
276 |
end
|
|
277 |
_roscmd $argv[1] $argv[2]
|
|
278 |
cp $arg $argv[3]
|
|
279 |
end
|
|
280 |
|
|
281 |
function _roscomplete
|
|
282 |
_ros_list_locations
|
|
283 |
_ros_list_stacks
|
|
284 |
end
|
|
285 |
|
|
286 |
function _roscomplete_sub_dir
|
|
287 |
set -l wd $PWD
|
|
288 |
set -l roslocs (_ros_list_locations)
|
|
289 |
set -l arg (commandline -ct)
|
|
290 |
set -g rosvals
|
|
291 |
set -l path (_ros_decode_path $arg)
|
|
292 |
if test -z $rosvals[1]
|
|
293 |
# Not a full ROS location
|
|
294 |
_ros_list_locations
|
|
295 |
else
|
|
296 |
# The first section is a full ROS location, so we complete from it's subdirs
|
|
297 |
find -L $rosvals[2]$rosvals[3] -maxdepth 1 -mindepth 1 -type d ! -regex ".*/[.].*" -print0 | tr '\000' '\n' | sed -e "s/.*\/\(.*\)/$rosvals[1]\/\1/g"
|
|
298 |
end
|
|
299 |
end
|
|
300 |
|
|
301 |
function _roscomplete_rosmake
|
|
302 |
_roscomplete
|
|
303 |
set options --test-only --all --mark-installed --unmark-installed --robust --build-everything --specified-only --buildtest --buildtest1 --output --pre-clean --bootstrap --disable-logging --target --pjobs= --threads --profile --skip-blacklist --status-rate
|
|
304 |
for i in $options
|
|
305 |
echo $i
|
|
306 |
end
|
|
307 |
end
|
|
308 |
|
|
309 |
function _roscomplete_search_dir
|
|
310 |
set -l command (commandline -o)
|
|
311 |
if test (count $command) = 1
|
|
312 |
echo "1" >> ~/output.txt
|
|
313 |
_ros_list_packages
|
|
314 |
end
|
|
315 |
if test (count $command) = 2
|
|
316 |
echo "2" >> ~/output.txt
|
|
317 |
_ros_list_packages
|
|
318 |
end
|
|
319 |
if test (count $command) = 3
|
|
320 |
echo "3" >> ~/output.txt
|
|
321 |
find (_ros_location_find $command[1]) $arg -printf "%f\n"
|
|
322 |
end
|
|
323 |
end
|
|
324 |
|
|
325 |
function _roscomplete_rosrun
|
|
326 |
_roscomplete_search_dir '-type f -perm +111'
|
|
327 |
end
|
|
328 |
|
|
329 |
function _roscomplete_file
|
|
330 |
_roscomplete_search_dir '-type f ! -regex .*[.][oa]$'
|
|
331 |
end
|
|
332 |
|
|
333 |
function _roscomplete_launch
|
|
334 |
if test -z (commandline -ct | grep i-)
|
|
335 |
set options --files --args --nodes --find-node --child --local --screen --server_uri --run_id --wait --port --core --pid --dump-params
|
|
336 |
for i in $options
|
|
337 |
echo $i
|
|
338 |
end
|
|
339 |
else
|
|
340 |
_roscomplete_search_dir '-type f -regex \'.*\.launch$\' -o -type f -regex \'.*\.test$\''
|
|
341 |
end
|
|
342 |
end
|
|
343 |
|
|
344 |
complete -x -c roscd -a '(_roscomplete_sub_dir)'
|
|
345 |
complete -c roscd -l help --description "prints command info"
|
|
346 |
complete -c rospd -a '(_roscomplete_sub_dir)'
|
|
347 |
complete -c rosls -a '(_roscomplete_sub_dir)'
|
|
348 |
complete -c rosls -l help --description "prints command info"
|
|
349 |
complete -x -c rosmake -a '(_roscomplete_rosmake)'
|
|
350 |
complete -x -c rosclean -a 'check purge'
|
|
351 |
complete -x -c rosrun -a '(_roscomplete_rosrun)'
|
|
352 |
complete -x -c roslaunch -a '(_roscomplete_launch)'
|
|
353 |
complete -x -c rosed -a '(_roscomplete_file)'
|
|
354 |
complete -c rosed -l help --description "prints command info"
|
|
355 |
complete -x -c roscp -a '(_roscomplete_file)'et -x TEST works
|
|
356 |
complete -c roscp -l help --description "prints command info"
|