PK P4=kh Default.sublime-keymap
PK P4=5SVZ Z MercurialCommand.pyimport sublime, sublimeplugin
import subprocess
import os
# This plugin provides access to frequently used Mercurial commands
#
# To use this plugin, Mercurial must be in your path.
# To verify this, open a command prompt and type 'hg'
# If you get a list of commands, it's on the path, otherwise, add it to the path
#
# You may obtain Mercurial at: http://mercurial.selenic.com/wiki/
class MercurialCommand(sublimeplugin.TextCommand):
def run(self, view, args):
# don't operate unless the buffer is saved
if(view.fileName() == None):
return
# Put the file name in quotes to allow spaces in the name
bufferName = "\"" + str(view.fileName()) + "\""
# Parse the arguments
if(args[0]=="commit"):
Results = doSystemCommand("hg commit")
displayResults(Results, "MessageBox", None)
elif(args[0]=="addCurrent"):
Results = doSystemCommand("hg add " + bufferName)
displayResults(Results, "MessageBox", None)
elif(args[0]=="initCurrent"):
Results = doSystemCommand("hg init")
displayResults(Results, "MessageBox", None)
elif(args[0]=="removeCurrent"):
Results = doSystemCommand("hg remove " + bufferName)
displayResults(Results, "MessageBox", None)
elif(args[0]=="diff"):
Results = doSystemCommand("hg diff " + bufferName)
displayResults(Results, "Window", view)
elif(args[0]=="push"):
Results = doSystemCommand("hg push ")
displayResults(Results, "MessageBox", None)
elif(args[0]=="pull"):
Results = doSystemCommand("hg pull")
displayResults(Results, "MessageBox", None)
elif(args[0]=="update"):
Results = doSystemCommand("hg update")
displayResults(Results, "MessageBox", None)
elif(args[0]=="pullAndUpdate"):
Results = doSystemCommand("hg pull -u ")
displayResults(Results, "Window", view)
elif(args[0]=="revert"):
Results = doSystemCommand("hg revert " + str(bufferName))
displayResults(Results, "Window", view)
elif(args[0]=="status"):
Results = doSystemCommand("hg status")
displayResults(Results, "Window", view)
# Runs a system command from the command line
# Captures and returns both stdout and stderr as an array, in that respective order
def doSystemCommand(commandText):
p = subprocess.Popen(commandText, shell=True, bufsize=1024, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p.wait()
stdout = p.stdout
stderr = p.stderr
return [stdout.read(),stderr.read()]
# Displays given stderr if its not blank, otherwise displays stdout
# Method of display is configured using the Mode argument
#
# Results is of the form
# Results[0] is stdout to display
# Results[1] is stderr which, if its not None, will be displayed instead of stdout
#
# Modes:
# Window - Opens a new buffer with output
# MessageBox - Creates a messageBox with output
#
# view is the view that will be used to create new buffers
def displayResults(Results, Mode, view):
if(Mode == "Window"):
if(Results[1] != None and Results[1] != ""):
createWindowWithText(view, "An error or warning occurred:\n\n" + str(Results[1]))
elif(Results[0] != None and Results[0] != ""):
createWindowWithText(view, str(Results[0]))
# Message Box
elif(Mode == "MessageBox"):
if(Results[1] != None and Results != ""):
sublime.messageBox("An error or warning occurred:\n\n" + str(Results[1]))
elif(Results[0] != None and Results[0] != ""):
sublime.statusMessage(str(Results[0]))
# Open a new buffer containing the given text
def createWindowWithText(view, textToDisplay):
MercurialView = sublime.Window.newFile(view.window())
MercurialView.insert(MercurialView.size(), textToDisplay)PK P4=Qx
README.txtThis plugin is designed to provide an integrated interface to the most commonly used features of Mercurial.
# Easy Installation
Find the Mercurial package on http://sublimetextwiki.com, download it, and double click-it.
Sublime Text should recognize and install it.
After you double click it, restart Sublime Text.
This will give you keybindings for Commit, Add, Remove, and Diff actions.
# Manual Installation
Copy the "MercurialCommand.py" and "MercurialCommand.package-menu" files to your Packages\User folder:
- On Vista, this is \Users\UserName\AppData\Roaming\Sublime Text\Packages\User\
- On XP, this is \Documents and Settings\UserName\Application Data\Sublime Text\Packages\User\
Optionally, alter your "Default.sublime-keymap" file and create any shortcuts you wish. Some examples are provided with the plugin.
# Usage
There is a pull-down menu under Tools->Packages->Mercurial that provides access to all the commands provided by the plugin.
You may also map any of the Mercurial commands to a keystroke and use them in that way.
A thing to note is that this command uses the currently open buffer to determine the file path where the commands should be run from.
# Notes
When using the revert command, you must change to another open buffer or close
and reopen the buffer in question. This is because Sublime Text needs to realize
that the file has been modified outside the editor so it can be reloaded.PK P4=%$m m MercurialCommand.package-menu
PK P4=kh Default.sublime-keymapPK P4=5SVZ Z M MercurialCommand.pyPK P4=Qx
README.txtPK P4=%$m m MercurialCommand.package-menuPK Y