Pergunta

I'm having a heck of a time standardizing my prompts across the different shells I have installed for cygwin.

Installed shells:

  1. bash (default login shell)
  2. sh
  3. csh (tcsh, actually)
  4. ksh
  5. zsh

My prompt is standardized across bash, csh, and zsh, but I can't get sh and ksh on board.

The prompt I'm looking to use across all shells is similar to the following:

20121216 15:18:04 [shell]   # date and time in yellow, shell in red
user@hostname pwd           # user@host in green, pwd in yellow
$                           # white

I've got it set the way I want it for bash with the following line in /etc/profile:

PS1="\[\e]0;\w\a\]\n\[\e[33m\]\D{%Y%m%d %H:%M:%S} \[\e[31m\][bash]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ "

And I've got it set for csh with the following line in .tcshrc:

set prompt="\n%{\033[33m%}%Y%W%D %P %{\033[31m%}[csh]\n%{\033[32m%}%n@%M %{\033[33m%}%~\n%{\033[0m%}$ "

And I've got it set for zsh with the following lines in .zshrc:

PROMPT="
%{$fg[yellow]%}%D{%Y%m%d} %* %{$fg[red]%}[zsh]%{$reset_color%}
%{$fg[green]%}%n@%m %{$reset_color%}%{$fg[yellow]%}%~%{$reset_color%}
$ "

But I can't seem to set a default prompt for sh or ksh anywhere. I can open both of them and manually set PS1="$ ", but I cannot for the life of me get it to set automatically. The sh prompt looks identical to the bash prompt, and the ksh prompt is gibberish (bc it doesn't like the syntax of PS1 that it's inheriting from bash, I assume).

Things I've tried unsuccessfully:

  • setting PS1 in /etc/profile (in a case statement reading the shell name from echo $0)
  • setting PS1 in .kshrc
  • setting PS1 in .shrc
  • setting PS1 in .sh_profile
  • setting PS1 in .profile

It seems that cygwin just doesn't execute the files listed above when I launch one of those shells. Note that I only ever launch those shells from within bash.

Any ideas? (Sorry for the book, I'm just trying to be thorough.)

Foi útil?

Solução

The official Korn shell ksh93 will read /etc/profile and ~/.profile on login, in that order.

If ksh is not acting as a login shell it will try to read the file referred to by $ENV, or $HOME/.kshrc if ENV is not set.

Older versions (sun's ksh88 in particular) suffered from a chicken and egg situation because you could only set ENV in ~/.profile, but then you still had to source the file yourself with . $ENV.

Note that ENV and PS1 have to be exported in order to be picked up by ksh instances spawned after login (say, from screen or tmux).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top