Re: Mimic zsh's right prompt in bash
2007-05-31, 21:04(+01), Thorsten Kampe:
[...]
>> PROMPT_COMMAND='printf "%*s\r" "$COLUMNS" "$PWD"'
>
> That's pretty clever but unfortunately the PROMPT_COMMAND uses an
> additional line - it doesn't display on the same line as PS1. This is
> the same effect as having a two line prompt.
Works for me.
>
> To explain: I started with a two line prompt like many people:
>
> /path/to/pwd
> user@host$
Personaly, I have
PS1='%(?..%B(%?%)%b)${jobstates:+%S$#jobstates%s}% 60<...<${STY[1,0]-"%{$fg_bold[magenta]%}%m%{$reset_color%}:"}%~%(#.#.$) '
RPS1='%30<...<${ZFTP_PWD:-%T}%S${ZFTP_HOST:+×}%s'
That is:
if running within screen I have:
~/bin$
or
~/bin# if I'm root (that is alsmost never as I tend to use sudo)
so no need to have the user in the prompt.
(1)~/bin$
with (1) in bold if the last command failed (1 being the exit
status).
~/bin4$
4 in reverse video, being the number of jobs in background.
If I don't run in screen (which never happens and thus means one
of my screen windows runs a rlogin or ssh to some remote host),
then the prompt also includes the host name in bold magenta (as
a reminder that I'm rloggedin).
I have the screen status line in the xterm window. That includes
the hostname and username and date and time, and the currently
run command (and window number), so all those informations don't
need to be in the prompt.
in ~/.screenrc:
hardstatus string '%H - %D %d %M - %c - %h (%n)'
termcapinfo xterm* 'hs:ts=\E]2;:fs=\007:ds=\E]0;xterm\007'
and in ~/.zshrc:
if (( $+STY )); then
preexec() {
local -a words
words=("${(@Q)${(z)1}}")
printf '\033]0;%s\a' " ${${${(qqqq)words[1,2]}#??}%?}${words[3]+...}";
}
precmd() { printf '\033]0;zsh\a'; }
fi
--
Stéphane
|