aboutsummaryrefslogtreecommitdiff
path: root/scripts/.scripts/i3removesupportof.py
blob: 6cbc87761720e53126409efd0bb92f269c1089c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#/bin/python

import re, sys, os

key_to_rm=str(sys.argv[1])
config_file=os.path.expanduser("~/.config/i3/config")

oneline_conf_file = ""

conf_file_input = open(config_file, 'r')

for line in conf_file_input:
    line = re.sub("^#{1}\.", "", line)
    oneline_conf_file = oneline_conf_file + line

conf_file_input.close()


# add key
block_conf_found = re.search(r"#{1}"+key_to_rm+".*#{1}"+key_to_rm+".", oneline_conf_file, re.DOTALL)

if block_conf_found != None:

    block_conf_found_splited = block_conf_found.group(0).splitlines()

    oneline_final_data = ""
    line_parsed=0
    comment_this_line=0
    end_key=0
    for line in block_conf_found_splited:
        if re.search("^#{1}"+key_to_rm+"$", line):
            comment_this_line=1
        elif re.search("^#{1}"+key_to_rm+".$", line):
            end_key=1
            comment_this_line=0
        if comment_this_line == 1:
            oneline_final_data = oneline_final_data + "#." + line
        elif end_key == 1:
            oneline_final_data = oneline_final_data + "#." + line
            end_key = 0
        else:
            oneline_final_data = oneline_final_data + line
        if line_parsed != len(block_conf_found_splited)-1:
            oneline_final_data = oneline_final_data + "\n"
        line_parsed = line_parsed + 1


    oneline_new_conf_file = re.sub(r"#"+key_to_rm+".*#"+key_to_rm+".", oneline_final_data, oneline_conf_file, flags=re.DOTALL)

    confOutput = open(config_file, 'w')

    confOutput.write(oneline_new_conf_file)

    confOutput.close()
else:
    print("Sorry the keymap '"+str(sys.argv[1])+"' is not in this conf file, use 'fr' or 'bepo'.\nBetween, this script is used to remove a keymap support for i3wm.\nUsage:\n    "+sys.argv[0]+" fr")