If the possible is following, could someone help me do it?
I want to customize the Windows 7 command prompt (cmd.exe) so that instead of it showing C:\Users\Blah> , it shows
[HH:MM] text#text ~ $
Essentially, I want to make it look like it's Arch Linux but it's not.
/halp
As foxidrive says in comment, the built in help documentation for PROMPT describes the available meta characters for the PROMPT command.
There is no direct way to get time as HH:MM. You will have to use backspaces to strip off the minutes and seconds. Also, hours less than 10 may have a leading space instead of a leading zero, depending on regional settings.
prompt [$T$H$H$H$H$H$H] text#text ~ $$
Try Clink which supports customizing the prompt with Lua scripts, as well as adding Bash-style line editing, completion, and history just like Arch Linux.
Related
I'm using Mac OS 10.13.4.
iTerm2 Version is Build 2.1.1
Vim Version is
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Nov 29 2017 18:37:46)
Included patches: 1-503, 505-680, 682-1283
Compiled by root#apple.com
And I Installed the Vundle plugin
And when I open vim in iTerm2 with oh-my-zsh, the $p appears at the first line.
It doesn't appear with Terminal.app of Apple?
How to solve this problem?
vim is assuming that iTerm2 is xterm (not a good assumption), and attempting to determine the state of the cursorBlink resource by sending an escape sequence containing $p which iTerm2 does not handle properly (see source-code for vim for the escape sequence, and also where it uses the feature). While vim starts with the TERM setting (i.e., "xterm"), it does make a few checks to exclude things like gnome-terminal as noted in the source code comment. But iTerm2 happens to fool vim in this case. So the result goes to the screen.
In XTerm Control Sequences that is documented like this:
CSI ? Ps$ p
Request DEC private mode (DECRQM). For VT300 and up, reply is
CSI ? Ps; Pm$ y
where Ps is the mode number as in DECSET/DECSET, Pm is the
mode value as in the ANSI DECRQM.
Two private modes are read-only (i.e., 1 3 and 1 4 ), pro-
vided only for reporting their values using this control
sequence. They correspond to the resources cursorBlink and
cursorBlinkXOR.
Although vim is fooled here, the problem is due to iTerm2, for which you've probably set the TERM environment variable to xterm-256color, or something like that. It doesn't match iTerm2's behavior very well (the function keys don't match up, etc). ncurses provides a better one. But out-of-the-box MacOS has a terminal database that's about ten years old, and lacks that entry. To get a good terminal database (i.e., one where you could set TERM to iterm2), you could do that with MacPorts or home-brew.
Running infocmp to get a measure of the differences between the (correct) iterm2 entry and linux, xterm-256color shows that
it's actually closer to nsterm-256color (a correct entry for Terminal.app which Apple doesn't provide) with 38 lines of difference,
next closest linux with 76 lines and
still further away from xterm-256color with 94 lines.
The feature that's missing or mis-implemented in iTerm2 isn't in the terminal description: it's a special feature that vim has to guess about.
As mentioned above, this $p is due to vim sending a control sequence for a cursor blink request. In your .vimrc, you can turn off the cursor blink request by clearing the t_RC terminal option. I wrapped this in a conditional which turns it off only for 256 color terminals.
if &term =~ '256color'
set t_RC=
endif
Setting the terminal explicitly to linux solved it for me:
export TERM=linux
The p means print, which is the command the range is being given to, and yes.. it displays to you what is in that range.
In vim you can look at :help :range and :help :print to find out more about how this works. These types of ranges are also used by sed and other editors.
They probably used the 1,$ terminology in the tutorial to be explicit, but note that you can also use % as its equivalent. Thus, %p will also print all the lines in the file.
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.
I am new to OSX and have downloaded iTerm 2 and my name for the command line is superfluously long.
It looks like my-name-Macbook-pro:~ myname$
and I want it to look like ~myname$
Is there an easy way to shorten this name, I have googled as much as I can but can't find an easy solution.
This has nothing to do with OSX or with iterm2. OSX by default uses the bash shell and you just need to set the prompt correctly.
The prompt is set by the variable PS1. See this article on how to set your bash prompt. To achieve what you want, you need the \w and the \u fields. So something like
PS1=\\w:\\u\$
will give you ~:myname$. Play around with the other options and see what you like best. Once you find a setting that you like, enter it in your .bashrc file so that it is loaded every time you login. Also see this question for cool stuff to put in your .bashrc.
I am using a bash script to run a number of application (some repeatedly) on a Windows machine through cygwin. The script contains commands to launch those applications, line by line. Most of these applications run for many minutes and many times I have observed that the i+1 th application is not being started even after i th application is completed. In such cases, if I press enter in the cygwin console on which the bash script is running, the next application starts running. Is it because of any issue with bash on cygwin? Or is it an issue with the Windows OS itself? Have any of you observed such an issue with bash + cygwin + Windows?
Thanks.
I think I have seen this before.
Instead of
somecommand
try
somecommand </dev/null
If that doesn't work, try
cmd /c somecommand
Or experiment with other redirections, e.g.
somecommand >/dev/null
Sounds like you may have a problem with your shell script encoding; DOS (and Windows) uses CR+LF line endings, whereas Linux uses LF endings. Try saving the file as LF.
What might also be going on:
When I was running Cygwin on a school laptop, I encountered a dramatic slowing of shell scripts vs. when they were running in a native Linux environment. This was especially apparent when running a configure script from GNU Autotools.
Check your path for slow drives. (From the Cygwin FAQ):
Why is Cygwin suddenly so slow?
If suddenly every command takes a very long time, then something is probably attempting to access a network share. You may have the obsolete //c notation in your PATH or startup files. Using //c means to contact the network server c, which will slow things down tremendously if it does not exist.
You might also want to check whether you have an antivirus program running. Antivirus programs tend to scan every single executable file as it is executed; this can cause problems for even simple shell scripts that run hundreds or even thousands of individual programs before they run their course.
This mailing list post outlines what is needed to pseudo-mount the main /usr/bin directory as cygexec. I'm not sure what that does, but I found it helped.
If you're running a configure script, try the -C option.
Hope this helps!
Occasionally, I'll get this behaviour because I have accidentally deleted the 'she-bang' at the top of the script, that is, deleted the #!/bin/bash on the first line of the script.
It's even more likely for this to happen when a parent shell script calls a child script that has the she-bang missing!
Hope this helps.
A bit of a long shot, but I have seen some similar behaviour previously.
In Windows 2000, if any program running in a command prompt window had some of it's text highlighted by the cursor, it would pause the command running, and you had to press enter or clear the highlighting to get the command prompt to continue executing.
As I said, bit of a long shot, but accidental mouse clicks could be your issue...
Install cygwin with unix style line breaks and forget weird problems like that.
Try saving your script as "the-properly-line-broken-style" for your cygwin. That is, use the style you specified under installation.
Here is some relevant information:
https://stackoverflow.com/a/7048200/657703
In gvim on windows if I have text with CRLF eol then the text will display ^M at the end of each line.
How do I 'hide' that special char from display?
The :set nolist command """ does not dismiss it.
UPDATE
I did :set fileformats=unix,dos as a list. It didn't work at first, but I closed the file and reopened it again and it worked.
By default I had set fileformats to only unix value.
Thanks for answers.
You may want to set fileformat to dos.
:ed ++ff=dos %
To hide them:
:set fileformats=dos
To remove them (so you can later save the file as a unix file):
:%s/\r//g
While convening on the DOS or Unix format once and for all is of course the preferable approach, sometimes some co-workers just don't care enough about proper source management to make their editors behave.
In those desperate cases, instead of converting the file completely (resulting in a file completely rewritten by yourself according to the SCM, rendering the “blame” function useless), I found it preferable to just pretend that the problem doesn't exist. If the compiler is accommodating, and PHP by all means is, you can have a mixed-EOL file look perfectly cool with the following command:
:match Invisible /\r$/
Or in newer versions of VIM 7.4+
:match Ignore /\r$/
To make things even worse, most GUI editors don't end a text file with a newline, and when a file does end with a newline, they show an empty line at the bottom. Since this is kind of annoying, most people will remove that empty line, which will result in a mixed-EOL file (and the dreadful ^Ms shown in Vim) if the file format was DOS.
If anyone knows how to make Eclipse or NetBeans honor the newline termination without showing the empty last line (as Vim cleverly does), please share your knowledge and you'll make a coder happy here. ;-)
The file format is usually automatically detected. You must have mixed Unix and DOS/Windows lines in your file.
try this to clean it up (where "clean" = unix format):
% tr -d '\015' < old.file > new.file
:0,$ s/<ctrl-v><ctrl-m>//g
:set ff=dos
I'd like to point out that if you are using full blown VIM (at least on my ubuntu 9.10 box) it "does what you want" and auto-hides it, but the stock vi (and vim-tiny) do NOT auto-hide the ^M. If you do a minimal install (or server install) you get vi and vim-tiny only. The fix I found was to install proper vim (apt-get install vim) on my ubuntu box. Hope that helps someone that comes along this topic for the same reason I did :-D
use the command:
:1,$ s/^v^M/ /g
When my neovim showed me these ugly ^M in some files from node_modules, I fixed this by adding following code to BufWinEnter:
if char2nr(getline(1)[-1:-1]) == 13
e ++ff=dos
endif