Home Download Buy Blog Forum Support

Open Command Window Here

Open Command Window Here

Postby atomi on Sun Sep 25, 2011 8:14 pm

Does anyone know if anything been added to the API that allows a plugin to grab the current path triggered from a sidebar folder right click context menu entry?

I'd like to be able to right click a folder and "Open Command Window Here" type thing.
atomi
 
Posts: 342
Joined: Thu Jan 20, 2011 5:06 pm
Location: Los Angeles CA US

Re: Open Command Window Here

Postby jbrooksuk on Mon Sep 26, 2011 4:21 pm

Windows only :)

Make a new folder in your plugin directory, create a new file called opencommand.py and put this code in it:

Code: Select all
import sublime, sublime_plugin
import subprocess

class OpenPromptCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        dire = os.path.dirname(self.view.file_name())
        retcode = subprocess.Popen(["cmd", "/K", "cd", dire])

    def is_enabled(self):
        return self.view.file_name() and len(self.view.file_name()) > 0

Now create another file called "Content.sublime-menu" and put the following in it:
Code: Select all
[
    { "caption": "-", "id": "file" },
    { "command": "open_prompt", "caption": "Open Command Window Here…" }
]

Now when you right click and click "Open Command Window Here.." you'll get a new command prompt at the location of the file you were editing.
jbrooksuk
 
Posts: 689
Joined: Sun Apr 11, 2010 10:37 am
Location: England

Re: Open Command Window Here

Postby jbrooksuk on Mon Sep 26, 2011 4:27 pm

Oh, sorry, I see you wanted this from the sidebar... Just change "Context" to "Sidebar" in the filename.
jbrooksuk
 
Posts: 689
Joined: Sun Apr 11, 2010 10:37 am
Location: England

Re: Open Command Window Here

Postby atomi on Mon Sep 26, 2011 7:40 pm

Saved me some time with this. Thanks!
atomi
 
Posts: 342
Joined: Thu Jan 20, 2011 5:06 pm
Location: Los Angeles CA US

Re: Open Command Window Here

Postby ChadW on Mon Sep 26, 2011 9:25 pm

Hmm, I can't seem to get the Popen command to work on my setup (XP64, dev2122). The item shows up in the context menu enabled, but doesn't seem to act in any way.

I've dickered with the Popen command, but I admit little facility with Python libraries. Any ideas what the call might be fragile on?
ChadW
 
Posts: 21
Joined: Fri Sep 23, 2011 7:45 pm

Re: Open Command Window Here

Postby atomi on Mon Sep 26, 2011 11:44 pm

Yup. Try adding the import os.

Code: Select all
import sublime, sublime_plugin, subprocess, os


The problem with loading this from the sidebar is that the working directory is set using self.view.file_name().
What I wanted was a way to use the folder I right clicked on as the current working directory for the command prompt.
atomi
 
Posts: 342
Joined: Thu Jan 20, 2011 5:06 pm
Location: Los Angeles CA US

Re: Open Command Window Here

Postby jbrooksuk on Tue Sep 27, 2011 8:06 am

atomi wrote:The problem with loading this from the sidebar is that the working directory is set using self.view.file_name().
What I wanted was a way to use the folder I right clicked on as the current working directory for the command prompt.

I see...

Well the sidebar can pass arguments through I believe, so I'll have a play :)
jbrooksuk
 
Posts: 689
Joined: Sun Apr 11, 2010 10:37 am
Location: England

Re: Open Command Window Here

Postby ChadW on Tue Sep 27, 2011 5:34 pm

Ah ha, yes, there it is. Thanks, works like a charm now!
ChadW
 
Posts: 21
Joined: Fri Sep 23, 2011 7:45 pm

Re: Open Command Window Here

Postby atomi on Tue Sep 27, 2011 8:15 pm

jbrooksuk wrote:
atomi wrote:The problem with loading this from the sidebar is that the working directory is set using self.view.file_name().
What I wanted was a way to use the folder I right clicked on as the current working directory for the command prompt.

I see...

Well the sidebar can pass arguments through I believe, so I'll have a play :)


Yeah that was what was hanging me up.

I see

Code: Select all
{ "caption": "Delete Folder", "command": "delete_folder", "args": {"dirs": []} },


in the Default\Side Bar.sublime-menu but when I add "args" to my Side Bar entry I get this in the console:

Code: Select all
Traceback (most recent call last):
  File ".\sublime_plugin.py", line 276, in run_
TypeError: run() got an unexpected keyword argument 'dirs'
atomi
 
Posts: 342
Joined: Thu Jan 20, 2011 5:06 pm
Location: Los Angeles CA US

Re: Open Command Window Here

Postby wbond on Wed Sep 28, 2011 12:30 pm

Sublime Terminal does what you are looking for, and works cross-platform too: http://wbond.net/sublime_packages/terminal

You can right click on any folder, and also use ctrl+shift+t to open a terminal/command prompt at the folder of the current file, or ctrl+shift+alt+t to open at the project folder the current file is in.
wbond
 
Posts: 493
Joined: Mon Feb 28, 2011 5:33 am

Next

Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 2 guests

cron