2

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.)

j0k
  • 22,600
  • 28
  • 79
  • 90
nullrevolution
  • 3,937
  • 1
  • 18
  • 20
  • There's no such thing as `'sh'` anymore. It used to refer to the original Bourne Shell, but nowadays is linked to some other minimal feature shell like `ash`, `bash`, or `dash`. It does not have the features you need - you can try and set PS1 from another shell, but it won't track the time, nor the shell's working directory. – Henk Langeveld Dec 09 '12 at 11:54
  • `ksh` can track the current directory with `PS1='$PWD $ '` -- use single quotes to postpone expansion of `$PWD` until `$PS1` gets evaluated. The original documentation for `ksh` has a hack for adding date and time, but it's still a (smart) hack. The bash escape sequences won't help here. – Henk Langeveld Dec 09 '12 at 11:59
  • Thanks for that info, Henk. But I guess what I was really asking is where do I set the default prompt in `ksh`? – nullrevolution Dec 10 '12 at 14:25

1 Answers1

1

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).

Henk Langeveld
  • 8,088
  • 1
  • 43
  • 57
  • 1
    +1 and acceptance for a) the reference to `$ENV` and b) the info about `sh` in your earlier comment. together, that led me to add `export ENV=$HOME/.kshrc` to my `/etc/profile`, then add `export PS1=blahblahblah` to ~/.kshrc, which is finally setting a default prompt for non-login korn shells. thanks! – nullrevolution Dec 11 '12 at 22:39