Last active
March 28, 2021 15:49
-
-
Save sezanzeb/1236917f509f13d30010c98c9fa8389f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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