* PATCH: _setxkbmap
@ 2006-12-17 13:03 arno.
0 siblings, 0 replies; only message in thread
From: arno. @ 2006-12-17 13:03 UTC (permalink / raw)
To: zsh-workers
[-- Attachment #1: Type: text/plain, Size: 4201 bytes --]
Hi,
I made a completion file for setxkbmap (a X utility to change keyboard
layout).
I have a few difficulties, so I'm not that happy with my completion script :
*: There are some options of setxkbmap I did not understand, and
therefore, I could not make completion suggestions.
*: setxkbmap allows layout to be specified either as first non-option
argument, either as argument to -layout option. In the same way, variant
can be specified either as second option, either as argument to
-variant. It looks quite unusual to me. As a matter of fact, setxkbmap
source does not call getopt, but has it own option parser. I did not
find a nice way to consider that behaviour with zsh completion, so I
simply discarded -variant and -layout option.
*: Another problem is that xkb files are in /usr/lib/X11/xkb (according
to setxkbmap manual), but are in /usr/share/X11/xkb on my linux
distribution. My workaround is :
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
Have you ever had this problem ?
How did you solve it ?
So, my script is far from perfect, but it's still quite useful for me.
May be it would be for other people so I submit it to you.
arno.
diff -Nur zsh/Completion/X/Command/_setxkbmap zsh~/Completion/X/Command/_setxkbmap
--- zsh/Completion/X/Command/_setxkbmap 1970-01-01 01:00:00.000000000 +0100
+++ zsh~/Completion/X/Command/_setxkbmap 2006-12-17 13:57:26.000000000 +0100
@@ -0,0 +1,100 @@
+# 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 "$@"
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2006-12-17 13:04 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-12-17 13:03 PATCH: _setxkbmap arno.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).