Dan*_*eck 4 text-editing sublime-text-2 macos
在编写例如 shell 脚本时,我想从 Sublime Text 2 中更改它们的权限(主要是可执行权限)。
我怎样才能做到这一点?
以下是当前正在编辑的文件的通用权限编辑命令。有关插件和编辑 Sublime Text 2 菜单的更详细说明,请参阅此帖子。
它将在编辑菜单中添加一个更改模式命令。当被选中时,用户被要求输入一个有效的参数字符串到 chmod(例如或;默认是当前设置的 4 位八进制权限字符串,如),然后将其应用于正在编辑的文件。u+rwx7550644

选择工具»新的插件,将下面的内容,并保存为chmod.py在~/Application Support/Sublime Text 2/Packages/User/:
import sublime, sublime_plugin, subprocess
def chmod(v, e, permissions):
subprocess.call( [ "chmod", permissions, v.file_name() ] )
def stat(filename):
proc = subprocess.Popen( [ "stat", "-f", '%Mp%Lp', filename ], stdout=subprocess.PIPE )
return str(proc.communicate()[0]).strip()
class ChangeModeCommand(sublime_plugin.TextCommand):
def run(self, edit):
if sublime.platform() != 'osx':
return
fname = self.view.file_name()
if fname == None:
sublime.message_dialog("You need to save this buffer first!")
return
perms = stat(fname)
def done(permissions):
chmod(self.view, edit, permissions)
sublime.active_window().show_input_panel(
"permissions to apply to the file " + fname + ": ", perms, done, None, None)
Run Code Online (Sandbox Code Playgroud)
要为此命令插入菜单项,请将以下~/Application Support/Sublime Text 2/Packages/User/Main.sublime-menu内容添加到 中,如果文件已存在,则与现有文件内容合并:
[
{
"id": "edit",
"children":
[
{"id": "wrap"},
{ "command": "change_mode" }
]
}
]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1660 次 |
| 最近记录: |