about summary refs log tree commit diff
path: root/Completion/X/Command/_setxkbmap
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2006-12-17 15:33:27 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2006-12-17 15:33:27 +0000
commite475a39d4c4d5d4c5f0ddfba59eb2190d559112f (patch)
tree57c91ddd5322624799adc03982694928f737dcf5 /Completion/X/Command/_setxkbmap
parent937dc9a84d85bb1ca5135badd52461a928c17f6a (diff)
downloadzsh-e475a39d4c4d5d4c5f0ddfba59eb2190d559112f.tar.gz
zsh-e475a39d4c4d5d4c5f0ddfba59eb2190d559112f.tar.xz
zsh-e475a39d4c4d5d4c5f0ddfba59eb2190d559112f.zip
23057, 23058, 23059: completions from arno
Diffstat (limited to 'Completion/X/Command/_setxkbmap')
-rw-r--r--Completion/X/Command/_setxkbmap99
1 files changed, 99 insertions, 0 deletions
diff --git a/Completion/X/Command/_setxkbmap b/Completion/X/Command/_setxkbmap
new file mode 100644
index 000000000..85609b554
--- /dev/null
+++ b/Completion/X/Command/_setxkbmap
@@ -0,0 +1,99 @@
+# compdef setxkbmap
+
+# TODO:
+# model, option, symbols and types suggestions
+# take -layout and -variant into account
+
+_setxkbmap() {
+    emulate -L zsh
+    setopt extendedglob
+
+    # xkb files may be in different places depending on system
+    local dir sourcedir
+    for dir in /usr/lib/X11/xkb /usr/share/X11/xkb; do
+        if [ -d $dir ] ; then
+           sourcedir=$dir
+           break
+        fi
+    done
+    [ -d $sourcedir ] || return 1
+
+    local -a arguments
+
+    arguments=(
+        '-compat[compability map]:compability:_setxkbmap_compat'
+        '-config[configuration file]:configuration:_files'
+        '-display[display]:display:_x_display'
+        '-geometry[geometry component]:geometry:_setxkbmap_geometry'
+        '-model[model name]:model:'
+        '-option[xkb option]:option:'
+        '(-)'-print'[print component names]'
+        '-rules[rules file]:rules:_files'
+        '-symbols[symbols components]:symbols:'
+        '(-)'{-help,-h}'[Display help message]'
+        '-synch[force synchronization]'
+        '-types[types components]:types:'
+        '(-verbose -v)'{-verbose,-v}'[Set verbosity level]:verbosity:(0 1 2 3 4 5 6 7 8 9)'
+        '*::keyboard:_setxkbmap_dispatcher'
+    )
+    _arguments $arguments
+}
+
+_setxkbmap_dispatcher () {
+
+    case $CURRENT in
+        1)
+            _setxkbmap_layout
+        ;;
+        2)
+            _setxkbmap_variant "$words[1]"
+        ;;
+    esac
+}
+
+_setxkbmap_files () {
+    local dir="$1"
+    local label="$2"
+
+    local -a fullpath shortpath
+
+    fullpath=($sourcedir/$dir/**/*~*README(.))
+    shortpath=(${fullpath#$sourcedir\/$dir\/})
+
+    _wanted layout expl $label compadd -a - shortpath
+
+}
+
+(( $+functions[_setxkbmap_compat] )) ||
+_setxkbmap_compat() {
+    _setxkbmap_files "compat" "compatibility"
+}
+
+(( $+functions[_setxkbmap_layout] )) ||
+_setxkbmap_layout () {
+    _setxkbmap_files "symbols" "layout"
+}
+
+(( $+functions[_setxkbmap_geometry] )) ||
+_setxkbmap_geometry () {
+    _setxkbmap_files "geometry" "geometry"
+}
+
+(( $+functions[_setxkbmap_variant] )) ||
+_setxkbmap_variant () {
+    local file=$sourcedir/symbols/${1}
+    local -a variants lines
+
+    if [ ! -f $file ]; then
+        _message "no such layout: ${1}"
+        return 1
+    fi
+
+    lines=("${(f)$(< ${file})}")
+    variants=(${${${(M)lines:#*xkb_symbols*\"([[:alnum:]])##\"*}##*xkb_symbols([^\"])##\"}%%\"*})
+    
+    _wanted variant expl 'variant' compadd -a variants
+
+}
+
+_setxkbmap "$@"