Skip to content

Instantly share code, notes, and snippets.

@sezanzeb
Last active March 28, 2021 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sezanzeb/1236917f509f13d30010c98c9fa8389f to your computer and use it in GitHub Desktop.
Save sezanzeb/1236917f509f13d30010c98c9fa8389f to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import os
import re
def find_xkb_names_in_file(path):
"""Return a set of all keys used in this xkb symbols file."""
keys = set()
with open(path) as f:
for line in f:
start = r'.*key.+<.+\['
end = r'\].*'
valid_characters = r'[0-9a-zA-Z_,\s]'
match = re.match(f'{start}({valid_characters}+){end}', line)
if match is None:
continue
match = re.sub('\s', '', match[1]).split(',')
for key in match:
if '0x' in key or len(key) == 0:
continue
if re.match(r'^U[A-F0-9a-f]+$', key):
continue
keys.add(key)
return keys
def find_all_xkb_names():
"""Return a set of all keys used in xkb symbols files on this computer."""
keys = set()
for root, dirs, files in os.walk('/usr/share/X11/xkb/symbols'):
for name in files:
path = os.path.join(root, name)
if 'key-mapper' in path:
continue
keys = keys.union(find_xkb_names_in_file(path))
return keys
if __name__ == '__main__':
print(find_all_xkb_names())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment