Skip to content

Instantly share code, notes, and snippets.

@r3n4ud
Forked from jrd/bépo-afnor-quote-invert
Created March 15, 2022 09:27

Revisions

  1. @jrd jrd revised this gist Jun 17, 2020. 1 changed file with 9 additions and 3 deletions.
    12 changes: 9 additions & 3 deletions bépo-afnor-quote-invert
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #!/usr/bin/env python3
    from os import getuid
    from subprocess import check_call
    from subprocess import run
    from sys import exit, stderr


    @@ -15,7 +15,7 @@ if getuid() != 0:
    )
    exit(0)
    # création sauvegarde si inexistante ou fichier plus récent (après mise à jour)
    check_call(['cp', '-u', MAIN_PATH, BACKUP_PATH])
    run(['cp', '-u', MAIN_PATH, BACKUP_PATH], check=True)
    with open(MAIN_PATH, 'r+') as f:
    content = f.read()
    # liste des modifications ('original': 'modification')
    @@ -30,4 +30,10 @@ with open(MAIN_PATH, 'r+') as f:
    for original, modification in modifications.items():
    content = content.replace(original.strip(), modification.strip())
    f.write(content)
    print("Modifications effectuées, veuillez redémarrer X")
    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")
  2. @jrd jrd created this gist Apr 16, 2020.
    33 changes: 33 additions & 0 deletions bépo-afnor-quote-invert
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    #!/usr/bin/env python3
    from os import getuid
    from subprocess import check_call
    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)
    check_call(['cp', '-u', MAIN_PATH, BACKUP_PATH])
    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)
    print("Modifications effectuées, veuillez redémarrer X")