How can I remove the "path prefix line" from zsh on Cygwin?

1

I've installed Cygwin under Windows 7 and I've added the line exec zsh -l to C:\cygwin\home\Viktor\.bash_profile.

Problem is I still get that ugly new line for every command I write:

(Viktor@INET)[2] ~
$ cd D:

(Viktor@INET)[3] /cygdrive/d
$ ls
$RECYCLE.BIN  Program Files (x86)  System Volume Information  Viktor  xampp

(Viktor@INET)[4] /cygdrive/d
$ _

As horizontal space is no concern with 1920 pixels I would like to have the "Linux appearance", something like this viktor@inet> _ or whatever is default. One command shouldn't take three lines. And how do I change the colors?

Edit. I also have Console2 installed, which I have set to use Cygwin, if that's any help.

Viktor

Posted 2012-09-08T09:10:41.367

Reputation: 113

Answers

2

The "path prefix line thing" is called the prompt. It does not depend on the console or terminal; only on your shell.

  • In Bash, it is changed by setting the PS1 variable (usually from your .bashrc);
  • in ZSH it's PS1 or PROMPT (both are equivalent) which you set from .zshrc;
  • in the Windows cmd.exe shell – also PROMPT.

The default for ZSH appears to be %m%# ​, which expands to computername% ​​. In addition to %m and %#, there are many more substitutions (for user name, current directory, and so on) – they are documented in the zshmisc(1) manual page under "Expansion of prompt sequences". Some of them can be used to influence the formatting as well.

There are several detailed tutorials on how to customize the prompt's appearance, for example the one in Arch Linux wiki.

Note that there isn't a real "the Linux appearance" – many Linux users who use the terminal often will actually have elaborate customizations set up.

user1686

Posted 2012-09-08T09:10:41.367

Reputation: 283 655

I might have to brush up on my terminology then. ;) "Prompt" does ring a bell though. Anyway, great explanation and now I have something to go on: my googlings for "cygwin remove prefix line thingie" didn't return much. Which would be the ideal shell to use as a beginner? I downloaded zsh in hope that it would change the prompt to my liking (as I think I've used zsh or xterm in Ubuntu). Is bash a stand-alone shell? I thought I read that Cygwin uses mintty as default—is bash and mintty connected somehow? – Viktor – 2012-09-08T10:40:01.707

@Viktor: Both Bash and ZSH are "stand-alone", and both are good shells. Bash is the most popular and has a huge amount of tutorials on the web (not all of them are good, though), while ZSH is second (but more powerful and easier to customize – e.g. "grml-zsh" or "oh-my-zsh"). /// MinTTY is a terminal (similar to Xterm or Console2 or Win32 consoles) – it just displays program output on screen. You can run any shell inside it. – user1686 – 2012-09-08T10:59:55.677

Thanks a bunch! (I thought mintty was a shell as it was categorized under shells in the Cygwin package installer.) Anyways, I wrote a simple prompt variable which imitates the default terminal shell in the latest Ubuntu: PROMPT = '%n@%M:%1~$ ' | tr 'A-Z' 'a-z'. Although, my pipe tr does not seem to do anything. It's just an estetic change, but I would like to have it. That is, I want the whole PROMPT to be lowercased. – Viktor – 2012-09-08T11:24:12.370

@Viktor: Pipes and variables don't work that way. In your example, you are only running a command PROMPT=... (which sets a variable and does not output anything) and piping its output to tr. You aren't telling zsh to magically do the pipe every time it reads the value of PROMPT. /// If you want to have a lower-case hostname, try changing %M$(hostname|tr A-Z a-z). (You need to set PROMPT_SUBST for this to work.) – user1686 – 2012-09-08T11:46:28.953

I have set PROMPT_SUBST, but I can't figure out how to use your code. How do I "map" hostname to get its value from %M? Right now I have PROMPT='%n@$(%M|tr A-Z a-z):%1~$ '. I'm sorry, I have tried reading the documentation I could find, but it doesn't make sense for me. – Viktor – 2012-09-08T13:31:20.700

@Viktor: You can't really do it with %M – you'll have to get the hostname from somewhere else, such as the hostname command or the $HOSTNAME variable. – user1686 – 2012-09-08T13:37:21.610

Okay, so PROMPT='$(whoami|tr A-Z a-z)@$(hostname|tr A-Z a-z):$(pwd|tr A-Z a-z)$ ' did the trick. Now I get viktor@inet:/home/viktor$. Although I would like to just have the last directory, i.e. viktor@inet:subfolder$ or viktor@inet:~$ when in my home folder (which viktor is), but that's maybe too much to ask for? – Viktor – 2012-09-08T14:02:30.723

basenamepwd``! – Viktor – 2012-09-08T14:15:25.667

There, I'm satisfied for now: http://db.tt/tXLigPMr :)

– Viktor – 2012-09-08T14:38:23.487

0

As for "colors", try ansi-sequences. Description in my another answer.

Also, I recommend you, give a try to ConEmu - another windows terminal (I'm the author of it).

Maximus

Posted 2012-09-08T09:10:41.367

Reputation: 19 395

Okay, I will try that when I have some free time, just wanted to get a decent terminal environment up and going for my Perl/Prolog course. I switched back from Console2 to Cygwin as I couldn't figure out how to get UTF-8 in Console2, but I am still using zsh. I will definitely try your ConEmu, as I am not 100 % satisfied with my current. – Viktor – 2012-09-09T10:54:03.753