factorize session completions

This commit is contained in:
Guillaume Rousse 2009-03-30 21:56:09 +02:00
parent 515beac77e
commit 2c3fd00439

View File

@ -6,6 +6,19 @@
# screen(1) completion # screen(1) completion
# #
have screen && have screen &&
_screen_sessions()
{
local pattern
if [ -n "$1" ]; then
pattern=".*$1.*"
else
pattern=".*"
fi
COMPREPLY=( $( command screen -ls | \
sed -ne 's|^['$'\t'']\+\('$cur'[0-9]\+\.[^'$'\t'']\+\)'$pattern'$|\1|p' ) )
} &&
_screen() _screen()
{ {
local cur prev preprev local cur prev preprev
@ -16,32 +29,34 @@ _screen()
[ "$COMP_CWORD" -ge 2 ] && preprev=${COMP_WORDS[COMP_CWORD-2]} [ "$COMP_CWORD" -ge 2 ] && preprev=${COMP_WORDS[COMP_CWORD-2]}
if [ "$preprev" = "-d" -o "$preprev" = "-D" -a "$prev" = "-r" -o \ case "$preprev" in
"$prev" = "-R" ]; then -[dD])
# list all _screen_sessions
COMPREPLY=( $( command screen -ls | \ return 0
sed -ne 's|^['$'\t'']\+\('$cur'[0-9]\+\.[^'$'\t'']\+\).*$|\1|p' ) ) ;;
else esac
case "$prev" in
case "$prev" in
-[rR]) -[rR])
# list detached # list detached
COMPREPLY=( $( command screen -ls | \ _screen_sessions 'Detached'
sed -ne 's|^['$'\t'']\+\('$cur'[0-9]\+\.[^'$'\t'']\+\).*Detached.*$|\1|p' ) ) return 0
;; ;;
-[dDx]) -[dDx])
# list attached # list attached
COMPREPLY=( $( command screen -ls | \ _screen_sessions 'Attached'
sed -ne 's|^['$'\t'']\+\('$cur'[0-9]\+\.[^'$'\t'']\+\).*Attached.*$|\1|p' ) ) return 0
;; ;;
-s) -s)
# shells # shells
COMPREPLY=( $( grep ^${cur:-[^#]} /etc/shells ) ) COMPREPLY=( $( grep ^${cur:-[^#]} /etc/shells ) )
;; ;;
*) -c)
_filedirs
return 0
;; ;;
esac esac
fi fi
return 0
} && } &&
complete -F _screen $default screen complete -F _screen $default screen