Ha. "oops". Sorry for the noise, then.

Anyway, here's an updated version. Using _init_completion -s. Hope i did
it right.

I've also added '-i map.gz' options to _init_completion so that reading
key maps from stdin are allowed.

    D

Le lundi 09 juin 2014 à 14:01 +0300, Ville Skyttä a écrit :
> On Mon, Jun 9, 2014 at 1:52 PM, Dams <ali...@livna.org> wrote:
> >
> > Sorry, I'm still a bit new to this. Simply using _parse_help, and doing 
> > "loadkeys --con<TAB>" showed me a "loadkeys --console= " (with the trailing 
> > space)
> 
> That's what the nospace thing in the patch I linked to is for.
> 
> > By the way, why not also showing short single-letter options in the 
> > completion ? Is that on purpose ?
> 
> Yes, see CONTRIBUTING in README (search for "offer only the most 
> descriptive").

-- 
Dams <ali...@livna.org>
>From 9c3d947f08a008b5162b0fae200c76020307bc00 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Damien=20Nad=C3=A9?= <ali...@livna.org>
Date: Sun, 8 Jun 2014 19:53:26 +0200
Subject: [PATCH] loadkeys: new completion file for loadkeys command

---
 completions/loadkeys | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 completions/loadkeys

diff --git a/completions/loadkeys b/completions/loadkeys
new file mode 100644
index 0000000..0ae22d2
--- /dev/null
+++ b/completions/loadkeys
@@ -0,0 +1,53 @@
+# bash completion for loadkeys                    -*- shell-script -*-
+
+## @fn _loadkeys_usage()
+## @brief parse loadkeys --help to obtain long/short options.
+_loadkeys_usage() {
+    # _parse_usage does not help, due to '--console='.
+    local -a shorts longs
+    while read line
+    do
+        if [[ $line =~ ^\ *(-[a-zA-Z])\ (--[-A-Za-z0-9]+)(=[^\ ]+)?\ +.*$ ]]
+        then
+            shorts+=( "${BASH_REMATCH[1]}" )
+            longs+=( "${BASH_REMATCH[2]}" )
+        fi
+    done < <(loadkeys -h 2>&1 || :)
+    printf "%s %s"  "${shorts[*]}" "${longs[*]}"
+}
+
+## @fn _loadkeys()
+## @brief completion helper for loadkeys.
+_loadkeys() {
+    local cur prev words cword
+    _init_completion || return
+
+    # FIXME: We should implement "< <glob>.map.gz"
+    if [[ "$prev" = @(-C|--console) ]]
+    then
+        # FIXME : What can one provides to loadkeys ?  ttys ?
+        # Regular files ? I dont know.
+        COMPREPLY=( $(compgen -W "/dev/console" -- "$cur" ) )
+    else
+        case "$cur" in
+            ""|*)
+                local restore_shopt=$(
+                    shopt -p extglob failglob nullglob globstar)
+                shopt -u failglob
+                shopt -s extglob nullglob globstar
+                COMPREPLY=( /{usr/,usr/local/,}@(share|lib*)/kbd/keymaps/**/*.map.gz )
+                eval "$restore_shopt"
+                COMPREPLY=( "${COMPREPLY[@]##*/}" )
+                COMPREPLY=( "${COMPREPLY[@]%.map.gz}" )
+                COMPREPLY=( $(compgen -W "${COMPREPLY[*]}" -- "$cur") )
+                ;;&
+            ""|-*)
+                COMPREPLY+=( 
+                    $(compgen -W '$(_loadkeys_usage)' -- "$cur") )
+                ;;
+        esac
+    fi
+} &&
+complete -F _loadkeys loadkeys
+
+# ex: ts=4 sw=4 et filetype=sh
-- 
1.9.3

_______________________________________________
Bash-completion-devel mailing list
Bash-completion-devel@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/bash-completion-devel

Reply via email to