2011-11-01 22:14:45 +02:00
|
|
|
# bash completion for screen -*- shell-script -*-
|
2009-03-30 21:49:40 +02:00
|
|
|
|
2009-03-30 21:56:09 +02:00
|
|
|
_screen_sessions()
|
|
|
|
{
|
2011-05-17 20:07:08 +03:00
|
|
|
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
|
|
|
} &&
|
2009-03-30 21:49:40 +02:00
|
|
|
_screen()
|
|
|
|
{
|
2010-06-09 22:37:02 +02:00
|
|
|
local cur prev words cword
|
2011-04-21 11:04:51 +03:00
|
|
|
_init_completion || return
|
2009-03-30 21:49:40 +02:00
|
|
|
|
2010-06-10 23:51:30 +02:00
|
|
|
if ((cword > 2)); then
|
|
|
|
case ${words[cword-2]} in
|
|
|
|
-[dD])
|
|
|
|
_screen_sessions
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
2009-03-30 21:56:09 +02:00
|
|
|
|
2011-04-25 15:51:33 +03: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
|
|
|
|
|
2009-12-30 00:39:59 +01:00
|
|
|
case $prev in
|
2009-10-04 19:42:50 +02:00
|
|
|
-[rR])
|
|
|
|
# list detached
|
|
|
|
_screen_sessions 'Detached'
|
|
|
|
return 0
|
|
|
|
;;
|
2010-11-05 01:19:14 +00:00
|
|
|
-[dD])
|
2009-10-04 19:42:50 +02:00
|
|
|
# list attached
|
|
|
|
_screen_sessions 'Attached'
|
|
|
|
return 0
|
|
|
|
;;
|
2010-11-05 01:19:14 +00:00
|
|
|
-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
|
|
|
|
;;
|
2011-04-25 15:21:53 +03:00
|
|
|
-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
|
2009-12-09 01:06:47 +02:00
|
|
|
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 \
|
2009-12-09 01:06:47 +02:00
|
|
|
--version' -- "$cur" ) )
|
2009-10-04 19:42:50 +02:00
|
|
|
fi
|
2009-03-30 21:49:40 +02:00
|
|
|
} &&
|
2011-04-25 15:51:33 +03:00
|
|
|
complete -F _screen screen
|
2009-10-01 20:54:51 +03:00
|
|
|
|
2009-10-04 19:42:50 +02:00
|
|
|
# ex: ts=4 sw=4 et filetype=sh
|