sublime text 是一個(gè)跨平臺(tái)的文本編輯工具正卧,用了下還是比較方便。
安裝后跪解,除了默認(rèn)的語(yǔ)法支持外炉旷,如果想找下額外的功能,可以通過(guò)安裝插件的方法來(lái)做叉讥。
快捷鍵 Ctrl+Shift+p 敲入install 可以看到已發(fā)布的插件列表窘行。根據(jù)自己情況選擇需要的插件。
但是有的時(shí)候图仓,找不到自己想要的插件罐盔,那么只有自己編寫了。
自己編寫插件必備條件:
1透绩、會(huì)基本python腳本語(yǔ)言
2翘骂、了解sublime text插件的api,這個(gè)通過(guò)官方文檔查看
http://www.sublimetext.com/docs/3/
3帚豪、了解創(chuàng)建插件的過(guò)程碳竟,可以通過(guò)這個(gè)地址了解:
https://code.tutsplus.com/tutorials/how-to-create-a-sublime-text-2-plugin--net-22685
我寫了個(gè)一個(gè)簡(jiǎn)單的sftp上傳的插件:
pscp.exe 可以到網(wǎng)上下一個(gè):
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
目錄結(jié)構(gòu):
example/example.py
example/bin/pscp.exe
example.py代碼如下
import sublime
import sublime_plugin
import os
import sys
import re
bin_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'bin')
has_bin = os.path.exists(bin_folder)
pscp_exe = os.path.join(bin_folder, 'pscp.exe')
has_psftp = os.path.exists(pscp_exe)
remote_ip = '1.1.1.1' # replace your ip
remote_ssh_password = 'you_password' # replace your you_password
pscp_exe_cmd = "\"" + pscp_exe + "\" -pw \"" + remote_ssh_password + "\" \"%s\" root@" + remote_ip + ":\"%s\" "
base_path = "D:\\svn\\project1\\" # repalce you base path
remote_path = "/data/project1/" # repalce you remote path
def get_relative_path(full_path,base_path):
full_path = re.sub(r"\\", "/", full_path)
base_path = re.sub(r"\\", "/", base_path)
if (re.match(base_path, full_path, re.I)):
relative_path = re.sub(base_path, "", full_path, re.I)
return relative_path
else:
return ""
class ExampleCommand(sublime_plugin.TextCommand):
def run(self, edit):
if os.name == 'nt' and (not has_bin or not has_psftp):
sublime.error_message("sftp plugin is invalid")
else:
file_path = self.view.file_name()
relative_path = get_relative_path(file_path,base_path)
remote_file_path = remote_path + relative_path
if (relative_path == ""):
sublime.error_message("can not sftp to server, due to file not in base_path")
else:
cmd = pscp_exe_cmd % (file_path,remote_file_path)
ret = os.popen(cmd)
output = ret.read()
if re.search(r'100%',output):
msg = relative_path+" upload success!"
else:
msg = relative_path+" upload failed"
sublime.message_dialog(msg)