Created
December 31, 2018 09:15
-
-
Save ayanamist/40d4b49028a0aa6650b85be1ed141272 to your computer and use it in GitHub Desktop.
Convert Xshell 6 *.xsh files to Xshell 5 *.xsh format
This file contains hidden or 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/env python2 | |
# -*- coding: utf-8 -*- | |
import ConfigParser | |
import codecs | |
import sys | |
import StringIO | |
def main(): | |
config = ConfigParser.RawConfigParser(allow_no_value=True) | |
config.optionxform = str | |
with open(sys.argv[1], 'rb') as f: | |
encoded_text = f.read() | |
if encoded_text.startswith(codecs.BOM_UTF16_LE): | |
encoded_text = encoded_text[len(codecs.BOM_UTF16_LE):] | |
buf = StringIO.StringIO(encoded_text.decode('utf-16le')) | |
elif encoded_text.startswith(codecs.BOM_UTF8): | |
encoded_text = encoded_text[len(codecs.BOM_UTF8):] | |
buf = StringIO.StringIO(encoded_text.decode('utf8')) | |
else: | |
buf = StringIO.StringIO(encoded_text.decode('utf8')) | |
config.readfp(buf) | |
buf.close() | |
config.remove_section('BELL') | |
config.remove_section('HIGHLIGHT') | |
config.remove_section('ADVANCED') | |
config.set('SessionInfo', 'version', '5.3') | |
config.remove_option('CONNECTION:SSH', 'SSHCiphers') | |
config.remove_option('CONNECTION:SSH', 'SSHMACs') | |
config.remove_option('CONNECTION:SSH', 'SSHKeyExchanges') | |
config.remove_option('TERMINAL', 'FixedCols') | |
buf = StringIO.StringIO() | |
config.write(buf) | |
with open(sys.argv[1], 'wb') as f: | |
f.write(buf.getvalue().replace(' = ', '=').encode('utf8')) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment