#! /usr/bin/env python3 # -*- coding: utf-8; mode: python -*- """ Tiny SublimeText3 plugin to add this command: 'send_sms' - It sends the content of the current file to my phone, using https://bitbucket.org/lbesson/bin/src/master/FreeSMS.py (must be accessible in your $PATH) - It is NOT binded to any key 'send_selected_sms' - It sends the selected text to my phone, using https://bitbucket.org/lbesson/bin/src/master/FreeSMS.py (must be accessible in your $PATH) - It is NOT binded to any key About: - *Date:* 2016-10-27 - *Version:* 0.0.1 - *Web:* http://perso.crans.org/besson/publis/ST3/ - *Author:* Lilian Besson (C) 2016 - *Licence:* MIT Licence (http://lbesson.mit-license.org) """ import sublime import sublime_plugin from subprocess import Popen class SendSmsCommand(sublime_plugin.TextCommand): def run(self, edit): if self.view.file_name(): filename = self.view.file_name() print("Sending current saved file {} to your phone ...".format(filename)) # Set status message self.view.window().status_message("Sending current saved file {} to your phone ...".format(filename)) # Send a notification Popen([ "/usr/bin/env", "/usr/bin/notify-send", "--icon", "/opt/sublime_text/Icon/256x256/sublime-text.png", # icon "Sublime Text 3 - FreeSMS.py", # title "Sending the content of the file '{}' to your phone, from Sublime Text 3 (command 'send_sms')".format(filename), # body ]) # Send the file Popen([ "/usr/bin/env", "FreeSMS.py", "-f", filename ]) else: print("Sending current non-saved text of visible region to your phone ...") content = self.view.substr(self.view.visible_region()) print(content) # Set status message self.view.window().status_message("Sending current non-saved text of visible region to your phone ...") # Send a notification Popen([ "/usr/bin/env", "/usr/bin/notify-send", "--icon", "/opt/sublime_text/Icon/256x256/sublime-text.png", # icon "Sublime Text 3 - FreeSMS.py", # title "Sending the content of the non-saved text of visible region to your phone, from Sublime Text 3 (command 'send_sms')", # body ]) # Send the file Popen([ "/usr/bin/env", "FreeSMS.py", content ]) class SendSelectedSmsCommand(sublime_plugin.TextCommand): def run(self, edit): # content = self.view.substr(self.view.window().active_view().sel()[0]) contents = '\n'.join( self.view.substr(s) for s in self.view.window().active_view().sel() ) print("Sending this selection to your phone ...") print(contents) # Set status message self.view.window().status_message("Sending this selection to your phone ...") # Send a notification Popen([ "/usr/bin/env", "/usr/bin/notify-send", "--icon", "/opt/sublime_text/Icon/256x256/sublime-text.png", # icon "Sublime Text 3 - FreeSMS.py", # title "Sending the content of this selection to your phone, from Sublime Text 3 (command 'send_sms')", # body ]) # Send the file Popen([ "/usr/bin/env", "FreeSMS.py", contents ])