This file is indexed.

/usr/share/zsh/vendor-completions/roszsh is in rosbash 1.14.2-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
# roszsh - functions to support ROS users
# Useful things to know:
# 'local' variables get unset after function, all others stay forever
# 'reply' is the var used by zsh compctl builtin

function _rossed {
    if [[ `uname` == Darwin || `uname` == FreeBSD ]]; then
        sed -E "$@"
    else
        sed -r "$@"
    fi
}

function _rosfind {
    if [[ `uname` == Darwin || `uname` == FreeBSD ]]; then
        # BSD find needs -E for extended regexp
        find -E "$@"
    else
        find "$@"
    fi
}

# _ros_location_find
# based on $ROS_LOCATIONS, which the user can set to any colon
# separated of key=folder pairs also resolves keys 'log' and
# 'test_results' to ROS defaults finally resolves to package, then
# stack echoes its result
function _ros_location_find {
    local ROS_LOCATION_KEYS_ARR ROS_LOCATIONS_ARR loc
    ROS_LOCATION_KEYS_ARR=(`echo $ROS_LOCATIONS | _rossed -e 's/([^:=]*)=([^:=]*)(:*[^=])*(:|$)/\1 /g'`)
    ROS_LOCATIONS_ARR=(`echo $ROS_LOCATIONS | _rossed -e 's/([^:=]*)=([^:=]*)(:*[^=])*(:|$)/\2 /g' -e "s|~|$HOME|g"`)

    for (( i = 1 ; i <= ${#ROS_LOCATION_KEYS_ARR[@]} ; i++ )); do
        if [[ $1 == ${ROS_LOCATION_KEYS_ARR[$i]} ]]; then
            echo ${ROS_LOCATIONS_ARR[i]}
            return 0
        fi
    done

    if [[ $1 == log ]]; then
        echo `roslaunch-logs`
        return 0
    elif [[ $1 == test_results ]]; then
        echo `rosrun rosunit test_results_dir.py`
        return 0
    fi

    loc=`export ROS_CACHE_TIMEOUT=-1.0 && rospack find $1 2> /dev/null`
    if [[ $? != 0 ]]; then
        loc=`export ROS_CACHE_TIMEOUT=-1.0 && rosstack find $1 2> /dev/null`
        if [[ $? != 0 ]]; then
            return 1
        fi
        echo $loc
        return 0
    fi
    echo $loc
    return 0
}

function _ros_list_locations {
    local ROS_LOCATION_KEYS packages stacks
    ROS_LOCATION_KEYS=`echo $ROS_LOCATIONS | _rossed -e 's/([^:=]*)=([^:=]*)(:*[^=])*(:|$)/\1 /g'`
    packages=`export ROS_CACHE_TIMEOUT=-1.0 && rospack list-names`
    stacks=`export ROS_CACHE_TIMEOUT=-1.0 && rosstack list-names`
    echo $packages $stacks log test_results $ROS_LOCATION_KEYS | tr ' ' '\n'
    return 0
}

function _ros_decode_path {
    local rosname rosdir reldir last rospackdir rosstack_result rosstackdir
    rosvals=()
    if [[ -z $1 ]]; then
        return 0
    fi

    echo $1 | grep -G '.\+/.*' > /dev/null
    if [[ $? == 0 ]]; then
        rosname=${1%%/*}
        reldir=/${1#*/}
        last=${reldir##*/}
        reldir=${reldir%/*}/
    else
        rosname=$1
        if [[ -z $2 || $2 != "forceeval" ]]; then
            rosvals=(${rosname})
            return 1
        fi
    fi

    if [[ $rosname == ros ]]; then
        rosdir=`rosstack find ros`
    elif [[ $rosname == pkg ]]; then
        rosdir=${ROS_PACKAGE_PATH%%:*}
    elif [[ $rosname == log ]]; then
        rosdir=`roslaunch-logs`
    elif [[ $rosname == test_results ]]; then
        rosdir=`rosrun rosunit test_results_dir.py`
    else
        rospackdir=`export ROS_CACHE_TIMEOUT=-1.0 && rospack find $rosname 2> /dev/null`
        rospack_result=$?
        rosstackdir=`export ROS_CACHE_TIMEOUT=-1.0 && rosstack find $rosname 2> /dev/null`
        rosstack_result=$?
        if [[ $rospack_result == 0 ]]; then
            rosdir=$rospackdir
        elif [[ $rosstack_result == 0 ]]; then
            rosdir=$rosstackdir
        else
            rosvals=(${rosname})
            return 1
        fi
    fi

    rosvals=(${rosname} ${rosdir} ${reldir} ${last})
}

function rospython {
    if [[ $1 = "--help" ]]; then
        echo -e "usage: rospython [package] \n\nRun python loading package manifest first."
        return 0
    fi
    if [[ -z $1 ]]; then
        if [[ -f ./manifest.xml ]]; then
            pkgname=`basename \`pwd\``
            python -i -c "import roslib; roslib.load_manifest('$pkgname')"
        else
            python
        fi
    else
        python -i -c "import roslib; roslib.load_manifest('$1')"
    fi
}

function roscd {
    local rosvals
    if [[ $1 = "--help" ]] | [[ $# -gt 1 ]]; then
        echo -e "usage: roscd package\n\nJump to target package."
        return 0
    fi
    if [ -z $1 ]; then
        if [ ! -z $ROS_WORKSPACE ]; then
            cd ${ROS_WORKSPACE}
            return 0
        fi
        if [ ! -z $CMAKE_PREFIX_PATH ]; then
            workspaces=("${(s/:/)CMAKE_PREFIX_PATH}")
            for ws in "${workspaces[@]}"; do
                if [ -f $ws/.catkin ]; then
                    cd ${ws}
                    return 0
                fi
            done
        fi
        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."
        return 1
    fi

    _ros_decode_path $1 forceeval
    if [ $? != 0 ]; then
        echo "roscd: No such package '$1'"
        return 1
    elif [ -z ${rosvals[1]} ]; then
        if [ -z $ROS_WORKSPACE ]; then
            echo -e "No ROS_WORKSPACE set.  Please set ROS_WORKSPACE to use roscd with no arguments."
            return 1
        fi
        cd ${ROS_WORKSPACE}
        return 0
    else
        cd ${rosvals[2]}${rosvals[3]}${rosvals[4]}
        return 0
    fi
}

function _is_integer {
    [ "$1" -eq "$1" ] > /dev/null 2>&1
    return $?
}

function rosd {
    if [[ $1 = "--help" ]]; then
        echo -e "usage: rosd\n\nDisplays the list of currently remembered directories with indexes."
        return 0
    fi
    let count=0;
    for items in `dirs`;
    do
        echo $count $items;
        let count=$((count+1));
    done
}

function rospd {
    if [[ $1 = "--help" ]]; then
        echo -e "usage: rospd\n\nLike pushd, also accepts indexes from rosd."
        return 0
    fi
    if _is_integer $1; then
        pushd +$1 > /dev/null ;
    else
        local rosvals
        _ros_decode_path $1 forceeval
        pushd ${rosvals[2]}${rosvals[3]}${rosvals[4]} > /dev/null ;
    fi
    rosd
}

function rosls {
    local rosvals
    if [[ $1 = "--help" ]]; then
        echo -e "usage: rosls [package]\n\nLists contents of a package directory."
        return 0
    fi
    _ros_decode_path $1 forceeval
    ls ${rosvals[2]}${rosvals[3]}${rosvals[4]} $2
}

# sets arg as return value
function _roscmd {
    local pkgdir exepath opt
    pkgdir=`export ROS_CACHE_TIMEOUT=-1.0 && rospack find $1 2> /dev/null`
    if [[ $? != 0 ]] ; then
        echo "Couldn't find package [$1]"
        return 1
    fi
    exepath=(`find $pkgdir -name $2 -type f`)
    if [[ ${#exepath[@]} == 0 ]] ; then
        echo "That file does not exist in that package."
        return 1
    elif [[ ${#exepath[@]} -gt 1 ]] ; then
        echo "You have chosen a non-unique filename, please pick one of the following:"
        select opt in ${exepath[@]}; do
            echo $opt
            break
        done
    else
        opt=${exepath[1]}
    fi
    arg=${opt}
}

function rosed {
    local arg
    if [[ $1 = "--help" ]]; then
        echo -e "usage: rosed [package] [file]\n\nEdit a file within a package."
        return 0
    fi
    _roscmd ${1} ${2}
    if [[ -z $EDITOR ]]; then
        vim ${arg}
    else
        eval $EDITOR ${arg}
    fi
}

function roscp {
    local arg
    if [[ $1 = "--help" ]] | [[ $# -ne 3 ]]; then
        echo -e "usage: roscp package filename target\n\nCopy a file from a package to target location."
        return 0
    fi
    _roscmd ${1} ${2}
    cp ${arg} ${3}
}

function roscat {
    local arg
    if [[ $1 = "--help" ]] | [[ $# -ne 2 ]]; then
        echo -e "usage: roscat [package] [file]\n\nDisplay a file content within a package."
        [[ $1 = "--help" ]] && return 0 || return 1
    fi
    _roscmd ${1} ${2}
    [ $? -eq 1 ] && return 1
    if [[ -z $CATTER ]]; then
        cat ${arg}
    else
        $CATTER ${arg}
    fi
}

function _roscomplete {
    local arg opts stack_opts
    reply=()
    opts=`export ROS_CACHE_TIMEOUT=-1.0 && rospack list-names`
    stack_opts=`export ROS_CACHE_TIMEOUT=-1.0 && rosstack list-names`
    IFS=$'\n'
    reply=(${=opts} ${=stack_opts})
    unset IFS
}

function _roscomplete_rosmake {
    local param
    _roscomplete
    if [[ $PREFIX == "--"* ]]; then
        param="--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"
        reply=(${=reply} ${=param})
    fi
}

function _roscomplete_sub_dir {
    local arg opts rosvals sedcmd stack_opts
    reply=()
    arg="$1"
    _ros_decode_path ${arg}
    if [[ -z ${rosvals[3]} ]]; then
        opts=`export ROS_CACHE_TIMEOUT=-1.0 && rospack list-names`
        stack_opts=`export ROS_CACHE_TIMEOUT=-1.0 && rosstack list-names`
        IFS=$'\n'
        reply=(${=opts} ${=stack_opts})
        unset IFS
    else
        if [ -e ${rosvals[2]}${rosvals[3]} ]; then
            sedcmd="s:^${rosvals[2]}:${rosvals[1]}:"g
            opts=`find ${rosvals[2]}${rosvals[3]} -maxdepth 1 -mindepth 1 -type d ! -regex ".*/[.].*" -print0 | tr '\000' '\n' | sed -e "$sedcmd"`
        else
            opts=''
        fi
        IFS=$'\n'
        reply=(${=opts})
        unset IFS
    fi
}

function _roscomplete_search_dir {
    local words arg opts pkg pkgdir pkgdir_result stack_result catkin_package_libexec_dir
    reply=()
    words=(${=BUFFER})
    if [[ $BUFFER[-1] == ' ' ]]
    then
        pkg=${words[-1]}
    else
        pkg=${words[-2]}
    fi
    pkgdir=`export ROS_CACHE_TIMEOUT=-1.0 && rospack find ${pkg} 2> /dev/null`
    pkgdir_result=$?
    catkin_package_libexec_dir=`catkin_find --first-only --without-underlays --libexec ${pkg} 2> /dev/null`
    if [[ $? != 0 ]]
    then
        catkin_package_libexec_dir=""
    fi
    stackdir=`export ROS_CACHE_TIMEOUT=-1.0 && rosstack find ${pkg} 2> /dev/null`
    stack_result=$?
    if [[ $pkgdir_result == 0 ]]; then
        opts=`find $pkgdir $catkin_package_libexec_dir ${=1} -print0 | tr '\000' '\n' | sed -e "s/.*\/\(.*\)/\1/g"`
    elif [[ $stack_result == 0 ]] ; then
        opts=`find $stackdir ${=1} -print0 | tr '\000' '\n' | sed -e "s/.*\/\(.*\)/\1/g"`
    else
        opts=""
    fi
    IFS=$'\n'
    reply=(${=opts})
    unset IFS
}

function _roscomplete_exe {
    local perm
    if [[ `uname` == Darwin ]]; then
        perm="+111"
    else
        perm="/111"
    fi
    _roscomplete_search_dir "-type f -perm $perm -regex .*/.*$ ! -path */\.*"
}

function _roscomplete_file {
    _roscomplete_search_dir "-type f ! -regex .*/[.].* ! -regex .*[.][oa]$"
}

function _roscomplete_launchfile {
    _roscomplete_search_dir "( -type f -regex .*\.launch$ -o -type f -regex .*\.test$ )"
}

function _roscomplete_rosbag {
    local opts
    reply=()

    if [[ ${CURRENT} == 2 ]]; then
        opts="check compress decompress filter fix help info play record reindex"
        reply=(${=opts})
    else
        if [[ ${=${(s: :)words}[$(( ${CURRENT} ))]} =~ \-\- ]]; then
            opts="--all --help"
            case ${=${(s: :)words}[2]} in
                check)
                    opts="--genrules --append --noplugins --help"
                    ;;
                compress|decompress)
                    opts="--output-dir --force --quiet --help"
                    ;;
                filter)
                    opts="--print --help"
                    ;;
                fix)
                    opts="--force --noplugins --help"
                    ;;
                info)
                    opts="--yaml --key --freq --help"
                    ;;
                play)
                    opts="--help --quiet --immediate --pause --queue --clock --hz --delay --rate --start --skip-empty --loop --keep-alive --try-future-version --topics --bags"
                    ;;
                record)
                    opts="--help --all --regex --exclude --quiet --output-prefix --output-name --split --size --duration --buffsize --limit --node --bz2"
                    ;;
                reindex)
                    opts="--help --force --quiet --output-dir"
                    ;;
            esac
            reply=(${=opts})
        else
            case ${=${(s: :)words}[2]} in
                record)
                    opts=$(rostopic list 2>/dev/null)
                    if [ -z "$opts" ]; then
                        reply="" #Prevent execution of next rule
                        return
                    fi
                    reply=(${=opts})
                    ;;
            esac
        fi
    fi

}

function _roscomplete_rospack {
    local opts
    reply=()
    if [[ ${CURRENT} == 2 ]]; then
        opts="help find list list-names list-duplicates langs depends depends-manifests depends1 depends-indent depends-msgsrv depends-why rosdep rosdep0 vcs vcs0 depends-on depends-on1 export plugins cflags-only-I cflags-only-other libs-only-L libs-only-l libs-only-other profile"
        reply=(${=opts})
    else
        opts=`rospack list-names`
        reply=(${=opts})
    fi
}

function _roscomplete_rosnode {
    local opts
    reply=()

    if [[ ${CURRENT} == 2 ]]; then
        opts="ping list info machine kill cleanup"
        reply=(${=opts})
    elif [[ ${CURRENT} == 3 ]]; then
        case ${=${(s: :)words}[2]} in
            info)
                opts=`rosnode list 2> /dev/null`
                reply=(${=opts})
                ;;
            ping|list|kill)
                if [[ ${=${(s: :)words}[$(( ${CURRENT} ))]} =~ \-\- ]]; then
                    opts="--all --help"
                else
                    opts=`rosnode list 2> /dev/null`
                fi
                reply=(${=opts})
                ;;
            machine)
                # This takes more logic to determine which machines are present.
                ;;
        esac
    else
        case ${=${(s: :)words}[2]} in
            kill)
                # complete on node name
                opts=`rosnode list 2> /dev/null`
                reply=(${=opts})
                ;;
        esac
    fi
}

function _roscomplete_rosparam {
    local opts
    reply=()

    if [[ ${CURRENT} == 2 ]]; then
        opts="set get load dump delete list"
        reply=(${=opts})
    elif [[ ${CURRENT} == 3 ]]; then
        case ${=${(s: :)words}[2]} in
            set|get|delete|list)
                opts=`rosparam list 2> /dev/null`
                reply=(${=opts})
                ;;
            load|dump)
                # complete on files
                reply=(${=opts})
                ;;
        esac
    elif [[ ${CURRENT} == 4 ]]; then
        case ${=${(s: :)words}[2]} in
            load|dump)
                # complete on namespace
                opts=`rosparam list 2> /dev/null`
                reply=(${=opts})
                ;;
        esac
    fi

}
function _roscomplete_rostopic {
    local opts word
    reply=()

    if [[ ${CURRENT} == 2 ]]; then
        opts="bw echo hz list pub type find info"
        reply=(${=opts})
    elif [[ ${CURRENT} > 2 ]]; then
        if [[ ${=${(s: :)words}[$(( ${CURRENT} ))]} =~ \-\- ]]; then
            case ${=${(s: :)words}[2]} in
                pub)
                    opts="--help --rate --once --file --latch"
                    ;;
                bw)
                    opts="--help --window"
                    ;;
                echo)
                    opts="--help --bag --filter --nostr --noarr --clear --all --offset"
                    ;;
                hz)
                    opts="--help --window --filter"
                    ;;
                list)
                    opts="--help --bag --verbose --host"
                    ;;
                type|info)
                    opts="--help"
                    ;;
            esac
            reply=(${=opts})
        else
            case ${=${(s: :)words}[2]} in
                bw|echo|hz|list|type|info)
                    if [[ ${=${(s: :)words}[$(( ${CURRENT} -1 ))]} == "-b" ]]; then
                        opts=`find . -maxdepth 1 -type f -not -name ".*" -not -name "*[~#]" | sed 's!.*/!!'`
                        reply=(${=opts})
                    else
                        opts=`rostopic list 2> /dev/null`
                        reply=(${=opts})
                    fi
                    ;;
                find)
                    opts=`_msg_opts ${=${(s: :)words[-1]}}`
                    reply=(${=opts})
                    ;;
                pub)
                    if [[ ${CURRENT} == 3 ]]; then
                        opts=`rostopic list 2> /dev/null`
                        reply=(${=opts})
                    elif [[ ${CURRENT} == 4 ]]; then
                        if [[ ${=${(s: :)words}[$(( ${CURRENT} ))]} =~ / ]]; then
                            word=(${=words})
                            type=`rostopic info ${word[3]} 2> /dev/null`
                            opts=${=${type[(w)2]}}
                        else
                            word=(${=words})
                            type=`rostopic info ${word[3]} 2> /dev/null`
                            opts=${=${type[(w)2]}}
                        fi
                        reply=(${=opts})
                    elif [[ ${CURRENT} == 5 ]]; then
                        w=(${=words})
                        opts=`rosmsg-proto msg 2> /dev/null -s ${=${w[-1]}}`
                        reply=(${opts})
                    fi
                    ;;
            esac
        fi
    fi
}

function _roscomplete_rosservice {
    local opts
    reply=()


    if [[ ${CURRENT} == 2 ]]; then
        opts="args call find info list type uri"
        reply=(${=opts})
    elif [[ ${CURRENT} == 3 ]]; then
        case ${words[2]} in
            args|call|info|list|type|uri)
                opts=`rosservice list 2> /dev/null`
                IFS=$'\n'
                reply=(${=opts})
                unset IFS
                ;;
            find)
                opts=`_srv_opts ${words[3]}`
                reply=(${=opts})
                ;;
        esac
    elif [[ ${CURRENT} == 4 ]]; then
        case ${words[2]} in
            call)
                type="$(rosservice type ${words[3]} 2>/dev/null)"
                reply=("$(rosmsg-proto srv -s ${type} 2> /dev/null)")
                ;;
        esac
    fi

}

function _msg_opts {
    local pkgname msgname searchmsg pkgs count pkgname2 opts result
    unset searchmsg

    if [[ $1 =~ .+/.* ]]; then
        pkgname=${1%%/*}
        msgname=${1#*/}
        searchmsg=1
    else
        pkgname=${1}
    fi

    if [[ -z ${searchmsg} ]]; then
        pkgs=`command rospack list | grep "^${pkgname}"`
        count=0

        opts=""

        for pkg in ${(f)pkgs}; do
            pkgdir=${=${(s: :)pkg}[2]}
            if [[ -d $pkgdir/msg ]]; then
                pkgname2=${=${(s: :)pkg}[1]}
                opts="$opts $pkgname2/"
                count=$((count+1))
            fi
        done

        if [[ $count > 0 ]]; then
            echo $opts
            return 0
        fi
    fi

    pkgpath=`rospack find ${pkgname} 2> /dev/null`
    if [[ $?  == 0 ]] && [[ -d ${pkgpath}/msg ]]; then
        result=`find -L ${pkgpath}/msg -maxdepth 1 -mindepth 1 -name \*.msg ! -regex ".\*/[.].\*" -print0 | tr '\000' '\n' | sed -e "s/.*\/\(.*\)\.msg/${pkgname}\/\1/g"`
        echo $result
    fi
}

function _roscomplete_rosmsg {
    local opts
    reply=()

    if [[ ${CURRENT} == 2 ]]; then
        opts="show list md5 package packages"
        reply=(${=opts})
    elif [[ ${CURRENT} == 3 ]]; then
        case ${=${(s: :)words}[2]} in
            show|users|md5)
                opts=`_msg_opts ${=${(s: :)words[-1]}}`
                reply=(${=opts})
                ;;
            package)
                opts=`rospack list-names`
                reply=(${=opts})
                ;;
            packages|list)
                # This shouldn't really have a completion rule
                ;;
        esac
    fi
}

function _srv_opts {
    local pkgname srvname searchsrv pkgs count opts pkgpath result
    unset searchsrv

    if [[ $1 =~ .+/.* ]]; then
        pkgname=${1%%/*}
        srvname=${1#*/}
        searchsrv=1
    else
        pkgname=${1}
    fi

    if [[ -z ${searchsrv} ]]; then
        pkgs=`command rospack list | grep "^${pkgname}"`
        count=0

        opts=""

        for pkg in ${(f)pkgs}; do
            pkgdir=${=${(s: :)pkg}[2]}
            if [[ -d $pkgdir/srv ]]; then
                pkgname2=${=${(s: :)pkg}[1]}
                opts="$opts $pkgname2/"
                count=$((count+1))
            fi
        done

        if [[ $count > 0 ]]; then
            echo $opts
            return 0
        fi
    fi

    pkgpath=`rospack find ${pkgname} 2> /dev/null`
    if [[ $?  == 0 ]] && [[ -d ${pkgpath}/srv ]]; then
        result=`find -L ${pkgpath}/srv -maxdepth 1 -mindepth 1 -name \*.srv ! -regex ".\*/[.].\*" -print0 | tr '\000' '\n' | sed -e "s/.*\/\(.*\)\.srv/${pkgname}\/\1/g"`
        echo $result
    fi
}

function _roscomplete_rossrv {
    local opts
    reply=()

    if [[ ${CURRENT} == 2 ]]; then
        opts="show list md5 package packages"
        reply=(${=opts})
    elif [[ ${CURRENT} == 3 ]]; then
        case ${=${(s: :)words}[2]} in
            show|users|md5)
                opts=`_srv_opts ${=${(s: :)words[-1]}}`
                reply=(${=opts})
                ;;
            package)
                opts=`rospack list-names`
                reply=(${=opts})
                ;;
            packages|list)
                # This shouldn't really have a completion rule
                ;;
        esac
    fi
}

function _roscomplete_roscreate_pkg {
    local opts
    reply=()

    if [[ ${CURRENT} > 2 ]]; then
        opts=`rospack list-names`
        reply=(${=opts})
    fi
}

compctl -K "_roscomplete_sub_dir" -S / "roscd" "rospd" "rosls"
compctl -K "_roscomplete_rosmake" "rosmake"

compctl -x 'p[1]' -k "(check purge)" -- "rosclean"
compctl -f -x 'p[1]' -K "_roscomplete" - 'p[2]' -K _roscomplete_file -- "rosed" "roscp" "roscat"
compctl -f -x 'S[-]' -k '(--debug --prefix)' - 'c[-1,--prefix][-1,-p]' -h '' - 'p[1],c[-1,-d],c[-1,--debug],c[-2,-p],c[-2,--prefix]' -K "_roscomplete" - 'p[2],c[-2,-d],c[-2,--debug],c[-3,-p],c[-3,--prefix]' -K _roscomplete_exe -- "rosrun"
compctl -/g '*.(launch|test)' -x 'p[1]' -K "_roscomplete" -tx - 'p[2]' -K _roscomplete_launchfile -- + -x 'S[--]' -k "(--files --args --nodes --find-node --child --local --screen --server_uri --run_id --wait --port --core --pid --dump-params --disable-title --help --numworkers --ros-args --skip-log-check --timeout)" -- "roslaunch"
compctl -/g '*.(launch|test)' -x 'p[1]' -K "_roscomplete" -tx - 'p[2]' -K _roscomplete_launchfile -- + -x 'S[--]' -k "(--bare --bare-limit --bare-name --pkgdir --package)" -- "rostest"
compctl -K "_roscomplete_rospack" "rospack"
compctl -K "_roscomplete_rosbag" + -g "*.bag *(/)" "rosbag"
compctl -K "_roscomplete_rosnode" "rosnode"
compctl -K "_roscomplete_rosparam" "rosparam"
compctl -x 'p[0,2]' -K "_roscomplete_rostopic" - 'n[1,/] p[3]' -K "_roscomplete_rostopic" - 'p[3]' -S ' ' -K "_roscomplete_rostopic" - 'p[4]' -Q -K "_roscomplete_rostopic" -- "rostopic"
compctl -Q -K "_roscomplete_rosservice" "rosservice"
compctl -x 'p[1]' -k "(md5 package packages show users)" - 'p[2]' -S '' -K "_roscomplete_rosmsg" -- "rosmsg"
compctl -x 'p[1]' -k "(md5 package packages show users)" - 'p[2]' -S '' -K "_roscomplete_rossrv" -- "rossrv"
compctl -K "_roscomplete_roscreate_pkg" "roscreate-pkg"
compctl -/g '*.(launch|test)' -x 'S[--]' -k "(--all --no-plugins --offline)" -- "roswtf"