From 6e4912d9cc006b1f63dc1751a671a402a1fbdf02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Tue, 17 May 2011 20:07:08 +0300 Subject: [PATCH] screen: Drop pid prefixes from session name completions where possible. Thanks-to: Alexey Zaytsev --- completions/screen | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/completions/screen b/completions/screen index e370c8ea..9e4b33cf 100644 --- a/completions/screen +++ b/completions/screen @@ -4,9 +4,23 @@ have screen || return _screen_sessions() { - COMPREPLY=( $( compgen -W "$( command screen -ls | sed -ne \ - 's|^\t\{1,\}\([0-9]\{1,\}\.[^\t]\{1,\}\).*'"$1"'.*$|\1|p' )" \ - -- "$cur" ) ) + 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 } && _screen() {