PageRenderTime 16ms CodeModel.GetById 13ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/bash_completion.d/gdb

http://github.com/brinkman83/bashrc
#! | 43 lines | 39 code | 4 blank | 0 comment | 0 complexity | 91128343cf12f39cbc4cc2b00c9d14da MD5 | raw file
 1# bash completion for gdb
 2
 3have gdb &&
 4_gdb()
 5{
 6    local cur prev
 7
 8    COMPREPLY=()
 9    cur=`_get_cword`
10    prev=${COMP_WORDS[COMP_CWORD-1]}
11
12    if [ $COMP_CWORD -eq 1 ]; then
13        local IFS
14        if [[ "$cur" == */* ]]; then
15            # compgen -c works as expected if $cur contains any slashes.
16            IFS=$'\n'
17            COMPREPLY=( $( PATH="$PATH:." compgen -d -c -- "$cur" ) )
18        else
19            # otherwise compgen -c contains Bash's built-in commands,
20            # functions and aliases. Thus we need to retrieve the program
21            # names manually.
22            IFS=":"
23            local path_array=( $(echo "$PATH" | sed 's/::\+/:/g;s/^:\|:$//g') )
24            IFS=$'\n'
25            COMPREPLY=( $( compgen -d -W '$(find "${path_array[@]}" . \
26                -mindepth 1 -maxdepth 1 -not -type d -executable \
27                -printf "%f\\n" 2>/dev/null)' -- "$cur" ) )
28        fi
29    elif [ $COMP_CWORD -eq 2 ]; then
30        prev=${prev##*/}
31        COMPREPLY=( $( compgen -fW "$( command ps axo comm,pid | \
32            awk '{if ($1 ~ /^'"$prev"'/) print $2}' )" -- "$cur" ) )
33    fi
34} &&
35complete -F _gdb $default gdb
36
37# Local variables:
38# mode: shell-script
39# sh-basic-offset: 4
40# sh-indent-comment: t
41# indent-tabs-mode: nil
42# End:
43# ex: ts=4 sw=4 et filetype=sh