bash permission denied on C++ build&run chain keybiding - linux

Through steps found:
Is it possible to chain key binding commands in sublime text 2?
Using the following Build System:
{
"cmd": ["g++", "$file", "-o", "${file_path}/${file_base_name}"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++, source.cxx, source.cpp",
"variants": [{
"name": "Run",
"shell": true,
"cmd": ["gnome-terminal -e 'bash -c \"${file_path}/${file_base_name};echo;read line;exit; exec bash\"'"]
}]
}
I created the following .py extension:
import sublime, sublime_plugin
class BuildAndRun(sublime_plugin.WindowCommand):
def run(self):
self.window.run_command("build")
self.window.run_command("build", {"variant": "Run"})
And keybiding:
{ "keys": ["ctrl+b"], "command": "build_and_run"},
The keybiding activates the extension correctly, but then in terminal it returns:
bash: /home/hadrian/Documents/new: Permission denied
'new' is the name of of .cpp file.
The problem is also that, if it only has (in the .py extension) build, it builds, if it only has run, it runs, but if it has both it returns that bash error.
I'm not being able to find out where this 'permission error' is created through the whole process.

Related

No Code output in sublime text 3, C++. I have tried the solution in previous posts

When there is no error in my code, I get this message in sublime
as you can see just build time but no output
I have added the mingW/bin folder to my path variable.
Here is my build system-
"shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\"",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",
"variants":
[
{
"name": "Run",
"shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\""
}
]
}
Do I need to make any changes to this? If yes, please let me know.
ALso when I press ctrl+b does it compile the entire .cpp file or does it only compile the current line?
Please help a fellow computer enthusiast out, I have looked it up on stack overflow, sublime forum but I cannot seem to find any answer out there.

How to run AStyle from inside Sublime?

I already tried using the SublimeAStyle Package, but it didn't work. When I pressed the keys, the command would not fire (I checked in the console). Now I am trying to write my own key-shortcut to run the program on my source code. I have this:
{ "keys": ["ctrl+alt+f"], "command": "exec", "args": { "cmd": ["C:\\Program Files\\AStyle\\bin\\astyle.exe", "${file_name}"]} }
but the ${file_name} is not expanding to pass the file name to the command. Is there anything I am doing wrong?

How to create Sublime Text 3 build system which reads shebang

How can I create a build system in Sublime Text 3 where "cmd" is replaced with a shebang if it exists?
More specifically, is there a way to alter the Python build system to use the version of Python specified in the shebang, and use a default if no shebang is present?
Sublime build systems have an option named target which specifies a WindowCommand that is to be invoked to perform the build. By default this is the internal exec command. You can create your own command that would examine the file for a shebang and use that interpreter or some default otherwise.
For example (caveat: I'm not super proficient in Python so this is probably quite ugly):
import sublime, sublime_plugin
class ShebangerCommand(sublime_plugin.WindowCommand):
def parseShebang (self, filename):
with open(filename, 'r') as handle:
shebang = handle.readline ().strip ().split (' ', 1)[0]
if shebang.startswith ("#!"):
return shebang[2:]
return None
def createExecDict(self, sourceDict):
current_file = self.window.active_view ().file_name()
args = dict (sourceDict)
interpreter = args.pop ("interpreter_default", "python")
exec_args = args.pop ("interpreter_args", ["-u"])
shebang = self.parseShebang (current_file)
args["shell_cmd"] = "{} {} \"{}\"".format (shebang or interpreter,
" ".join (exec_args),
current_file)
return args
def run(self, **kwargs):
self.window.run_command ("exec", self.createExecDict (kwargs))
You would save this in Packages/User as a python file (e.g. shebanger.py).
This creates a new command named shebanger that collects the arguments it's been given, examines the file in the currently active view of the window the build is triggered in to see if the first line is a shebang, and then synthesizes the arguments needed for the exec command and runs it.
Since the default python build system assumes it is building the current file and passing -u as an argument, that's what this command replicates as well. Note however that this code is not 100% correct because any arguments in the shebang line will be ignored, but you get the general idea.
In use, you would modify the default Python.sublime-build file to look like this:
{
// WindowCommand to execute for this build
"target": "shebanger",
// Use this when there is no shebang
"interpreter_default": "python",
// Args to pass to the interpreter
"interpreter_args": ["-u"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"env": {"PYTHONIOENCODING": "utf-8"},
"variants":
[
{
"name": "Syntax Check",
"interpreter_args": ["-m py_compile"],
}
]
}
Notice that in the variant we override what the interpreter arguments are; you could also override the default interpreter there as well if desired.
If think the only way to do this using a standard .sublime-build file is to pass your file to another script which then parses the shebang and passes it on to the correct Python version.
Alternatively, you could specify build variants, but then you will have to choose the desired build variant manually.
My python.sublime-build
{
"cmd": ["py", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"shell":true
}
In windows I used py launcher to detect the versions according to the shebang

"$file" variable nor working with exec command

I want to set a shortcut to open my current file using an external program (in my case, Visual Studio).
I thought I could use the $file variable, available in the build system. So it I write:
{ "keys": ["ctrl+o"], "command": "exec", "args": {"shell_cmd": "\"C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\Common7\\IDE\\devenv.exe\" $file"} }
I get in the Sublime console prompt:
Running "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe" $file
As you can see, the $file variable isn't expanded to the pull path of the open file. Does anyone know what's the problem here?
Working solution for (but for OS X) was to use it like this:
{ "keys": ["super+shift+option+o"], "command": "exec", "args": {"cmd": ["open", "-a", "ForkLift", ""]}}

Python 3.4 on Sublime Text 3

I followed these steps to run Python 3 on Sublime Text 3.
Select the menu Tools > Build > New Build System and I entered the following:
{
"cmd": ["python3", "$file"]
, "selector": "source.python"
, "file_regex": "file \"(...*?)\", line ([0-9]+)"
}
After that, I saved it to the following (Mac-specific) directory: ~/Library/Application Support/Sublime Text 3/Packages/User
but I'm getting this error when I'm trying to run my code on Python 3 in Sublime:
[Errno 2] No such file or directory: 'python3'
You need to provide the full path to python3, since Sublime Text does not read your ~/.bash_profile file. Open up Terminal, type which python3, and use that full path:
{
"cmd": ["path/to/python3", "$file"],
"selector": "source.python",
"file_regex": "file \"(...*?)\", line ([0-9]+)"
}
This is the snippet that I've been using. It's a slight variation to Andrew's solution, such that python3 is dynamically located by consulting the UNIX environment's PATH setting (not unlike how you would do the same inside a Python shell script; e.g.: '#! /usr/bin/env python3').
This snippet also uses "shell_cmd" instead of "cmd", which sublime-text-3 has seemingly switched to.
{
"shell_cmd": "/usr/bin/env python3 ${file}",
"selector": "source.python",
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"working_dir": "${file_path}",
}
I saved mine in ".../Packages/User/Python3.sublime-build". I hope this helps you. =:)
Thanks for your question. I began to learn python a couple days ago, and I am stuck with the same problem that you have met.Just as Andrew said above,it is “path problem”. I would like to share the code that I used to get python3 on sublime3.
For MacOS user:
{
"cmd": ["/usr/local/bin/python3", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"encoding": "utf8",
"path": "/usr/local/Frameworks/Python.framework/Versions/3.3/bin/"
}
and save the file as Python3.sublime-build.
I deeply recommended the book "A byte of python " for the new beginner of python.This book contributes a lot to my answer for this question.

Resources