Alacritty: run a startup script? - alacritty

I'm on Windows 10 and trying to run a startup script (vcvars64.bat) to setup the MSVC compiler before using the Alacritty prompt.
I have tried the -e switch with the command and also with the alacritty.yml shell: option, but both options open Alacritty, run the command, then exit.
How do I run a script on startup as the first command then continue into Alacritty?
Thanks,
Matic

What I ended up with is:
Specify program: cmd.exe in Alacritty alacritty.yml:
shell:
program: cmd.exe
Create a shortcut to Alacritty.exe and place it eg. in C:\ProgramData\Microsoft\Windows\Start Menu\Programs\ (so that it shows up in Windows search).
In properties for the shortcut, under target, specify:
"C:\Program Files\Alacritty\alacritty.exe" --command "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat >/NUL" && bash.exe
Modify Visual Studio path to whatever you have, and which varsall.bat you want to use.
The tricky part was how sensitive cmd.exe is regarding quotes. Eg., it does not work for me to specify an absolute path to which bash.exe to use, it would fail on the first whitespace in the path no matter how I tried to quote it. So make sure the correct bash.exe is first in your PATH (open plain cmd.exe and run where bash.exe to see order). Another solution is of course to create a shortcut to the bash.exe of your liking to a place without spaces in its path then specify it's absolute path (tested to work).

Related

Change directory in Node.js command prompt

I want to move to another directory in Node.js command prompt but when I open the Node.js cmd window it doesn't show me any path. Here is the screenshot of the Node.js cmd window:
Now if i want to change directory to D:\abc then how can i do it here?
That isn't the Node.js command prompt window. That is a language shell to run JavaScript commands, also known as a REPL.
In Windows, there should be a Node.js command prompt in your Start menu or start screen:
Which will open a command prompt window that looks like this:
From there you can switch directories using the cd command.
To switch to the another directory
process.chdir("../");
If you mean to change default directory for "Node.js command prompt", when you launch it, then (Windows case)
go the directory where NodeJS was installed
find file nodevars.bat
open it with editor as administrator
change the default path in the row which looks like
if "%CD%\"=="%~dp0" cd /d "%HOMEDRIVE%%HOMEPATH%"
with your path. It could be for example
if "%CD%\"=="%~dp0" cd /d "c://MyDirectory/"
if you mean to change directory once when you launched "Node.js command prompt", then execute the following command in the Node.js command prompt:
cd c:/MyDirectory/
Add the \d [dir] attribute to the cd command like this:
cd \d %yourdir%:\
Open file nodevars.bat
Just add your path to the end,
"%HOMEDRIVE%%HOMEPATH% /file1/file2/file3
Save file nodevars.bat
This work even with Swedish words
Type .exit in command prompt window, It terminates the node repl.
.help will show you all the options.
Do .exit in this case

Run Perl script in Linux environment

I'm trying to run code on Linux environment
Here's the code (saved as hello.pl):
#!/usr/bin/perl
use strict;
use warnings;
print "Hello You\n";
Here's what I tried on my linux environment:
%perl hello.pl
I tried listing out the path starting from C:\Users\... and so on
I keep getting error that says:
Can't open perl script "hello.pl": No such file or directory
You have to be located in the same folder with the hello.pl in the "window" (aka terminal, or console) that you try to execute perl hello.pl.
On linux, you can determine the folder that you're in by issuing pwd.
If you're not in the same folder (the most probable cause of your error), you have 2 options:
Navigate to that folder with cd /path/to/your/script/location you have to replace the /path/to/your/script/location in the example, with your actual path
Execute the file with perl /path/to/hello.pl - of course, you have to replace the /path/to/ in the example, with your ac
Also, you can try and view the file from the console running a less hello.pl
In cygwin you might try: /cygdrive/c/Users/bonan/Desktop/perl/hello.pl.
Alternatively at your prompt try tying in just perl without hitting enter, and then drag the hello.pl file from its file explorer location into the terminal window. That should paste the full file path to the file as text into the command prompt. If you're using cygwin I forget it if properly pastes the path with forward-slashes, like /cygdrive/c/Users/bonan/Desktop/perl/hello.pl, or if it pastes what it would in cmd with backslashes as you've indicated you typed yourself.
The other thing to do that's relatively easy is right click the file and choose to open a terminal or shell here, which for cygwin you can get in your context menu by running chere -i once (it actually says "Bash prompt here" I think). And there's similar context menu options for cmd, powershell, an actual linux bash, or mac os x's terminal ... once you're in the same path as the file, you can just type perl heltab and autocomplete the filename assuming no other files in the same folder start with "hel".

Open Cygwin command in specified directory on windows

I use phpstorm and it's terminal facility.
In terminal section I typed F:\Projects\cygwin64\bin\mintty.exe -i /Cygwin-Terminal.ico - so it uses Cygwin as terminal. But it opens it in home folder. Is it possible to open it in different folder? By typing a command or by doing something else.
Because I have a folder called F:\Projects\Local in this folder I have vagrant and I want to open phpstorm, open terminal within php storm and just type vagran up. I don't want to open cgywin again.
thanks
If you just want to open Cygwin with Mintty in the project directory then you can execute the command:
F:\Projects\cygwin64\bin\mintty.exe /bin/env CHERE_INVOKING=1 /bin/bash -l
This will avoid automatically changing to the home directory. See https://code.google.com/p/mintty/wiki/Tips#Starting_in_a_particular_directory for more information on this command.
If you want to use the embedded PhpStorm terminal, then you can modify the Shell path in the terminal settings. Open File > Settings... > Tools > Terminal. Replace the shell path with F:\Projects\cygwin64\bin\env.exe CHERE_INVOKING=1 /bin/bash -l. You may need to restart PhpStorm after this change.
Note: this is assuming that your Cygwin Root Directory is F:\Projects\cygwin64\.
For whome the above way ain't work anymore, like in PhpStorm v. 2016.3. The shell path have to be enclosed in quotes
"C:\Users\MyUser\.babun\cygwin\bin\env.exe" CHERE_INVOKING=1 /bin/zsh.exe
For the PhpStorm that I'am using (v10.0.4) in Windows 10 I use this command works:
D:\tools\.babun\cygwin\bin\env.exe CHERE_INVOKING=1 /bin/bash.exe
I'm using Babun which installs the Cygwin in D:\tools\.babun\cygwin.

How to start Gvim from Command Prompt?

I tried to start gvim using start command like this
start gvim.exe
But it doesn't work for gvim, although it does work for firefox.exe. My questions are-
How can I start gvim from command prompt?
Why start command doesn't work for gvim.exe?
Are there any additional parameter that I can use when starting gvim from command prompt?
Completely different, so a separate answer:
Actually, -- I just remembered -- Vim isn't normally added to the path variable, it's run through .bat files in C:\Windows.
From another answer on StackOverflow:
When you install gVim: Please make sure Create .bat files for
command line use is checked. It'll create several .bat files in
C:\Windows\:
C:\>cd %windir%
C:\WINDOWS>dir /b *.bat
evim.bat
gview.bat
gvim.bat
gvimdiff.bat
view.bat
vim.bat
vimdiff.bat
vimtutor.bat
This is because gvim.exe is not in your PATH list. If you know which directory gvim.exe resides, add this directory to your PATH list. This can be done by typing the following in an Explorer address bar:
Control Panel\System and Security\System
Then press Advanced system setings, then Environment Variables. The PATH is a list of directories separated by a ;.
Try typing just "gvim" instead of "start gvim.exe". That works for me. Vim isn't in my path environment variable.

How can I run a !<cmd> from a vim script when the path has a space in it on Windows?

I'm attempting to use the :!<cmd> format in vim to execute an external command and put the results in the buffer. If I type :!, path completion is possible and I can complete the path right up to the command I want to execute. This automatically escapes spaces like so:
:!c:\Program\ Files\ (x86)\Microsoft\ Visual\ Studio\ 9.0\Common7\IDE\TF.exe
When I hit enter, I get:
'c:\Program\' is not recognized as an internal or external command
Which I suspect means that vim has not escaped the spaces properly when passing the command to cmd.exe. I've tried all sorts of escaping combinations to make this work but to no avail. The only way I've found to do this is to work out what the DOS8.3 filename is and use that instead of the long path name. However, I don't like this approach since it's going to make my script less portable. Does anyone know if this can be done, or is it a bug in vim?
If you have quoted arguments, not just the exe path, then you may need to do some fancy quoting, like below. The main problem is not the exe path itself, but the arguments. I found this webpage helpful for similar problems myself:
http://blogs.msdn.com/b/twistylittlepassagesallalike/archive/2011/04/23/everyone-quotes-arguments-the-wrong-way.aspx
Not sure offhand and don't have time to check, but if you have a quoted argument then sample below may be closer to what you need:
silent! exe 'r!"C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\TF.exe" history /followbranches \^"#\^"'
Also, I wonder whether the quotes around the path may need special treatment since they are around only a portion of the full command. In any case, the quotes \^" work for main quotes in command line and ^" for quotes embedded in other quotes. I have in the past found it useful to experiment with the command at a windows prompt, remembering to test it with the way Vim prepares it, which is with your command prepended by c:\windows\sys32\cmd.exe .
On second thought, I think when I was working with similar problem I never did get to point of solving command with both quoted arguments and quoted exe-path-with-spaces in same command. I expect there's way to do it, but I instead just created a soft link to the exe in path with no spaces. E.g.:
mklink c:\users\myname\myexe c:\program files(x86)\myapp\myexe.exe
After having done that there's no need to quote the exe command itself and quoting the argument with \^" worked fine. I am of course curious about how to quote an exe-with-spaces that also has quoted arguments.
EDIT: I think I found way around my problem with quoting, don't have VS to test with your exact command but here's what I think may work from command line:
cmd /k ""C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\TF.exe" history /followbranches ^"#^""
If that works for you from command line then I think only issue is getting Vim to include the /k switch. (Also, there could be issue with Windows command line "throwing away" the /followbranch switch, because of the forward slash, but maybe not.)
EDIT2: I think the trick for doing it from Vim is just to include the 'cmd /k' as part of the command you're running. You end up with several levels of shells opening, but I don't think that's a problem. For an example, here's on that runs from Vim, with (1) spaces in exe path, (2) quoted argument (the (message .. ) ) and even (3) a quote within a quoted argument (\^"hi\^"). This command opens an Emacs instance and has Emacs print message "hi":
!cmd /k ""c:\program files (x86)\emacs\emacs\bin\emacs.exe" --eval ^"(message \^"hi\^")^""
And yet one more EDIT: Including your own 'cmd /k' does create problems, I think, if you're trying not just to execute the external command, but to read its output back into the Vim buffer. In that case you could redirect the output to a file in the user's home directory and the use :read to insert into the buffer. If there's some way to get Vim's own cmd to use k switch then this would be unnecessary, but if not then at least this provides good workaround.
Enclose the full pathname of the executable in double quotation marks. Do not escape spaces in the pathname.
In your example, some of the backslashes were added to escape spaces, and others are a part of the pathname. You did not provide the original pathname, but I can guess at it. If I guessed right, the command that will work is:
:!"c:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\TF.exe"
This works equally well in a script. The equivalent script command is:
silent execute '!"c:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\TF.exe"'
I have tested this in Vim 7.3.346 x86, installed on Windows 7 Pro SP1 x64.
%0 (batch name) %1 (1st parameter) %2 (2nd parameter)
example:
C:\CSW>MyBatchFile.bat "C:\Program files" "C:\CSW\My File.txt"
Not sure if this works with vim but it does work with bash in windows.
You just need to call by adding double quote in it.
I dont have enough idea about Vim script. but while running in command prompt if you will give the complete exe path having space then it will give error like
C:>c:\Program Files\Internet Explorer\iexplore.exe
'c:\Program' is not recognized as an internal or external command,
operable program or batch file.
But It will work if you will surrounded with double qoute.
C:>"c:\Program Files\Internet Explorer\iexplore.exe"
C:>

Resources