diff options
Diffstat (limited to 'scripts/.scripts')
-rwxr-xr-x | scripts/.scripts/i3removesupportof.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/scripts/.scripts/i3removesupportof.py b/scripts/.scripts/i3removesupportof.py new file mode 100755 index 0000000..6cbc877 --- /dev/null +++ b/scripts/.scripts/i3removesupportof.py @@ -0,0 +1,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") |