From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8868 invoked from network); 17 Dec 2006 13:04:23 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.7 (2006-10-05) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,FORGED_RCVD_HELO autolearn=ham version=3.1.7 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 17 Dec 2006 13:04:23 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 25059 invoked from network); 17 Dec 2006 13:04:10 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 17 Dec 2006 13:04:10 -0000 Received: (qmail 13527 invoked by alias); 17 Dec 2006 13:04:03 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 23057 Received: (qmail 13513 invoked from network); 17 Dec 2006 13:04:02 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 17 Dec 2006 13:04:02 -0000 Received: (qmail 24339 invoked from network); 17 Dec 2006 13:04:02 -0000 Received: from smtp4-g19.free.fr (212.27.42.30) by a.mx.sunsite.dk with SMTP; 17 Dec 2006 13:03:58 -0000 Received: from localhost (evr91-1-82-227-12-160.fbx.proxad.net [82.227.12.160]) by smtp4-g19.free.fr (Postfix) with ESMTP id C7C7D891C for ; Sun, 17 Dec 2006 14:03:57 +0100 (CET) Date: Sun, 17 Dec 2006 14:03:57 +0100 From: "arno." To: zsh-workers@sunsite.dk Subject: PATCH: _setxkbmap Message-ID: <20061217130357.GA16480@localhost.localdomain> Mail-Followup-To: zsh-workers@sunsite.dk MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="y0ulUmNC+osPPQO6" Content-Disposition: inline User-Agent: Mutt/1.5.13 (2006-08-11) --y0ulUmNC+osPPQO6 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi, I made a completion file for setxkbmap (a X utility to change keyboard=20 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=20 therefore, I could not make completion suggestions. *: setxkbmap allows layout to be specified either as first non-option=20 argument, either as argument to -layout option. In the same way, variant=20 can be specified either as second option, either as argument to=20 -variant. It looks quite unusual to me. As a matter of fact, setxkbmap=20 source does not call getopt, but has it own option parser. I did not=20 find a nice way to consider that behaviour with zsh completion, so I=20 simply discarded -variant and -layout option. *: Another problem is that xkb files are in /usr/lib/X11/xkb (according=20 to setxkbmap manual), but are in /usr/share/X11/xkb on my linux=20 distribution. My workaround is : for dir in /usr/lib/X11/xkb /usr/share/X11/xkb; do if [ -d $dir ] ; then sourcedir=3D$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.=20 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/_se= txkbmap --- 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=3D$dir + break + fi + done + [ -d $sourcedir ] || return 1 + + local -a arguments + + arguments=3D( + '-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=3D"$1" + local label=3D"$2" + + local -a fullpath shortpath + + fullpath=3D($sourcedir/$dir/**/*~*README(.)) + shortpath=3D(${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=3D$sourcedir/symbols/${1} + local -a variants lines + + if [ ! -f $file ]; then + _message "no such layout: ${1}" + return 1 + fi + + lines=3D("${(f)$(< ${file})}") + variants=3D(${${${(M)lines:#*xkb_symbols*\"([[:alnum:]])##\"*}##*xkb_s= ymbols([^\"])##\"}%%\"*}) + =20 + _wanted variant expl 'variant' compadd -a variants + +} + +_setxkbmap "$@" --y0ulUmNC+osPPQO6 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFFhUA9iH9aBScBsrMRAotQAJ9jjTNNSqHgupScKwVx40Re4VqkawCeLirj O6GaBPjr+VQf0+DIQ7+/UTw= =JxOt -----END PGP SIGNATURE----- --y0ulUmNC+osPPQO6--