Hello

I'd like to submit this implementation of "loadkeys" completion, in
order to fix #313855. Since I cannot attach anything to the ticket, I
thought about posting the patch here.

        D

-- 
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