Skip to content

Instantly share code, notes, and snippets.

@jrd
Last active July 13, 2022 17:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jrd/7b75612d566b063eaeb85b276d565522 to your computer and use it in GitHub Desktop.
Save jrd/7b75612d566b063eaeb85b276d565522 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
from os import getuid
from subprocess import run
from sys import exit, stderr
MAIN_PATH = '/usr/share/X11/xkb/symbols/fr'
BACKUP_PATH = MAIN_PATH + '.bck'
if getuid() != 0:
print(
"Vous devez lancer ce script avec les droits d’administration.",
file=stderr,
)
exit(0)
# création sauvegarde si inexistante ou fichier plus récent (après mise à jour)
run(['cp', '-u', MAIN_PATH, BACKUP_PATH], check=True)
with open(MAIN_PATH, 'r+') as f:
content = f.read()
# liste des modifications ('original': 'modification')
modifications = {
"""key <AC05> { type[group1] = "FOUR_LEVEL", [ comma, semicolon, apostrophe, dead_belowcomma ] }; // , ; ' ,""": # noqa: E501
"""key <AC05> { type[group1] = "FOUR_LEVEL", [ comma, semicolon, rightsinglequotemark, dead_belowcomma ] }; // , ; ’ ,""", # noqa: E501
"""key <AB06> { type[group1] = "FOUR_LEVEL", [ rightsinglequotemark, question, questiondown, dead_hook ] }; // ’ ? ¿ ̉ """: # noqa: E501
"""key <AB06> { type[group1] = "FOUR_LEVEL", [ apostrophe, question, questiondown, dead_hook ] }; // ' ? ¿ ̉ """, # noqa: E501
}
if all([orig.strip() in content for orig in modifications]):
f.seek(0)
for original, modification in modifications.items():
content = content.replace(original.strip(), modification.strip())
f.write(content)
xkbinfo = dict([
map(lambda x: x.strip(), line.split(':', 1))
for line in
run(['setxkbmap', '-query'], check=True, capture_output=True, text=True).stdout.strip().split('\n') # noqa: E501
])
run(['setxkbmap', xkbinfo['layout'], xkbinfo['variant']], check=True)
print("Modifications effectuées, veuillez redémarrer X dès que possible")
@Monolecte
Copy link

Monolecte commented May 23, 2021

Bonsoir et merci pour ce partage.
J’ai exécuté le script, vérifié les modifs dans le fichier cible (effectuées), redémarré la bécane… et rien. Je continue à devoir faire alt gr + , pour obtenir ’…
Sous Ubuntu LTS 20.04.2 avec clavier TypeMatrix 2030 et disposition BÉPO AFNOR.

@cdeleuze
Copy link

Je viens de le faire sur une Debian 11 sur un laptop et cela a fonctionné. Je n'avais pas eu ce soucis auparavant (Debian 10), je soupçonne que la disposition ait légèrement changé quand elle a été normalisée...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment