Run Windows command automatically before every command entered - windows

Is it possible to have the command prompt automatically run a command before every command that is entered?
The problem is sometimes when I kill the web server I am running to develop with in the command prompt with 'CTRL' + 'c' the process will change the color of the command prompt. This will linger in the command prompt and leave the color purple, making things hard to read. Currently when this happens I run color 07 before I start the server again. Is there a way to automatically run color 07 in the background when I type the next command so I always start with white?

You can adjust the prompt text by setting the PROMPT variable. This may allow you to use an ANSI escape code to reset the text color to default. Since some command prompt windows have ANSI color support turned on and some do not, it is difficult for me to tell if this will work as-is, but you can try it:
set PROMPT=$e[0m$P$G
If it does not work as-is, you could try one of a number of solutions to enable ANSI escape codes.

Since it sounds like you want the color command before you run the server, you can just make an alias to your command which runs both.
Try this?
Edit:
The general part of your question seems to be answered here for linux shell. If cygwin is available you could use that solution and still run your commands in windows. Could not find a trap equivalent for windows.

Related

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

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?

Fish shell on windows outputs question mark before each prompt

I just switched to a windows machine and I'm trying to get fish configured correctly. I installed it through the default route, as a shell selected through cygwin setup. It seems to be working fine, but when I directly access fish.exe or run fish.exe through IntelliJ, it outputs a ? before very prompt:
I googled and found this on fish documentation FAQ:
I'm seeing weird output before each prompt when using screen. What's wrong?
Quick answer:
Run the following command in fish:
echo 'function fish_title;end' > ~/.config/fish/config.fish
Problem solved!
The long answer:
Fish is trying to set the titlebar message of your terminal. While
screen itself supports this feature, your terminal does not.
Unfortunately, when the underlying terminal doesn't support setting
the titlebar, screen simply passes through the escape codes and text
to the underlying terminal instead of ignoring them. It is impossible
detect and resolve this problem from inside fish since fish has no way
of knowing what the underlying terminal type is. For now, the only way
to fix this is to unset the titlebar message, as suggested above.
Note that fish has a default titlebar message, which will be used if
the fish_title function is undefined. So simply unsetting the
fish_title function will not work
So it appears that intelliJ and cmd (fish.exe runs in cmd.exe if you access it directly) do not support setting the title bar, so they just output the character to the terminal instead. However, their suggested solution does not work. I've tried various options like echoing an empty string or a space, but nothing gets rid of that darn question mark.
Has anyone else run into this and found a solution?
Notes:
It doesn't have this behavior when using fish through mintty.exe,
most likely since that terminal supports setting the title, but I really prefer
to use the terminal inside intelliJ instead of having it in a
separate window.
It didn't have this problem when I used fish through IntelliJ on Ubuntu or MacOSX, it appears to be isolated to Windows

Is there a way to revert back to the command line after opening an application through it?

I want to be able to open an application on the command line, but instead of switching to the application, I want to stay on my terminal emulator. Is there a way of accomplishing this? I am using OS X.
Use the -g flag of open, which avoids bringing the app to the foreground.
$ open -g /Applications/TextEdit.app
$
open will start the app, and then return to the command prompt.
After you run the program hit ctrl+z and type bg. You will return to your terminal CLI.
Whenever you want to go back to your program, just type fg.
You can background the job. In the Bash shell, this is done with the &. For example:
some_script_or_application &
Note that some daemons and processes background themselves. For example, on OS X, running open some.pdf will preview the PDF in a GUI while returning the command prompt immediately without needing to do anything special.
See the GNU Bash Manual for more on job control for background jobs.

Any execution of command in vim causes it gets suspended

This occurs when I set the vim's shell to be interactive:
set shellcmdflag=-ic
or
set shell=/bin/bash\ -i
I like these because they give syntax highlighting to the output (eg.: !ls)
But the cost is that I have to type fg # every time.
Is this a default behavior?
How can I get interactive shell in vim without having to make it run foreground?
You can't. This behavior is perfectly normal and expected and in line with Vim's author's philosophy. It's very unlikely to change in the future.
If you want a shell inside Vim, you'll have to install a plugin like Conque or Vimshell.
I usually just use tmux instead. You can split the terminal and have a normal interactive shell and an instance of vim running side by side - very handy.

Suppress command window when running console application on Windows

Is there a way to suppress showing the command window when running a console application on Windows XP?
Details: I am calling a (console-based) program from Vim. I would like to avoid the command window being shown every time I do this.
Try start /B <program name> to start the program without a new window.
Did you try shell.vim?
The xolox#shell#execute() function
This function enables other Vim
plug-ins to execute external commands
in the background (i.e.
asynchronously) without opening a
command prompt window on Windows.
i can't believe no one has suggested simply using :silent
for example, I have the following in my .vimrc (gvim on Win7)
"open windows explorer to the directory of the current file
:map <leader>ex :silent !Explorer %:p:h<CR>
When I didn’t want to see the output of external commands called from the Vim command line, I would prepend them with :silent. However, this results in a command window momentarily flashing on screen when running GVim under MS Windows. After a short while, I got annoyed by this behaviour so I researched alternative solutions (which is how I came across this question).
The best solution I came up with was to use Vim’s inbuilt system function which runs shell commands without opening an external command window. While the output of the shell command is not printed, its exit status is conveniently available via v:shell_error. It also has the advantage that it’s portable across (all) platforms.
Example (the echo statement should print 0 if C:\Windows exists):
call system("dir c:\windows")
echo v:shell_error
You could maybe use some autohotkey script of this kind:
Loop {
WinWait, my command window title
WinHide
}
I was trying to use git-bash as my shell from vim on Windows but having the command prompt open whenever a command was run, as you described. My eventual solution was to install the plugin xolox/vim-shell and add the following snippet to .vimrc:
if has('win32')
set shell=bash\ -c
set shellcmdflag=
set shellxquote='
set shellquote=
set shellredir=>
set noshelltemp "This prevents an external window from opening.
endif
This utility will also do the job:
http://www.ntwind.com/software/utilities/hstart.html

Resources