Skip to content

Instantly share code, notes, and snippets.

@christiangenco
Created October 10, 2020 18:47
Show Gist options
  • Save christiangenco/351feaef344b8695a69a532bb43e0d4e to your computer and use it in GitHub Desktop.
Save christiangenco/351feaef344b8695a69a532bb43e0d4e to your computer and use it in GitHub Desktop.
Sublime Text 3 plugin to run a terminal command based on the contents of the line that the cursor is on
import sublime
import sublime_plugin
import re
import os
class OpenJournalReferencedOnThisLineCommand(sublime_plugin.TextCommand):
def run(self, edit):
region = self.view.sel()[0]
line_range = self.view.line(region)
line = self.view.substr(line_range)
match = re.findall(r"\d{4}-\d{2}-\d{2}", line)
# sublime.Window.open_file("/Users/cgenco/brain/journal/2020/10/2020-10-09.md")
if len(match) > 0:
date = match[0]
res = os.system("/Users/cgenco/utils/,journal " + date)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment