PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Mimic zsh's right prompt in bash
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Mimic zsh's right prompt in bash

Réponse
 
LinkBack Outils de la discussion
Vieux 31/05/2007, 18h25   #1
Thorsten Kampe
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Mimic zsh's right prompt in bash

Hi,

How can I mimic a typical zsh prompt with the current directory at the
right in bash?

My zsh prompt is:
user@host% /path/to/pwd

How can I mimic the right hand side in bash with PS1?


Thorsten
  Réponse avec citation
Vieux 31/05/2007, 19h02   #2
Thorsten Kampe
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Mimic zsh's right prompt in bash

* Thorsten Kampe (Thu, 31 May 2007 18:25:17 +0100)
> How can I mimic a typical zsh prompt with the current directory at the
> right in bash?
>
> My zsh prompt is:
> user@host% /path/to/pwd
>
> How can I mimic the right hand side in bash with PS1?


Oops, that's already been asked in May. I'll read through the
thread...
  Réponse avec citation
Vieux 31/05/2007, 19h17   #3
Thorsten Kampe
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Mimic zsh's right prompt in bash

* Thorsten Kampe (Thu, 31 May 2007 19:02:46 +0100)
> * Thorsten Kampe (Thu, 31 May 2007 18:25:17 +0100)
> > How can I mimic a typical zsh prompt with the current directory at the
> > right in bash?
> >
> > My zsh prompt is:
> > user@host% /path/to/pwd
> >
> > How can I mimic the right hand side in bash with PS1?

>
> Oops, that's already been asked in May. I'll read through the
> thread...


Hm, interesting thread but no answer given. I /guess/ it should be
possible to mimic the RPS1 in bash by extending the PS1 prompt to the
right.

Just to give a hint how this could be achieved in a shell that doesn't
have its own right hand side prompt:

In 4NT (Windows Cmd enhancement and replacement) you could do:

set prompt=`%_winuser@%_host%$g$s$e[s$e[%@inc[%_row];%@eval[%_columns
- %@len[%_cwd]]H$p$e[u`


Thorsten
  Réponse avec citation
Vieux 31/05/2007, 20h06   #4
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Mimic zsh's right prompt in bash

2007-05-31, 19:17(+01), Thorsten Kampe:
> * Thorsten Kampe (Thu, 31 May 2007 19:02:46 +0100)
>> * Thorsten Kampe (Thu, 31 May 2007 18:25:17 +0100)
>> > How can I mimic a typical zsh prompt with the current directory at the
>> > right in bash?
>> >
>> > My zsh prompt is:
>> > user@host% /path/to/pwd
>> >
>> > How can I mimic the right hand side in bash with PS1?

>>
>> Oops, that's already been asked in May. I'll read through the
>> thread...

>
> Hm, interesting thread but no answer given. I /guess/ it should be
> possible to mimic the RPS1 in bash by extending the PS1 prompt to the
> right.

[...]

Why don't you use zsh in the first place?

You want to try things like:

PROMPT_COMMAND='printf "%*s\r" "$COLUMNS" "$PWD"'

In anycase, this is bound not to always work, as you need the
shell to be aware that there are characters at the right of the
cursor.

--
Stéphane
  Réponse avec citation
Vieux 31/05/2007, 20h49   #5
Thorsten Kampe
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Mimic zsh's right prompt in bash

* Stephane CHAZELAS (Thu, 31 May 2007 19:06:50 GMT)
> 2007-05-31, 19:17(+01), Thorsten Kampe:
> > * Thorsten Kampe (Thu, 31 May 2007 19:02:46 +0100)
> >> * Thorsten Kampe (Thu, 31 May 2007 18:25:17 +0100)
> >> > How can I mimic a typical zsh prompt with the current directory at the
> >> > right in bash?
> >> >
> >> > My zsh prompt is:
> >> > user@host% /path/to/pwd
> >> >
> >> > How can I mimic the right hand side in bash with PS1?
> >>
> >> Oops, that's already been asked in May. I'll read through the
> >> thread...

> >
> > Hm, interesting thread but no answer given. I /guess/ it should be
> > possible to mimic the RPS1 in bash by extending the PS1 prompt to the
> > right.

> [...]
>
> Why don't you use zsh in the first place?


I do to 95%, I swear. But in some environments people haven't seen the
light yet and I have to use what's available there.

> You want to try things like:
>
> PROMPT_COMMAND='printf "%*s\r" "$COLUMNS" "$PWD"'
>
> In anycase, this is bound not to always work, as you need the
> shell to be aware that there are characters at the right of the
> cursor.


I'll try this.

Thorsten
  Réponse avec citation
Vieux 31/05/2007, 21h04   #6
Thorsten Kampe
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Mimic zsh's right prompt in bash

* Stephane CHAZELAS (Thu, 31 May 2007 19:06:50 GMT)
> 2007-05-31, 19:17(+01), Thorsten Kampe:
> > * Thorsten Kampe (Thu, 31 May 2007 19:02:46 +0100)
> >> * Thorsten Kampe (Thu, 31 May 2007 18:25:17 +0100)
> >> > How can I mimic a typical zsh prompt with the current directory at the
> >> > right in bash?
> >> >
> >> > My zsh prompt is:
> >> > user@host% /path/to/pwd
> >> >
> >> > How can I mimic the right hand side in bash with PS1?
> >>
> >> Oops, that's already been asked in May. I'll read through the
> >> thread...

> >
> > Hm, interesting thread but no answer given. I /guess/ it should be
> > possible to mimic the RPS1 in bash by extending the PS1 prompt to the
> > right.

>
> You want to try things like:
>
> 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.

To explain: I started with a two line prompt like many people:

/path/to/pwd
user@host$

....but then I noticed that half of my screen is always only used for
the pwd prompt. Then I switched to

user@host[$basename]$

That's better but now I have only the last component of the path in
the prompt and the prompt length still changes with the directory
(okay, of course not as much as if I would put the whole path in the
brackets).

Zsh's solution to this command dilemma is brilliant: put the path to
the space that is hardly ever used: the space on the right.

Thorsten
  Réponse avec citation
Vieux 01/06/2007, 09h49   #7
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 13h32.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,17662 seconds with 15 queries