VScode terminal shortcuts - command-line

In Visual Studio Code (Windows 10), how do I create shortcuts for certain commands in the terminal?
For example, if I have
javac -d ./bin *.java && java -cp ./bin test
I would like to just automatically execute that just by typing jrun(made up command) in the built-in terminal.

I ended up making a Windows batch script jrun.bat which contains javac -d ./bin *.java && java -cp ./bin test, so now I can just type jrun. I know there's a VsCode java extension, but I'm trying to do everything manually.

Related

How can I change the parameters passed to cmake during the "Build All Projects" command?

I am new to both vscode and cmake and I can't seem to find the settings that vscode uses when deciding what parameters to pass to cmake for the "build all projects" command, found in the context menu when right clicking a CMakeLists.txt file. In particular, the first time I compile (which fails) the parameters are different from the second time I compile (also fails). The first time I get:
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -Sc:/Users/Richard/source/repos/vmdevirt-vtil -Bc:/Users/Richard/source/repos/vmdevirt-vtil/build -G "Visual Studio 17 2022" -T host=x64 -A win32
and if there is already a build file from failed compilation:
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build c:/Users/Richard/source/repos/vmdevirt-vtil/build --config Debug --target vmdevirt-vtil -j 26 --
How can I select which options (preferably using a convenient preset like "MSVC x64 C++20" are passed to cmake using this command?
Thanks #Tsyvarev. Modifying CMake parameters can be done with Microsoft's own Cmake Tools extension using CMake: Select Variant and a number of CMake: * Preset options. The preset options will only be present if there is a valid CMakePresets.json file in the same directory as the base CMakeLists.txt file for the workspace.

Cannot run 'make' in VScode Terminal

For a school assignment, I am trying to compile a C file using a provided Makefile in Vscode. The makefile contains the following:
CFLAGS += -std=gnu11 -g
EXES = greet
all: $(EXES)
clean:
rm -f $(EXES)
greet: greet.c
# don't treat all and clean as file targets
.PHONY: all clean
When I run make in the VScode terminal, it gives me:
bash: make: command not found
Why is this happening? The assignment says this:
The accompanying Makefile will build the program greet. Thus, you can compile the
program by running make. The make program will print out each command that it uses to
compile the program. Note that if you run make twice in a row, the second time it won’t do
anything, because it knows your source file hasn’t changed.
Run the program using the following command:
./greet
I don't know if this has anything to do with my tasks.json file in VScode?
I also ran across this VSCode extension: https://naereen.github.io/Makefiles-support-for-VSCode/
It says Vscode now has something built-in: https://github.com/microsoft/vscode/tree/master/extensions/make
I don't know how to install this.

Visual Studio Code, autopep8 doesn't run

On Windows 10.
I did this:
pip install autopep8
and in vscode user settings I have
"python.linting.pep8Enabled": true,
"python.formatting.provider": "autopep8",
When I run format document, or explicitly invoke autopep8 from the command pallette, the error is:
Error: Command failed: autopep8 c:\tca-backend\lambdas\utilities\NetMenuAPIUtil.py
'autopep8' is not recognized as an internal or external command,
operable program or batch file.
Clearly, vsc wants to invoke autopep8.exe but there is no exe. Just py. So I created a autopep8.bat which works when I test from the command line, but when run from vsc, it inserts the content of the batch file into the top of the document. (Yes, that's as strange as it sounds.)
All other Python-related operations work ok, including the ESLint extension.
VS code Python extension supports source code formatting using either autopep8 (the default), black, or yapf so you don't need to install python formatting tools by yourself.
The way I use formatting is to set a shortcut in vs code.
Go to File -> Preferences -> Keyboard Shortcuts, then search format. Set the shortcut as ctrl + shift + p which is the same as the shortcut of autopep8 or you can set any combination you prefer.
Click the shortcuts in your .py files then you will get the formatted code.
Ref: https://code.visualstudio.com/docs/python/editing
Since you are using VSCode on Windows, please click on the Terminal Section and type
pip install pep8
This will start installing pep8.
for me, the autopep8 doc installation isn't enough, still seeing this error, I had to follow this https://pip.pypa.io/en/latest/user_guide/#user-installs. it works like a charm.
I'm on windows so I used this:
py -m pip install –-user autopep8
You need to add this as a PATH under System Environment Variables:
c:\users\<username>\appdata\roaming\python\python39\site-packages
Then close and restart VS Code. Type autopep8 at a terminal prompt and you should see this:
C:\Foobar>autopep8
usage: autopep8 [-h] [--version] [-v] [-d] [-i] [--global-config filename] [--ignore-local-config] [-r] [-j n] [-p n] [-a] [--experimental] [--exclude globs] [--list-fixes] [--ignore errors] [--select errors]
[--max-line-length n] [--line-range line line] [--hang-closing] [--exit-code]
[files ...]
autopep8: error: incorrect number of arguments
I encountered an error message while trying to do same and below was what I did (in my terminal):
Install or upgrade pep8:
pip install --upgrade autopep8
Navigate to the folder/directory where the file you need formatted is, then use the following command:
autopep8 --in-place file_name
There you have it!
I encountered this same error running WSL: Ubuntu-20.04, well this was my solution:
$ pip --version
This will make you verify that you have python3 pip installed correctly in your distribution, if that's not the case, it will pop up an error:
Command 'pip' not found, but can be installed with:
apt install python3-pip
Just run the indicated command to installed it and then after that, run:
$ python3 -m pip install autopep8
Now everything should be working as it should, including the formatting autpep8.

/bin/sh: mpic++ command not found in Eclipse for Parallel Application Developers

I'm trying to use Eclipse for Parallel Application Developers to do some MPI stuff but I can't get the program to compile. Below is the error I'm getting in the console:
Description Resource Path Location Type
/bin/sh: mpic++: command not found prog C/C++ Problem
I use mpic++ from the command line (bash shell) to successfully compile programs. When I run the command using bourne shell I get an error.
/bin/sh mpic++
/usr/local/bin/mpic++: /usr/local/bin/mpic++: cannot execute binary file
When I use sudo I still get the same error. But when I first change to the bourne shell then run the mpic++ command it works.
/bin/sh
sh-3.2$ mpic++
clang: error: no input files
I've been looking at ways to change the shell used by eclipse so I can use the bash shell because I can call mpic++ without any problems. I've also tried launching eclipse with sudo but that didn't work.
I have compiled mpi in eclipse successfully. Please follow the steps:
In terminal type:
$ which mpicxx
/usr/local/bin/mpicxx
You should get the mpicxx binary path as result. I have my mpicxx in /usr/local/bin/ directory.
In eclipse, go to project properties:
Set GCC C Compiler as: /usr/local/bin/mpicxx
Also set GCC C+ Compiler as: /usr/local/bin/mpicxx
Set MacOS X C++ Linker as: /usr/local/bin/mpicxx. Also set All options as -L/usr/local/lib

Does anyone know how to run the scala executable in Git Bash shell?

I have installed Scala on my Windows 7 system. When I run "scala -version" from the Windows command prompt, I get:
Scala code runner version 2.11.4 -- Copyright 2002-2013, LAMP/EPFL
When I run "scala -version" from a Git Bash shell, required by Swagger and other frameworks, I get:
Error: Could not find or load main class Files
Does anyone know how to run the scala executable from a Git Bash shell?
I'm guessing that you've installed Scala on C:\Program Files (x86) or C:\Program Files. As far as I can tell, git bash has problems reading the classpath if it has spaces and/or "()" in it.
If you're on a Win7 64-bit system, the easiest thing for you is:
Edit the system variables PATH
Find the scala\bin entry
Replace the C:\Program Files with Progra~1 or C:\Program Files (x86) with Progra~2
If you're not on a 64-bit system, (which I can't verify due to not having one), you'll have to do some escaping so that PATH isn't screwed up with the spaces and/or ().
EDIT: Here's a related SO but with Play instead: Play 2.0-RC3 -- Error: Could not find or load main class
Install scala with Coursier and run the scala.bat command from git bash terminal