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