Is there a way to create a build command in Sublime Text that opens a new external window (terminal/cmd.exe)? Everything I try gets captured to the built-in output window.
I tried:
{
"cmd": ["ruby", "$file"],
"target": "cmd.exe",
"file_regex": "rb$",
"selector": "source.rb"
}
But nothing happened
The following works for Windows (I've tested it on XP and 7):
{
"cmd": ["start", "cmd", "/k", "c:/ruby193/ruby.exe", "$file"],
"selector": "source.ruby",
"shell": true,
"working_dir": "$file_dir"
}
Save it as Packages/User/Ruby_cmd.sublime-build (you may need to alter the path to the Ruby executable depending on your system), select Tools -> Build System -> Ruby_cmd, and build with CtrlB.
start does what it says it does, start a new process independent of Sublime Text. cmd is cmd.exe, the Windows command-line interpreter. The /k flag keeps the window open (at a new command prompt) after your program has run, allowing you to examine its output, look at tracebacks, run additional commands, etc.
May be you will find this solution helpful:
https://github.com/rctay/sublime-text-2-buildview
(transfers build output in the separate sublime tab, you can then do with it whatever you want)
Related
New Windows Terminal (Windows Terminal (Preview) Version: 0.2.1831.0) have settings in JSON file. How can I setup powershell running with Anaconda?
Anaconda running in powershell with:
%windir%\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy ByPass -NoExit -Command "& 'C:\Users\akali\Anaconda3\shell\condabin\conda-hook.ps1' ; conda activate 'C:\Users\akali\Anaconda3' "
Windows Terminal use profiles in JSON like this:
"profiles": [{
"colorScheme": "Solarized Light",
"commandline": "powershell.exe"
}]
How can I use running with Args with double quote in JSON that allow me run something like -Command "& 'C:\'"?
I realize I'm late of some years but I had a similar problem and stranded up here looking for an answer. So, I'm hoping that this is useful for people like me in the future.
After some time tinkering I generated an Anaconda profile:
copy paste an existing profile
generate guid here
open C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Anaconda3 (64-bit)
right click on Anaconda Powershell Prompt (Miniconda3) and go to Properties
copy the entire content of the target field and paste it on the field commandline (make sure the field is commandline and not source)
escape all the \ characters (\ --> \\)
Change the name field
You should have something like this
{
"guid": "{generated guid}",
"hidden": false,
"name": "Anaconda",
"commandline": "powershell.exe -ExecutionPolicy ByPass -NoExit -Command & 'C:\\ProgramData\\Miniconda3\\shell\\condabin\\conda-hook.ps1' ; conda activate 'C:\\ProgramData\\Miniconda3'"
},
As a nice sidenote, you can also create a profile to directly launch an Ipython session or a jupyter notebook.
As you may have noticed, lo launch anaconda in the commandline field we are just launching powershell.exe, and then telling the powershell instance to execute a -Command, which is the subsequent string.
Were you to add a ; ipython to the command, you would launch an ipython session.
Copy-paste the settings for cmd from above.
Go to "C:\Users\Username\AppData\Roaming\Microsoft\Windows\Start
Menu\Programs\Anaconda3 (64-bit)"
Right-click on "Anaconda Prompt (Anaconda3)"
Copy the content from the target field and paste it on the field commandline
Mine is %windir%\System32\cmd.exe "/K" C:\bin\Anaconda3\Scripts\activate.bat C:\bin\Anaconda3
Replace \ with \
Thanks to the above answer by Marco Necci, this is a more clear version with cmd and anaconda
"commandline" : "%windir%\\System32\\cmd.exe /K C:\\bin\\Anaconda3\\Scripts\\activate.bat C:\\bin\\Anaconda3"
Building upon Navaneeth M et al, I contribute a command line which includes the default Anaconda location using USERPROFILE environment variable, specifying non-default Anaconda env (fastai), starting directory and color scheme.
"commandline": "%windir%\\System32\\cmd.exe /K %USERPROFILE%\\Anaconda3\\Scripts\\activate.bat fastai",
"colorscheme": "Solarized Light",
"startingDirectory": "c:\\sw",
Pro Tip: Use keybindings to add a hotkey which opens a new tab in the specified project directory. For example, use ctrl-b to open a new Anaconda tab in just the right place.
"keybindings": [
{
"keys": [ "ctrl+b" ],
"command": {
"action": "newTab",
"profile": "Anaconda",
"startingDirectory": "c:\\sw\\myproject\\myprojectdirectory"
}
}
]
Right click properties of conda powershell shortcut (in desktop or start menu). There you get the path to the command that effectively starts conda using powershell.
Now, just follow the recipe of Marco Necci outlined above, just caring to put double backslashes instead of single ones.
Searching further modifications, in this site i've found that i could generate the new needed guid with powershell itself: [guid]::NewGuid().
And in the repo of new terminal, i've discovered it's possible to customize the icon too. My icon was in a different path, that i came across looking in anaconda shortcut in windows menu (i used anaconda navigator's icon - right click it > more > open; somewhere ending with 'Start Menu\Programs\Anaconda3 (64-bit)': right click once more in the shortcut > properties; change icon - there is the path to the icon).
Again, be wary to use double backslashes instead of single ones.
Why is this Sublime Text Grunt Build failing in Windows 7?
{
"cmd": ["grunt.cmd", "--no-color"],
"path": "C:\\Users\\USER\\AppData\\Roaming\\npm;C:\\Program/ Files\\nodejs",
"working_dir": "${project_path}"
}
Console says:
'node' is not recognized as an internal or external command, operable program or batch file.
[Finished in 0.1s with exit code 1]
Try the following first:
{
"cmd": ["grunt.cmd", "--no-color"],
"path": "C:/Users/USER/AppData/Roaming/npm;C:/Program\ Files/nodejs",
"working_dir": "${project_path}"
}
If that doesn't work, try removing the \ character between Program and Files. You don't need the "selector" argument at all, as that is used to specify the scope for the build system. ["Gruntfile.js"] is not a valid scope.
As an alternative option, check out the Grunt plugin available via Package Control. I haven't used it myself, but it looks quite useful. It parses your Gruntfile.(js|coffee) file and adds the available tasks to the Command Palette, among other things. It directly reads your PATH variable, so as long as your node and npm directories are there, it should work quite well.
I am using Octave for some Machine Learning work and I have noticed in my package library in Sublime that there is SublimeREPL: Octave as an option.
However when I select it, I get the following error message:
FileNotFoundError(2, "No such file or directory: octave")
Is there a way to use sublime to code with Octave?
Many thanks
First, you need to find out where your octave executable lives, and note the full path to it. On Linux or OS X, open your favorite terminal emulator and type which octave, and if it's in your $PATH variable it will print the full path to it (for example, /opt/local/bin/octave or something like that). If it's not in your path, or if you're on Windows, you'll have to search around a bit until you find octave or octave.exe, if you're on Windows.
Once you have the path, open Sublime and select Preferences -> Browse Packages..., which will open your Packages folder (surprisingly). Navigate to Packages/SublimeREPL/config/Octave and open the Main.sublime-menu file in Sublime - don't worry, it's just plain JSON. Go down to line 18 (or thereabouts) - it should say "cmd": ["octave", "-i"],. Change "octave" to "/full/path/to/octave", obviously replacing /full/path/to/ with the actual full path you noted earlier.
Save the file, and you should be all set. Tools -> SublimeREPL -> Octave should now open up an interactive session, just like running octave -i on the command line would do. You can use all of the usual SublimeREPL shortcuts to send code to the running REPL, or just use if for testing functions, code snippets, etc.
Have fun!
I am using Sublime Text 3 on OS X
Octave programs are running perfectly. So you can try the below mentioned steps
Open Sublime
Goto Tools --> Build System --> New Build System...
Paste this code
{
"cmd": ["/usr/local/octave/3.8.0/bin/octave-3.8.0", "$file"],
"selector": "source.m"
}
Save it as Octave.sublime-build
Now use Octave as your build system
Use ⌘ + B to run your code.
Enjoy!
I'm struggling to successfully build a HTML build system in Sublime Text 2. I am running Windows 7.
This is the code for my build system:
{
"cmd": ["open", "-a", "Google Chrome", "$file"]
}
This is the error I recieve when I try and build a html file:
[WinError 2] The system cannot find the file specified
[cmd: ['open', '-a', 'Google Chrome', 'C:\\Users\\Soham\\Desktop\\hello.html']]
[dir: C:\Users\Soham\Desktop]
[path: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem]
[Finished]
I have no idea why this error is ocurring and have searched the web for an explanation.
Any help will be much appreciated!
Thanks in advance!
The open command is only available on OSX systems. You have two options - you can use Sublime's built-in "Open in Browser" functionality by right-clicking in any open HTML file and selecting Open in Browser, or you can modify your build system to just point to the correct location of chrome.exe:
"cmd": [ "C:\\Users\\YourUserName\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe", "$file"]
replacing YourUserName with the correct value, and ensuring that this actually is the location of chrome.exe on your system.
If you are using Chrome with Windows 7, you could run successfully the following:
{
"cmd": ["C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe", "$file"]
}
I've had this problem for ages, and it's SO ANNOYING.
Suppose I want to run mysqldump.exe... here's my process: Start->run, type "cmd" ... dir into directory after directory until I finally get to c:/program files/mysql/bin/then I can FINALLY call "mysqldump.exe"
I don't mind using Windows Explorer to get to c:/program files/mysql/bin, but then I can't freaking open up any of the .exe files in a shell, and I can't open up shell with the directory being that one.
How can I do this?
This is what I do for those type of commands:
Drag a copy of the "Command Prompt" shortcut onto your desktop.
Open the properties of the shortcut.
Change the Target: field to: %SystemRoot%\system32\cmd.exe /k mysqldump.exe
Change the Start in: field to: c:/program files/mysql/bin/
Hit Ok, then rename the short cut from "Command Prompt" to "Mysqldump".
Then just double click the icon whenever you need that command. The "/k" option for cmd.exe leaves the window open.
Microsoft released a powertoy for Windows XP called Open Command Prompt Here. If you're using Vista, all you need to do is hold shift and right-click.
here's my process: Start->run, type
"cmd" ... dir into directory after
directory until I finally get to
c:/program files/mysql/bin/ then I can
FINALLY call "mysqldump.exe"
Why not just the following?
c:
cd "c:/program files/mysql/bin"
mysqldump.exe
Better yet, put this in a batch file and execute it.
You can also create a shortcut for cmd.exe and set the "Start in" directory to "c:/program files/mysql/bin".
You can download an add-in so that you can right click on the folder and open a command prompt. Saves a lot of time and you say you dont mind navigating to the location.
http://download.microsoft.com/download/whistler/Install/2/WXP/EN-US/CmdHerePowertoySetup.exe
A nice little trick is that the icon in the adress bar of explorer could be dragged to a command line window and it insert the full path at your current cursor position.
It doesn't work in vista but if you SHIFT-RightClick on a folder you have an "Open Command Windows Here" option that appears.
Under xp you could have it by saving this as a .reg and executing it :
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\cmd]
#="Open Command Prompt Here"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\cmd\command]
#="cmd.exe /k pushd %L"
Just use the explorer to navigate to the bin or any directory. then enter cmd at the address bar und hit return. the command line with start at this location.
You can do it with python:
If you don't have activepython already, download from ActiveState's Website. Next, run PythonWin and create a new script. Write the following:
from subprocess import *
Call("c://program files//mysql//bin//mysqldump.exe")
Save the script somewhere. When you want to run it, just doubleclick. There are easier ways if you like writing batch files, but Python is more succinct than even windows for this case.
Just put c:/program files/mysql/bin/ into your path...
Then you can run mysqldump.exe directly without even opening a cmd prompt by typing it into " Start > Run "
I was using the MS PowerToy for a while but moved on to the open source Open Command Prompt Shell Extension because of the key feature:
(copied verbatim from the website)
The ability to open a command prompt in the directory that you are currently in by right-clicking on any empty screen space in the directory. This eliminates the need to navigate up a level in order to open a command prompt in the current directory.
Having to actually click on a folder to open the command prompt using the MS tool was a annoyance for me... especially since I always need to run command line tools on my current directory at the time.