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 > Colors and regex in zsh
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Colors and regex in zsh

Réponse
 
LinkBack Outils de la discussion
Vieux 07/03/2007, 17h32   #1
Johny
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Colors and regex in zsh

1) How can I receive colors in prompt under zsh ?
2) I have turn on coloring in ls.
When i run:
ls * | grep john
-> bash keep colors of directoris etc...
-> zsh lose colors

3) How i sholud use regex in zsh:
ps -aux | grep [w]eechat
generatin error (only under zsh) why ?

Greetings from Poland
John

  Réponse avec citation
Vieux 07/03/2007, 18h16   #2
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Colors and regex in zsh

2007-03-7, 08:32(-08), Johny:
> 1) How can I receive colors in prompt under zsh ?
> 2) I have turn on coloring in ls.
> When i run:
> ls * | grep john
> -> bash keep colors of directoris etc...
> -> zsh lose colors


Neither bash nor zsh have an influence on how ls displays its
output.

What matters is what options you pass to ls. You probably have
an alias defined for ls.

In the bash case (maybe in ~/.bashrc), you probably have

alias ls='ls --color=always'

while with zsh (in ~/.zshrc?):

alias ls='ls --color=auto'

I would advice against using ls --color=always, because to
display in color, ls output extra characters, so when piping to
another command, those extra characters may cause trouble.

for instance

ls --color=always | grep blah | xargs rm

would not work because xargs would think you want to remove a
file called <Esc>[32mblahblah<Esc>[m when actually you want to
remove blahblah. (<Esc>[32m is only of use to a terminal to
change the current foreground text color, it is not to grep nor
to xargs that treat it as any other character sequence).

>
> 3) How i sholud use regex in zsh:
> ps -aux | grep [w]eechat
> generatin error (only under zsh) why ?


This is incorrect syntax in both bash and zsh. zsh s you a
bit more in telling you that there is an error.

[w]eechat is asking the shell to expand the globbing *pattern*
into a list of matching files in the current directory. You want
to make sure that globbing is not performed by the shell by
quoting the "[" character that is a character special to the
shell (both to bash and zsh).

ps aux | grep '[w]eechat'

On some systems:

ps -fC weechat

--
Stéphane
  Réponse avec citation
Vieux 07/03/2007, 18h50   #3
Frank Terbeck
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Colors and regex in zsh

Johny <Jan.Koprowski@gmail.com>:
> 1) How can I receive colors in prompt under zsh ?


Take a look at: man zshcontrib | less -p "OTHER FUNCTIONS"
After autoloading and running the 'colors' function, you are able to
access foreground and background colors via the associative arrays
described in the part of the manual I pointed you to above.

Make sure to put '%{%}' around your colors, so zsh's character
counting does not get confused.

Example:
PS1="%{${fg[red]}%}%~%{${reset_color}%}%% "

> 2) I have turn on coloring in ls.

[...]
> 3) How i sholud use regex in zsh:

[...]

Stéphane answered these already.

Regards, Frank


--
There are no threads in alt.binaries.pictures.erotica,
so there's no gain in using a threaded news reader.
-- unknown source
  Réponse avec citation
Vieux 08/03/2007, 08h08   #4
Johny
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Colors and regex in zsh

On 7 Mar, 18:16, Stephane CHAZELAS <this.addr...@is.invalid> wrote:
> 2007-03-7, 08:32(-08), Johny:
>
> > 1) How can I receive colors in prompt under zsh ?
> > 2) I have turn on coloring in ls.
> > When i run:
> > ls * | grep john
> > -> bash keep colors of directoris etc...
> > -> zsh lose colors

>
> Neither bash nor zsh have an influence on how ls displays its
> output.
>
> What matters is what options you pass to ls. You probably have
> an alias defined for ls.
>
> In the bash case (maybe in ~/.bashrc), you probably have
>
> alias ls='ls --color=always'
>
> while with zsh (in ~/.zshrc?):
>
> alias ls='ls --color=auto'
>
> I would advice against using ls --color=always, because to
> display in color, ls output extra characters, so when piping to
> another command, those extra characters may cause trouble.
>
> for instance
>
> ls --color=always | grep blah | xargs rm
>
> would not work because xargs would think you want to remove a
> file called <Esc>[32mblahblah<Esc>[m when actually you want to
> remove blahblah. (<Esc>[32m is only of use to a terminal to
> change the current foreground text color, it is not to grep nor
> to xargs that treat it as any other character sequence).
>


Thank you for this grate simple examples. (This is very nice )

>
> > 3) How i sholud use regex in zsh:
> > ps -aux | grep [w]eechat
> > generatin error (only under zsh) why ?

>
> This is incorrect syntax in both bash and zsh. zsh s you a
> bit more in telling you that there is an error.
>
> [w]eechat is asking the shell to expand the globbing *pattern*
> into a list of matching files in the current directory. You want
> to make sure that globbing is not performed by the shell by
> quoting the "[" character that is a character special to the
> shell (both to bash and zsh).
>
> ps aux | grep '[w]eechat'
>
> On some systems:
>
> ps -fC weechat


ps -fC weechat works great I found this example here: [http://
www.oreilly.com/catalog/esa3/] and it works (in bash on my computer).

Example (i have alias weechat='env TERM=xterm weechat-curses'):
Weechat is runing:

1) ps -fC weechat
UID PID PPID C STIME TTY TIME CMD

2) ps -aux | grep weechat
dziubdziub 3248 0.5 1.1 71472 7172 pts/2 S+ 08:00 0:00
weechat-curses
dziubdziub 3258 0.0 0.1 2092 748 pts/1 R+ 08:02 0:00
grep weechat

3) ps -aux | grep [w]eechat
johny 3248 0.3 1.1 71472 7172 pts/2 S+ 08:00 0:00
weechat-curses

(and error before Warning: bad ps syntax, perhaps a bogus '-'? See
http://procps.sf.net/faq.html)

sometimes instead of error i get (here for ps -aux | grep [e]kg2):
johny 3294 41.0 0.8 78996 5260 pts/2 S+ 08:05 0:00 ekg2
johny 3295 0.0 0.3 9748 2280 pts/2 S+ 08:05 0:00 ekg2

I belive that is wrong syntax in bash/zsh today but what i should to
do to get this same effect in zsh today ?
> --
> Stéphane


On 7 Mar, 18:50, Frank Terbeck <f...@bewatermyfriend.org> wrote:
> Johny <Jan.Koprow...@gmail.com>:
>
> > 1) How can I receive colors in prompt under zsh ?

>
> Take a look at: man zshcontrib | less -p "OTHER FUNCTIONS"
> After autoloading and running the 'colors' function, you are able to
> access foreground and background colors via the associative arrays
> described in the part of the manual I pointed you to above.
>
> Make sure to put '%{%}' around your colors, so zsh's character
> counting does not get confused.
>
> Example:
> PS1="%{${fg[red]}%}%~%{${reset_color}%}%% "
>


Thank you Thanks you I have prompt like rainbow:

PS1="%{${fg_bold[red]}%}%n%{${fg_bold[green]}%}@%{${fg_bold[blue]}%}%m%
{${fg_bold[yellow]}%}:%~%#%{${reset_color}%}"



  Réponse avec citation
Vieux 08/03/2007, 15h49   #5
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Colors and regex in zsh

On 7 Mar 2007 23:08:40 -0800, Johny
<Jan.Koprowski@gmail.com> wrote:
>
> sometimes instead of error i get (here for ps -aux | grep [e]kg2):
> johny 3294 41.0 0.8 78996 5260 pts/2 S+ 08:05 0:00 ekg2
> johny 3295 0.0 0.3 9748 2280 pts/2 S+ 08:05 0:00 ekg2
>
> I belive that is wrong syntax in bash/zsh today but what i should to
> do to get this same effect in zsh today ?


ps aux | grep "[e]kg2"

--
If you don't do it, you'll never know what would have happened if you
had done it.
  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 22h49.


É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,11592 seconds with 13 queries