Making Gvim work with Powershell - powershell

In gvim when I want to execute something like,:!ls it send this command to the regular Command prompt cmd.exe. So, I can't use ls or pwd or any of the regular linux commands. But, PowerShell supports most of the Linux type commands. So, how can I set PowerShell as the default shell for vim?

Set the vim shell variable to the PowerShell executable:
set shell=C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

Related

Keep Windows Terminal tab open after invoked WSL command

I'm trying to open a WSL (Ubuntu) tab in Windows Terminal, and then run a command in that tab using WSL. I use the following PowerShell command for that:
wt new-tab -p "WSL (Ubuntu)" wsl echo "hallo"
The problem is, after echo has run, the tab closes immediately.
Is there a way to keep it open?
When you pass a command line to wt.exe, the Windows Terminal CLI, it is run instead of a shell, irrespective of whether you also specify a specific shell profile with -p.
Thus, to achieve what you want:
Your command line must explicitly invoke the shell of interest...
...and that shell must support starting an interactive, stay-open session in combination with startup commands.
While PowerShell supports this, POSIX-compatible shells such as bash - WSL's default shell - do not.
A - suboptimal - workaround is the following:
wt -p 'WSL (Ubuntu)' wsl -e bash -c 'echo ''hello''\; exec $BASH'
Note:
Inexplicably, as of Windows Terminal v1.13.11431.0,
the ; char. inside the quoted -c argument requires escaping as \; - otherwise it is interpreted by wt.exe as its separator for opening multiple tabs / windows.
The above executes the specified echo command first, and then uses exec to replace the non-interactive, auto-closing original shell with an interactive, stay-open session via exec. The limitation of this approach is that any state changes other than environment-variable definitions made by the startup command(s) are lost when the original shell is replaced.
A better, but more elaborate solution is possible: create a temporary copy of Bash's initialization file, ~/.bashrc, append your startup commands, and pass the temporary copy's file path to bash's --rcfile option; delete the temporary copy afterwards.

My windows powershell display weird chars

My windows powershell display weird chars suddenly like the following:
[39;49m // [39;49mClearing the cache for the [32mdev[39m environment with debug [32mtrue[39m
Anyone knows what is the issue?
This looks like in the format of bash. I suppose a script has changed your command line to bash but does not change it back at the end.
Just type in
exit
to quit bash on PowerShell and return to PowerShell.
If bash scripts are heavily used, I would recommend you start bash to run the scripts and view the output formatted correctly (hopefully), and type in
PowerShell
to launch PowerShell on bash to run PowerShell commands.

#!/bin/bash equivalent in windows / specify interpreter for executable script IN the script

I don't really know which part of the described technology stack the behaviour i'm describing is actually a property of - linux, or bash/sh? but it does not really matter i guess.
Anyway, on linux, in a bash or sh shell, i can run a script marked as executable in the file system without specifying the interpreter on the shell or somewhere global, but right in first line of the file,
e.g.
#!/bin/bash
#!/usr/bin/python
or even
#!/usr/bin/gcl -f
for a common lisp implementation.
Is there a general windows, powershell or cmd.exe equivalent to this?Specifically, specifying the interpreter/command line to run the script with in the script itself, rather than on the command line or in the windows registry.
If not, what are similar options? The most similar thing I know about are shortcuts. Is there something more similar?
In Windows the file extension specifies, which programs is used to Interpret a script.
You can also specify the Interpreter like "cmd": CMD /c "c:\temp\script.cmd" or with Powershell: powershell.exe script.ps1
What you can do (in Powershell) is, to specify the Version, which is used to run the script. Use #Requires -version 3.0 in first line and it will throw error on v4 cmdlets etc.

perl command prompt with arguments

Is it possible to start a command prompt from perl script using Win32::Process::Create package?
I am trying to start DOORS from perl script. The executable is present in C:\Program Files\DOORS\bin\runDOORS9.rck.
I need to start the runDOORS9.rck with the argument COL9 to change the Database.
Try the good old system() function. On Windows it would use the cmd.exe, the system shell, to execute the command.
Since what you try to launch doesn't seem to be an .exe file, potentially you would have to use the start command of the cmd.exe.
For example:
system(qq{start "" "C:\Program Files\DOORS\bin\runDOORS9.rck" COL9});
(The first "" is required due to quirky argument parsing of the Window's shell commands. See help start for more information.)

interactive powershell from Cygwin

I cannot run PowerShell.exe interactively in a Cygwin rxvt or mintty terminal. Seems any session using a /dev/tty? or /dev/pts? pseudo terminal device. An instance using the junky windows console device /dev/console or /dev/cons? will work.
cygstart /bin/bash -li
launches the console version in the cruddy Windows Command Prompt which is the only place I can get an interactive PowerShell.
Works. Rxvt doesnt:
Nor does mintty:
I've tried all the echo -e | powershell.exe and powershell.exe </dev/null
I'm assuming when I see answers on Stackoverflow on this they are using Console's ... or am I missing something?
Why I cannot run PowerShell 2 from Cygwin? seems to run fine, just gets powershell v3 when he wants v2 ... wish I had that problem.
I've developed a powershell wrapper to call powershell scripts and commands from a Cygwin terminal session but cannot get the interactive option to work (if you give the wrapper no script or commands then you want to go interactive). see https://bitbucket.org/jbianchi/powershell/wiki/ for info on the wrapper script. It works for most powershell.exe calls and even acts like a "she-bang" if used in the first line of the ps1 script.
Today, typing powershell at a Cygwin bash prompt just works.
If you need to run powershell inside cygwin/babun, follow https://code.google.com/p/mintty/issues/detail?id=56#c64 . Bascilly, downloard or compile https://github.com/rprichard/winpty, copy it to your $PATH and then run
console.exe powershell
This also works with batch scripts that invoke powershell inside.
The solution I've found is to use http://sergeybelous.com/ (main site) Proxy32 proxywinconsole.exe program. If this program is in the path, my poweshell.bash wrapper will call it which will let you work interactively with PowerShell.
First Install cygwin in your system.
After that type bash on powershell terminal and you can access cygwin terminal.
PS C:\Users\username\1and1> bash
username#LWMT-14R25Q2:/mnt/c/Users/username/1and1$
I'm afraid I can't answer your question, but maybe I can help you a little further on your way with this:
I believe this is related to this issue, as discussed on the MinTTY Issue #56.
It goes into great detail as to how common cmd.exe shell applications work and interact, so much as they detail how common unix applications using their TTY abstraction layer work differently than Windows command line applications.
Script for running powershell on Cygwin minty:
blahblah#blahblahbin $ cat pwrshl
#!/usr/bin/bash if [[ ! -f "$1" ]] then
echo "Usage: $0 <PowerShellScriptFile>"
exit fi
echo "\n" | powershell -Command "& {$(<$1)}"