2011-11-01 22:14:45 +02:00
|
|
|
# bash completion for gdb -*- shell-script -*-
|
2009-05-17 22:05:54 +02:00
|
|
|
|
|
|
|
_gdb()
|
|
|
|
{
|
2011-04-20 17:02:27 +03:00
|
|
|
local cur prev words cword
|
|
|
|
_init_completion || return
|
2009-05-17 22:05:54 +02:00
|
|
|
|
2011-11-09 23:28:11 +02:00
|
|
|
if [[ $cword -eq 1 ]]; then
|
2009-10-04 19:42:50 +02:00
|
|
|
local IFS
|
2011-04-21 12:33:05 +03:00
|
|
|
compopt -o filenames
|
2009-10-04 19:42:50 +02:00
|
|
|
if [[ "$cur" == */* ]]; then
|
|
|
|
# compgen -c works as expected if $cur contains any slashes.
|
|
|
|
IFS=$'\n'
|
|
|
|
COMPREPLY=( $( PATH="$PATH:." compgen -d -c -- "$cur" ) )
|
|
|
|
else
|
|
|
|
# otherwise compgen -c contains Bash's built-in commands,
|
|
|
|
# functions and aliases. Thus we need to retrieve the program
|
|
|
|
# names manually.
|
|
|
|
IFS=":"
|
2009-12-09 22:46:09 +02:00
|
|
|
local path_array=( $( \
|
2010-01-18 18:53:41 +02:00
|
|
|
sed -e 's/:\{2,\}/:/g' -e 's/^://' -e 's/:$//' <<<"$PATH" ) )
|
2009-10-04 19:42:50 +02:00
|
|
|
IFS=$'\n'
|
|
|
|
COMPREPLY=( $( compgen -d -W '$(find "${path_array[@]}" . \
|
|
|
|
-mindepth 1 -maxdepth 1 -not -type d -executable \
|
|
|
|
-printf "%f\\n" 2>/dev/null)' -- "$cur" ) )
|
|
|
|
fi
|
2011-11-09 23:28:11 +02:00
|
|
|
elif [[ $cword -eq 2 ]]; then
|
2011-05-11 00:35:16 +03:00
|
|
|
COMPREPLY=( $( compgen -W "$( command ps axo comm,pid | \
|
|
|
|
awk '{if ($1 ~ /^'"${prev##*/}"'/) print $2}' )" -- "$cur" ) )
|
|
|
|
compopt -o filenames
|
|
|
|
COMPREPLY+=( $( compgen -f -X '!?(*/)core?(.+([0-9]))' -o plusdirs \
|
|
|
|
-- "$cur" ) )
|
2009-10-04 19:42:50 +02:00
|
|
|
fi
|
2009-05-17 22:05:54 +02:00
|
|
|
} &&
|
2011-05-11 00:35:16 +03:00
|
|
|
complete -F _gdb gdb
|
2009-10-01 20:54:51 +03:00
|
|
|
|
2009-10-04 19:42:50 +02:00
|
|
|
# ex: ts=4 sw=4 et filetype=sh
|