Skip to content

Instantly share code, notes, and snippets.

@ayanamist
Created December 31, 2018 09:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayanamist/40d4b49028a0aa6650b85be1ed141272 to your computer and use it in GitHub Desktop.
Save ayanamist/40d4b49028a0aa6650b85be1ed141272 to your computer and use it in GitHub Desktop.
Convert Xshell 6 *.xsh files to Xshell 5 *.xsh format
#!/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