[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 1.3-306-g6e4912d

Ville Skyttä ville.skytta at iki.fi
Tue May 17 17:08:33 UTC 2011


The following commit has been merged in the master branch:
commit 6e4912d9cc006b1f63dc1751a671a402a1fbdf02
Author: Ville Skyttä <ville.skytta at iki.fi>
Date:   Tue May 17 20:07:08 2011 +0300

    screen: Drop pid prefixes from session name completions where possible.
    
    Thanks-to: Alexey Zaytsev <alexey.zaytsev at gmail.com>

diff --git a/completions/screen b/completions/screen
index e370c8e..9e4b33c 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()
 {

-- 
bash-completion



More information about the Bash-completion-commits mailing list