2

I need to list all possible xkb layouts and their respective variants that do not use 3rd-level symbols. Manually review of all files in /usr/share/X11/xkb/symbols/ directory is crazy, there maybe an easier way?

2
  • @don_crissti so, it works, but it doesn't completely solve problem. US layout for example missing in the list, but some variants ("basic" or "dvorak" e.g.) nevertheless don't use 3rd level symbols. I.e. I need parsing of all possible layouts and variants.
    – png2378
    Jun 24 '16 at 21:52
  • My idea after your comment - if xkb_symbols "*" { equally include "level3(ralt_switch)", then all variants of this layout include 3rd level symbols. Maybe after that it will be possible to continue parsing manually.
    – png2378
    Jun 24 '16 at 21:57
3

You could process the list of all layouts and for each item in the list check every corresponding variant for level3 symbols:

list=($(sed '/! layout/,/^$/!d;//d
s/[[:blank:]]*\([^[:blank:]]*\)[[:blank:]].*/\1/' \
< /usr/share/X11/xkb/rules/evdev.lst))

layouts=("${list[@]##*/}")

for i in "${layouts[@]}"; do
sed -n '\|//.*level3|d;H;/xkb_symbols/{s/.*"\(.*\)".*/'"${i}:"'\1/;h}
/^};/{x;/level3/d;s/\n.*//p}' < /usr/share/X11/xkb/symbols/${i}
done

The first sed lists all layouts in /usr/share/X11/xkb/rules/evdev.lst and saves the result in the array list. The elements of this array are then further processed via param expansion to get only the layout name (e.g. extract jp from nec_vndr/jp) and saved into the array layouts.
Then, for each item in layouts the corresponding /usr/share/X11/xkb/symbols/${item} file is processed to extract the variants that have no level3 symbols: sed first deletes all commented lines that contain level3, then unconditionally appends each line to Hold buffer. It edits the line containing the variant name prepending the layout name and overwriting the hold buffer, then, at the end of each variant section (/^};/) it exchanges buffers, deleting the pattern space if it contains level3 else printing only the first line (i.e. layout:variant). So the result is something like this:

us:basic
us:ibm238l
us:dvorak
us:dvorak-l
us:dvorak-r
us:dvorak-classic
us:dvp
us:olpc2
us:chr
us:carpalx
us:carpalx-full
us:alt-intl-unicode
us:sun_type6
............
dk:nodeadkeys
dk:winkeys
dk:mac
dk:mac_nodeadkeys
dk:dvorak
dk:sun_type6
............
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.