Skip to content

Instantly share code, notes, and snippets.

@7osema
Forked from jordan-brough/instructions.markdown
Created June 20, 2016 08:27
Show Gist options
  • Save 7osema/c8dcdcb1b6e49b40f630910529e09360 to your computer and use it in GitHub Desktop.
Save 7osema/c8dcdcb1b6e49b40f630910529e09360 to your computer and use it in GitHub Desktop.
Splunk-friendly timestamp plugin snippet for Sublime Text 2
  1. Choose: Tools > New Plugin

  2. Paste in the contents of "timestamp.py" below

  3. Save as timestamp.py in ~/Library/Application Support/Sublime Text 2/Packages/User/ (should be the default directory that pops up when you save)

  4. Choose: Sublime Text 2 > Preferences > Key Bindings - User

  5. Add:

    { "keys": ["super+ctrl+t"], "command": "timestamp" }

To make command+ctrl+t perform the insertion.
Make sure to add a comma after the previous keymap entry, if present.

import sublime, sublime_plugin
from datetime import datetime
class TimestampCommand(sublime_plugin.TextCommand):
def run(self, edit):
stamp = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ ")
for r in self.view.sel():
if r.empty():
self.view.insert (edit, r.a, stamp)
else:
self.view.replace(edit, r, stamp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment