@@ -0,0 +1,1297 @@
+import os%0Aimport sys%0A%0Acomment_syntax_dict = %7B%0A  '.py': '# ',%0A  '.pl': '# ',%0A  '.rb': '# ',%0A  '.php': '# ',%0A  '.c': '// ',%0A  '.h': '// ',%0A  '.cpp': '// ',%0A  '.cs': '// ',%0A  '.go': '// ',%0A  '.java': '// ',%0A  '.js': '// ',%0A  '.m': '// ',%0A  '.mm': '// ',%0A  '.swift': '// ',%0A  '.sass': '// ',%0A  '.scss': '// ',%0A  '.lisp': '; '%0A%7D%0A%0Adef get_comment_syntax(filepath):%0A  _, extension = os.path.splitext(filepath)%0A  if extension in comment_syntax_dict:%0A    return comment_syntax_dict%5Bextension%5D%0A  # TODO: This needs to replaced so that users can input the right inline comment %0A  # syntax for unknown file types.%0A  return '#'%0A%0Adef insert_comment(filepath, line_number, comment):%0A  comment_syntax = get_comment_syntax(filepath)%0A  with open(filepath, 'r') as f:%0A    lines = f.readlines()%0A    lines.insert(line_number - 1, comment_syntax + comment + '%5Cn')%0A%0A  with open(filepath, 'w') as f:%0A    f.writelines(lines)%0A%0Adef main():%0A  if len(sys.argv) %3C 4:%0A    print 'USAGE:%5Cnpython insert_comment.py %5Bfile path%5D %5Bline number%5D %5Bcomment%5D%5Cn%5Ct%5Bfile path%5D: path of file to insert comments into%5Cn%5Ct%5Bline number%5D: line to insert comment before%5Cn%5Ct%5Bcomment%5D: comment to insert (wrap in quotes if multiple words)%5Cn'%0A  else: %0A    insert_comment(sys.argv%5B1%5D, int(sys.argv%5B2%5D), sys.argv%5B3%5D)%0A%0Aif __name__ == %22__main__%22:%0A  main()%0A

insert inline comment script