PageRenderTime 24ms CodeModel.GetById 22ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/bash_completion.d/strace

http://github.com/brinkman83/bashrc
#! | 103 lines | 94 code | 9 blank | 0 comment | 0 complexity | 63b7277ed887a91d7a009ffe447bc0ef MD5 | raw file
  1# bash completion for strace
  2
  3have strace &&
  4_strace()
  5{
  6    local cur prev offset i syscalls arch unistd
  7
  8    # check if we're still completing strace
  9    offset=0
 10    for (( i=1; i <= COMP_CWORD; i++ )); do
 11        case ${COMP_WORDS[$i]} in
 12            -@(o|e|p))
 13                i=$((i+1))
 14                continue
 15                ;;
 16            -*)
 17                continue
 18                ;;
 19        esac
 20        offset=$i
 21        break
 22    done
 23
 24    if [ $offset -gt 0 ]; then
 25        # FAIL: _command_offset is not defined anywhere. Guillame?
 26        _command_offset $offset
 27    else
 28
 29        COMPREPLY=()
 30        cur=`_get_cword`
 31        prev=${COMP_WORDS[COMP_CWORD-1]}
 32
 33        case $prev in
 34        -e)
 35            if [[ "$cur" == *=* ]]; then
 36                prev=${cur/=*/}
 37                cur=${cur/*=/}
 38
 39                # Import arch-specific syscalls -- not foolproof IMHO
 40                #+                                     --David Paleino
 41                arch=$(command uname -m)
 42                syscalls=$(awk '/^#define __NR/ {print $2}' \
 43                    /usr/include/asm/unistd.h | sed -e \
 44                    's/__NR_//')
 45                if [ -z "$syscalls" ]; then
 46                    if [[ "$arch" =~ 86$ ]]; then
 47                        unistd=/usr/include/asm/unistd_32.h
 48                    else
 49                        unistd=/usr/include/asm/unistd_64.h
 50                    fi
 51                    syscalls=$(awk '/^#define __NR/ {print $2}' \
 52                        $unistd | sed -e 's/__NR_//')
 53                fi
 54
 55                case $prev in
 56                    trace)
 57                        COMPREPLY=( $( compgen -W "$syscalls file process \
 58                            network signal ipc desc all none" -- "$cur") )
 59                        return 0
 60                        ;;
 61                esac
 62            else
 63                COMPREPLY=( $( compgen -S"=" -W 'trace abbrev \
 64                    verbose raw signal read write' -- "$cur" ) )
 65            fi
 66            return 0
 67            ;;
 68        -o)
 69            _filedir
 70            return 0
 71            ;;
 72        -p)
 73            _pids
 74            return 0
 75            ;;
 76        -S)
 77            COMPREPLY=( $( compgen -W 'time calls name nothing' -- "$cur" ) )
 78            return 0
 79            ;;
 80        -u)
 81            COMPREPLY=( $( compgen -u -- "$cur" ) )
 82            return 0
 83            ;;
 84        esac
 85
 86        if [[ "$cur" == -* ]]; then
 87            COMPREPLY=( $( compgen -W '-c -d -f -ff -F -h --help -i -q \
 88                -r -t -tt -ttt -T -v -V -x -xx -a -e -o -O -p \
 89                -s -S -u -E' -- "$cur" ) )
 90        else
 91            COMPREPLY=( $( compgen -c -- "$cur" ) )
 92        fi
 93    fi
 94} &&
 95complete -F _strace $default strace
 96
 97# Local variables:
 98# mode: shell-script
 99# sh-basic-offset: 4
100# sh-indent-comment: t
101# indent-tabs-mode: nil
102# End:
103# ex: ts=4 sw=4 et filetype=sh