Advertisement
Guest User

Untitled

a guest
Aug 6th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. example_output="""
  2. <snippet>
  3. <content><![CDATA[Type your snippet here]]></content>
  4. <!-- Optional: Tab trigger to activate the snippet -->
  5. <tabTrigger>xyzzy</tabTrigger>
  6. <!-- Optional: Scope the tab trigger will be active in -->
  7. <scope>source.python</scope>
  8. <!-- Optional: Description to show in the menu -->
  9. <description>My Fancy Snippet</description>
  10. </snippet>
  11. """
  12.  
  13. def random_string(length=32,upper=True,lower=True,digits=True):
  14. # Generates a random string with selectable characters
  15. # By: Cody Kochmann
  16. from random import choice
  17. chars = ""
  18. if upper:
  19. chars+="QWERTYUIOPASDFGHJKLZXCVBNM"
  20. if lower:
  21. chars+="qwertyuiopasdfghjklzxcvbnm"
  22. if digits:
  23. chars+="1234567890"
  24. return(''.join(choice(chars) for _ in range(length)))
  25.  
  26. def multiline_input(prompt=""):
  27. print(prompt+"")
  28. out=[]
  29. len_before_previous=1
  30. previous_len=1
  31. while previous_len > 0 and len_before_previous>0:
  32. current=raw_input("")
  33. if current != "":
  34. out.append(current)
  35. len_before_previous=previous_len
  36. previous_len=len(current)
  37. out="\n".join(out)
  38. return(out)
  39.  
  40. def remove_periods(s=""):
  41. if "." in s:
  42. return("".join(s.split(".")))
  43. return(s)
  44.  
  45. def get_username():
  46. import getpass
  47. return(str(getpass.getuser()))
  48.  
  49. snippet_content=multiline_input("Type your snippet (2 blank lines to submit):")
  50. tab_trigger=raw_input("Enter the tab trigger:\n")
  51. extension_type=remove_periods(raw_input("Enter the file extension this will apply to:\n"))
  52.  
  53. if extension_type == "md":
  54. extension_type="markdown"
  55. if extension_type == "py":
  56. extension_type="python"
  57. if extension_type == "sh":
  58. extension_type="shell"
  59.  
  60.  
  61. snippet_description=raw_input("Enter the description:\n")
  62.  
  63. output="""
  64. <snippet>
  65. <content><![CDATA[%s]]></content>
  66. <!-- Optional: Tab trigger to activate the snippet -->
  67. <tabTrigger>%s</tabTrigger>
  68. <!-- Optional: Scope the tab trigger will be active in -->
  69. <scope>source.%s</scope>
  70. <!-- Optional: Description to show in the menu -->
  71. <description>%s</description>
  72. </snippet>
  73. """ % (snippet_content, tab_trigger, extension_type,snippet_description)
  74.  
  75. if extension_type=="markdown":
  76. output="<scope>text.html".join(output.split("<scope>source"))
  77.  
  78. filename="/home/%s/.config/sublime-text-3/Packages/User/%s.%s.sublime-snippet" % (get_username(),random_string(),extension_type)
  79.  
  80. with open(filename,'w') as f:
  81. f.write(output)
  82. print("\ncreated: %s"%(filename))
  83.  
  84. print("\n%s\n"%(output))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement