Created
May 8, 2012 13:37
-
-
Save cockscomb/2635074 to your computer and use it in GitHub Desktop.
A plugin for Sublime Text 2. If the file you saved has no extension and start with shebang, this plugin make executable that file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sublime, sublime_plugin | |
import os, stat | |
class MakeExecutable(sublime_plugin.EventListener): | |
def on_post_save(self, view): | |
filename = view.file_name() | |
ext = os.path.splitext(filename)[1] | |
if not ext: | |
shebang = view.substr(sublime.Region(0, 2)) | |
if shebang == '#!': | |
mode = os.stat(filename)[stat.ST_MODE] | |
mode = mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH | |
os.chmod(filename, mode) | |
self.name = os.path.split(filename)[1] | |
sublime.set_timeout( | |
lambda: sublime.status_message( | |
"'{0}' is now executable.".format(self.name) | |
), | |
4000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment