95 lines
2.2 KiB
Plaintext
Raw Normal View History

# bash completion for screen -*- shell-script -*-
2009-03-30 21:56:09 +02:00
_screen_sessions()
{
local sessions=( $( command screen -ls | sed -ne \
's|^\t\{1,\}\([0-9]\{1,\}\.[^\t]\{1,\}\).*'"$1"'.*$|\1|p' ) )
if [[ $cur == +([0-9])?(.*) ]]; then
# Complete sessions including pid prefixes
COMPREPLY=( $( compgen -W '${sessions[@]}' -- "$cur" ) )
else
# Create unique completions, dropping pids where possible
local -A res
local i tmp
for i in ${sessions[@]}; do
res[${i/#+([0-9])./}]+=" $i"
done
for i in ${!res[@]}; do
[[ ${res[$i]} == \ *\ * ]] && tmp+=" ${res[$i]}" || tmp+=" $i"
done
COMPREPLY=( $( compgen -W '$tmp' -- "$cur" ) )
fi
2009-03-30 21:56:09 +02:00
} &&
_screen()
{
local cur prev words cword
_init_completion || return
if ((cword > 2)); then
case ${words[cword-2]} in
-[dD])
_screen_sessions
return 0
;;
esac
fi
2009-03-30 21:56:09 +02:00
local i
for (( i=1; i <= cword; i++ )); do
case ${words[i]} in
-r|-R|-d|-D|-x|-s|-c|-T|-e|-h|-p|-S|-t)
(( i++ ))
continue
;;
-*)
continue
;;
esac
_command_offset $i
return
done
case $prev in
2009-10-04 19:42:50 +02:00
-[rR])
# list detached
_screen_sessions 'Detached'
return 0
;;
-[dD])
2009-10-04 19:42:50 +02:00
# list attached
_screen_sessions 'Attached'
return 0
;;
-x)
# list both
_screen_sessions
return 0
;;
2009-10-04 19:42:50 +02:00
-s)
2009-12-09 01:01:49 +02:00
_shells
return 0
2009-10-04 19:42:50 +02:00
;;
-c)
_filedir
return 0
;;
2011-04-25 15:19:48 +03:00
-T)
_terms
return 0
;;
-e|-h|-p|-S|-t)
return 0
;;
2009-10-04 19:42:50 +02:00
esac
2009-03-30 21:59:58 +02:00
2009-10-04 19:42:50 +02:00
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '-a -A -c -d -D -e -f -fn -fa -h -i -ln \
2011-04-25 15:19:48 +03:00
-list -L -m -O -p -q -r -R -s -S -t -T -U -v -wipe -x -X --help \
--version' -- "$cur" ) )
2009-10-04 19:42:50 +02:00
fi
} &&
complete -F _screen screen
2009-10-04 19:42:50 +02:00
# ex: ts=4 sw=4 et filetype=sh