In ConEmu I can't change the PROMPT when using cygwin bash - cmd

In conemu using cmd I can edit the prompt nice and easy in the CmdInit.cmd file - I do this because I don't like the prompt spread over two lines.
However I can't seem to do the same trick when I select the startup in settings to be bash::Cygwin.
I see that the CmdInit.cmd is dos commands, so I could create a startup.sh? not sure how I invoke it.
Also the PROMT variable does not seem to exist in the bash mode - even though there is a very long two-line prompt. How can I change it? Where are the defaults even taken from?

Related

Can not install Windows Service from Bash script [duplicate]

I have a small utility script called clear.bat that does some housekeeping work on my sources.
It is a .bat file so that I could easily double-click it in Windows Explorer.
Sometimes, I find it more handy to execute it from my Git bash (msysgit, if this matters).
To do this, I type
cmd
clear.bat
exit
cmd turns my Git bash into a normal cmd window where I could easily execute my batch. When I type exit, the cmd environment is terminated and I'm back in my Git bash.
Could this be achieved in an easier way?
I tried cmd /C clean.bat since the docs say
Syntax
CMD [charset] [options]
CMD [charset] [options] [/c Command]
CMD [charset] [options] [/k Command]
Options
/C Run Command and then terminate
/K Run Command and then return to the CMD prompt.
This is useful for testing, to examine variables
Edit:
Just noticed that the post is broken.
What I want is to execute clean.bat from within the Git bash without having to type the three commands above (cmd, clear.bat, exit). I just want to execute the .bat file from within my Git bash. Obvious way would be to create a separate .sh file that does the same work but this will lead to double code.
Edit 2:
When I execute cmd /C clean.bat, the Git bash turns into a plain CMD environment and only displays the prompt. The file clean.bat does not get executed. It's the same as if I just type cmd.
Also, adding a /debug switch does literally nothing. Seems like only cmd gets evaluated and all further parameters are getting ignored.
After playing around a bit more, I found the solution myself:
cmd "/C clean.bat"
does the trick. But I got no clue, why...
./clear.bat will do the trick.
The Git for Windows (msysGit has been superseded by Git for Windows1) FAQ says you have 3 options:
Run programs that have problems using the winpty utility. This allows you to keep using the nicer mintty terminal, but can become unwieldy if you need the workaround for many programs.
Modify the shortcut for Git Bash to run bash directly without mintty so it uses the default console host and configure it for "Quick Edit", reasonable size and scroll-back and suitable unicode font. You'll still have to live with the other quirks of console host.
Install and use ConEmu.
At some point, Git for windows added support for the MSYS_NO_PATHCONV environment variable, so in addition to #eckes and #AlikElzin-kilaka solutions, you can also
MSYS_NO_PATHCONV=1 cmd /c clean.bat
In general, I prefer this solution, as it allows the code to be the closest to resembling normal bash, and there are many ways to export MSYS_NO_PATHCONV depending on your preferred situation.
Note: Git for Window's bash does not support the MSYS2 environment variable MSYS2_ARG_CONV_EXCL
The other solutions
The weird quoting solution
Why does cmd "/c clean.bat" not create other errors?
It turns out argument parsing in windows does not follow the same universal rules as it does in *nix. Instead, in windows the arguments are parsed differently based on the runtime you compile against. Basically in windows, the command line arguments are passed in as "one string" and then parsed by the runtime.
See here(archive) for more explanation than you could ever want.
E.g. cmd parses arguments differently then wscript.exe
In the end, you can hopefully find something that works with this method, and it is the most "window-esque" of the three solutions
The // method
This is pretty well explained here and simple to use, but adds an extra / which does not help readability
I like start clean, it opens a new window with cmd. This method has some benefits:
cmd.exe gets a native console
the new console has a native windows character encoding (e.g. cp1251 vs utf8)
This will work and it frees the terminal too
nohup ./nucleus.bat &
less nohup.out

How do I open a shell but still have access to vim

I am running gvim on Windows 7.
I use this mapping to execute the current file with powershell:
nnoremap <C-q> :! & '%:p'<cr>
It works great except I can't access vim until I close the powershell window. Sometimes I want the shell to remain open so I can run additional commands or I want to access vim with the shell still open so I can check the lines where errors were generated.
Ideally (don't know if this is possible) I want to have an already open shell execute the command. So I always have vim and a shell open (on separate monitors) and I can execute the script in that same shell.
How can I achieve this?
GVIM on Windows has a special :!start command to execute the external command asynchronously; i.e. Vim doesn't wait for its return. Just replace the :! with it. See :help :!start for more information.
On Unix, such special isn't necessary; you can just append & (a shell feature) to execute the command asynchronously.

Running Windows batch files from Emacs

I'm somewhat new to gnu emacs, and so perhaps this is a noob question, but I have a few batch files I use a lot when coding in emacs to compile/build/execute/debug/etc. I am wondering how I could A) run these batch files from emacs without having to keep opening a cmd prompt window or going to windows explorer and B) bind this to a key shortcut (perhaps I could specify the file?) I have seen several things online about running emacs in batch-mode, but I don't believe this is what I'm looking for. And I know it is possible because I have seen others run batch from emacs (output and everything would appear in a new buffer adjacent to the current as if you did C-x 3)
Thanks in advance!
To run an arbitrary shell command in Emacs, you call shell-command which is bound to M-!
See C-hf shell-command (or C-hkM-!) for details.
I believe in the Windows-native Emacs, the default shell is cmd (or some alias thereof), so I'm reasonably confident that this is what you're thinking of.
I'm not sure whether all of the following work in Windows, but related commands are:
M-& - async-shell-command
M-| - shell-command-on-region
And with a prefix argument (e.g. C-uM-!) any of those commands will insert the shell command's output into the current buffer. (In the case of shell-command-on-region, that replaces the region.)

Out of a git console: how do I execute a batch file and then return to git console?

I have a small utility script called clear.bat that does some housekeeping work on my sources.
It is a .bat file so that I could easily double-click it in Windows Explorer.
Sometimes, I find it more handy to execute it from my Git bash (msysgit, if this matters).
To do this, I type
cmd
clear.bat
exit
cmd turns my Git bash into a normal cmd window where I could easily execute my batch. When I type exit, the cmd environment is terminated and I'm back in my Git bash.
Could this be achieved in an easier way?
I tried cmd /C clean.bat since the docs say
Syntax
CMD [charset] [options]
CMD [charset] [options] [/c Command]
CMD [charset] [options] [/k Command]
Options
/C Run Command and then terminate
/K Run Command and then return to the CMD prompt.
This is useful for testing, to examine variables
Edit:
Just noticed that the post is broken.
What I want is to execute clean.bat from within the Git bash without having to type the three commands above (cmd, clear.bat, exit). I just want to execute the .bat file from within my Git bash. Obvious way would be to create a separate .sh file that does the same work but this will lead to double code.
Edit 2:
When I execute cmd /C clean.bat, the Git bash turns into a plain CMD environment and only displays the prompt. The file clean.bat does not get executed. It's the same as if I just type cmd.
Also, adding a /debug switch does literally nothing. Seems like only cmd gets evaluated and all further parameters are getting ignored.
After playing around a bit more, I found the solution myself:
cmd "/C clean.bat"
does the trick. But I got no clue, why...
./clear.bat will do the trick.
The Git for Windows (msysGit has been superseded by Git for Windows1) FAQ says you have 3 options:
Run programs that have problems using the winpty utility. This allows you to keep using the nicer mintty terminal, but can become unwieldy if you need the workaround for many programs.
Modify the shortcut for Git Bash to run bash directly without mintty so it uses the default console host and configure it for "Quick Edit", reasonable size and scroll-back and suitable unicode font. You'll still have to live with the other quirks of console host.
Install and use ConEmu.
At some point, Git for windows added support for the MSYS_NO_PATHCONV environment variable, so in addition to #eckes and #AlikElzin-kilaka solutions, you can also
MSYS_NO_PATHCONV=1 cmd /c clean.bat
In general, I prefer this solution, as it allows the code to be the closest to resembling normal bash, and there are many ways to export MSYS_NO_PATHCONV depending on your preferred situation.
Note: Git for Window's bash does not support the MSYS2 environment variable MSYS2_ARG_CONV_EXCL
The other solutions
The weird quoting solution
Why does cmd "/c clean.bat" not create other errors?
It turns out argument parsing in windows does not follow the same universal rules as it does in *nix. Instead, in windows the arguments are parsed differently based on the runtime you compile against. Basically in windows, the command line arguments are passed in as "one string" and then parsed by the runtime.
See here(archive) for more explanation than you could ever want.
E.g. cmd parses arguments differently then wscript.exe
In the end, you can hopefully find something that works with this method, and it is the most "window-esque" of the three solutions
The // method
This is pretty well explained here and simple to use, but adds an extra / which does not help readability
I like start clean, it opens a new window with cmd. This method has some benefits:
cmd.exe gets a native console
the new console has a native windows character encoding (e.g. cp1251 vs utf8)
This will work and it frees the terminal too
nohup ./nucleus.bat &
less nohup.out

powershell as gvim(vim) :shell

i'm on a Windows 7 machine and i've installed Gvim(win32 version not MinGW or something alike), i've written in my _vimrc
set shell=powershell.exe
Now when i type :shell command it must open a new buffer with powershell in it but instead it opens powershell in a new window.
Question : Is there a way to set Gvim ( configuration or plugin ) to open PowerShell in a buffer (like bash)?
Reread documentation for :shell and design-not. Quote from design-not:
Vim is not a shell or an Operating System. You will not be able to run a
shell inside Vim or use it to control a debugger. This should work the
other way around: Use Vim as a component from a shell or in an IDE.
A satirical way to say this: "Unlike Emacs, Vim does not attempt to include
everything but the kitchen sink, but some people say that you can clean one
with it. ;-)"
Of course, somebody does not like this. There are some projects that make it possible to run shell inside vim, most known is Conque which now has windows support. Note that it does not work with unicode.

Resources