Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
ZSH users (lovers?) thread
View unanswered posts
View posts from last 24 hours

Goto page Previous  1, 2, 3 ... 9, 10, 11, 12, 13  Next  
Reply to topic    Gentoo Forums Forum Index Gentoo Chat
View previous topic :: View next topic  
Author Message
Satoshi
Apprentice
Apprentice


Joined: 06 Nov 2006
Posts: 180
Location: Brazil

PostPosted: Sun Oct 24, 2010 4:27 am    Post subject: Reply with quote

Just switched and it's been working great!

Really like all of zsh's functions.


Gogiel wrote:
My PROMPT is
Code:
PROMPT=$'%{\e[0;32m%}%B[%b%{\e[0m%}%n%{\e[0;32m%}@%{\e[0m%}%(4c,./%1~,%~)%{\e[0;32m%}%B]%b% %(?,%{\e[0;32m%}:%)%{\e[0m%},%{\e[0;31m%}:(%{\e[0m%}) %# '

Last part is tricky. When previous program exit with error there's red ':(' in prompt. Otherwise there's green ':)'.


How can I change that to make the % or # turn green or red, instead of the smiling face?
Back to top
View user's profile Send private message
ppurka
Advocate
Advocate


Joined: 26 Dec 2004
Posts: 3205

PostPosted: Sun Oct 24, 2010 5:44 am    Post subject: Reply with quote

Satoshi wrote:
Just switched and it's been working great!

Really like all of zsh's functions.


Gogiel wrote:
My PROMPT is
Code:
PROMPT=$'%{\e[0;32m%}%B[%b%{\e[0m%}%n%{\e[0;32m%}@%{\e[0m%}%(4c,./%1~,%~)%{\e[0;32m%}%B]%b% %(?,%{\e[0;32m%}:%)%{\e[0m%},%{\e[0;31m%}:(%{\e[0m%}) %# '

Last part is tricky. When previous program exit with error there's red ':(' in prompt. Otherwise there's green ':)'.


How can I change that to make the % or # turn green or red, instead of the smiling face?
Remove the % or # from the end, and insert it in place of the smilies.
_________________
emerge --quiet redefined | E17 vids: I, II
Back to top
View user's profile Send private message
ppurka
Advocate
Advocate


Joined: 26 Dec 2004
Posts: 3205

PostPosted: Sun Oct 24, 2010 5:50 am    Post subject: Reply with quote

mv wrote:
ppurka wrote:
1. Use the following to automatically rehash. Then you don't need to alias emerge.

This will not work if you do not use autocompletion for the new command (i.e. if you "just" type it). Moreover, if the autocompletion finds another (existing) command it will also not rehash and thus not show the new alternative. I guess these are most of the cases when you installed something new. Moreover, IMHO it is a bit too overdone to rehash that often. If you have really such a fast machine that you do not really care about rehashing time, you can also rehash in the precmd hook (i.e. every time before the prompt is displayed).
I never thought that rehashing took a lot of time. I never noticed any lag on my core2duo laptop which usually runs at 800MHz.

But maybe you are right, simply putting rehash in precmd would be more efficient I believe. Only thing is that it would work on the terminal I am working on, and then it won't work (until I press enter) on some other terminal that remained open while the new program was being installed.
_________________
emerge --quiet redefined | E17 vids: I, II
Back to top
View user's profile Send private message
Krog
Apprentice
Apprentice


Joined: 26 Jun 2007
Posts: 256
Location: Roma, Italy

PostPosted: Sun Oct 24, 2010 6:48 am    Post subject: Reply with quote

for now i still use bash for root and zsh only for my normal user...
so if I emerge (root of course) and then i type "exit" i have to rehash?
So the other shells?
What happens exactly if i don't?
Back to top
View user's profile Send private message
mv
Advocate
Advocate


Joined: 20 Apr 2005
Posts: 3998

PostPosted: Sun Oct 24, 2010 5:37 pm    Post subject: Reply with quote

Krog wrote:
for now i still use bash for root and zsh only for my normal user...
so if I emerge (root of course) and then i type "exit" i have to rehash?

Yes, but this is not related with the question of whether the shells are different. You would have the same issue if both are zsh or both are bash.
Quote:
What happens exactly if i don't?

If you installed a new command, the running shell will not find this new command in the path.
Back to top
View user's profile Send private message
Krog
Apprentice
Apprentice


Joined: 26 Jun 2007
Posts: 256
Location: Roma, Italy

PostPosted: Sun Oct 24, 2010 7:02 pm    Post subject: Reply with quote

sorry if i don't understand:
if i install... for example, mplayer
and i don't rehash
i can't do "mplayer foo.avi"?
Back to top
View user's profile Send private message
mv
Advocate
Advocate


Joined: 20 Apr 2005
Posts: 3998

PostPosted: Sun Oct 24, 2010 7:19 pm    Post subject: Reply with quote

Krog wrote:
sorry if i don't understand:
if i install... for example, mplayer
and i don't rehash
i can't do "mplayer foo.avi"?

Yes, if mplayer was never installed before (more precisely, if there was no mplayer executable in $PATH before you emerged mplayer): If you type just "mplayer ..." (and not "/usr/bin/mplayer ...") the shell just looks up where "mplayer" was in PATH at the last rehash (typically at startup) - if there was no such binary before, it will not find that command.
Back to top
View user's profile Send private message
Krog
Apprentice
Apprentice


Joined: 26 Jun 2007
Posts: 256
Location: Roma, Italy

PostPosted: Mon Oct 25, 2010 5:19 am    Post subject: Reply with quote

mv wrote:
Krog wrote:
sorry if i don't understand:
if i install... for example, mplayer
and i don't rehash
i can't do "mplayer foo.avi"?

Yes, if mplayer was never installed before (more precisely, if there was no mplayer executable in $PATH before you emerged mplayer): If you type just "mplayer ..." (and not "/usr/bin/mplayer ...") the shell just looks up where "mplayer" was in PATH at the last rehash (typically at startup) - if there was no such binary before, it will not find that command.


this is really a very annoying issue....

and i still have problems under kde with "home" and "end" buttons of my keyboard under kde. With:
Code:
typeset -A key

key[Home]=${terminfo[khome]}
key[End]=${terminfo[kend]}
bindkey "${key[Home]}"      beginning-of-line
bindkey "${key[End]}"       end-of-line

outside X they work, but under kde still not!
Back to top
View user's profile Send private message
Krog
Apprentice
Apprentice


Joined: 26 Jun 2007
Posts: 256
Location: Roma, Italy

PostPosted: Sat Nov 13, 2010 6:11 am    Post subject: Reply with quote

still the same problem.... :-(
Back to top
View user's profile Send private message
Krog
Apprentice
Apprentice


Joined: 26 Jun 2007
Posts: 256
Location: Roma, Italy

PostPosted: Sat Nov 13, 2010 6:29 am    Post subject: Reply with quote

Krog wrote:
still the same problem.... :-(


found a nice way to solve it:
just typing cat and then pushing the button, it shows exactly the code of the button
on my system:
Code:
krog@krogpc ~ % cat     
^[[H^C

for home, and
Code:
krog@krogpc ~ % cat
^[[F

for end
so adding:
Code:
key[Home]=${terminfo[khome]}
key[End]=${terminfo[kend]}
bindkey "${key[Home]}"      beginning-of-line
bindkey "${key[End]}"       end-of-line
bindkey    "^[[3~"          delete-char
bindkey    "^[3;5~"         delete-char

bindkey "\e[H" beginning-of-line
bindkey "\e[F" end-of-line


makes home and end buttons working on konsole AND tty
Back to top
View user's profile Send private message
Satoshi
Apprentice
Apprentice


Joined: 06 Nov 2006
Posts: 180
Location: Brazil

PostPosted: Sat Nov 13, 2010 11:18 pm    Post subject: Reply with quote

Anyone know if there's a way to make the history persistent, as in bash (across reboots, etc)?
Back to top
View user's profile Send private message
BitJam
Advocate
Advocate


Joined: 12 Aug 2003
Posts: 2441
Location: Silver City, NM

PostPosted: Sun Nov 14, 2010 12:28 am    Post subject: Reply with quote

Here is what I use. I don't think it is all needed and you probably don't want all of it. For example, the extended_history option adds a timestamp to each line which you may not want. I think the first three lines will do what you want.
Code:
export HISTSIZE=100000
export HISTFILE="${HOME}/.zhistory/zhistory"
export SAVEHIST=$HISTSIZE
setopt hist_ignore_all_dups
setopt hist_ignore_space
setopt extended_history
setopt APPEND_HISTORY
setopt SHARE_HISTORY
setopt INC_APPEND_HISTORY
setopt HIST_REDUCE_BLANKS

Currently my ~/.zshistory directory contains 355 files which hold 15K lines of history.
Back to top
View user's profile Send private message
Satoshi
Apprentice
Apprentice


Joined: 06 Nov 2006
Posts: 180
Location: Brazil

PostPosted: Sun Nov 14, 2010 4:54 am    Post subject: Reply with quote

BitJam wrote:
Here is what I use. I don't think it is all needed and you probably don't want all of it. For example, the extended_history option adds a timestamp to each line which you may not want. I think the first three lines will do what you want.
Code:
export HISTSIZE=100000
export HISTFILE="${HOME}/.zhistory/zhistory"
export SAVEHIST=$HISTSIZE
setopt hist_ignore_all_dups
setopt hist_ignore_space
setopt extended_history
setopt APPEND_HISTORY
setopt SHARE_HISTORY
setopt INC_APPEND_HISTORY
setopt HIST_REDUCE_BLANKS

Currently my ~/.zshistory directory contains 355 files which hold 15K lines of history.


Perfect!
Back to top
View user's profile Send private message
Alex Libman
n00b
n00b


Joined: 26 May 2010
Posts: 39
Location: Leaving New Hampshire

PostPosted: Mon Nov 22, 2010 2:33 am    Post subject: Reply with quote

I'm a big fan of zsh, and it will probably be the only base shell (i.e. /bin/sh and /bin/ksh replacement) in my modernized pure-copyFREE redistribution of OpenBSD.

I can understand GNU/Linux being married to bash, but Apple and Haiku OS really goofed when they chose bash over zsh - GNU is not UNIX, and UNIX is not GNU. Korn is missing some very useful features, and (t)csh has syntax issues, so I think all non-GNU projects should use zsh by default.

I'd also like to see more software packages provide zsh auto-completion support, which is particularly convenient for package management commands, any commands where you specify modes (ex. ffmpeg), etc.
Back to top
View user's profile Send private message
Satoshi
Apprentice
Apprentice


Joined: 06 Nov 2006
Posts: 180
Location: Brazil

PostPosted: Mon Nov 22, 2010 4:23 am    Post subject: Reply with quote

Alex Libman wrote:
I'm a big fan of zsh, and it will probably be the only base shell (i.e. /bin/sh and /bin/ksh replacement) in my modernized pure-copyFREE redistribution of OpenBSD.

I can understand GNU/Linux being married to bash, but Apple and Haiku OS really goofed when they chose bash over zsh - GNU is not UNIX, and UNIX is not GNU. Korn is missing some very useful features, and (t)csh has syntax issues, so I think all non-GNU projects should use zsh by default.

I'd also like to see more software packages provide zsh auto-completion support, which is particularly convenient for package management commands, any commands where you specify modes (ex. ffmpeg), etc.


Have you seen fish? It also appears to be very good.
Back to top
View user's profile Send private message
Alex Libman
n00b
n00b


Joined: 26 May 2010
Posts: 39
Location: Leaving New Hampshire

PostPosted: Mon Nov 22, 2010 5:05 am    Post subject: Reply with quote

Um, I've just troll-ranted about copyFREE license issues. Fish is licensed as very market-unfriendly GPL. :roll:

Plus fish is just simply a bad idea right off the bat: yet another shell that breaks POSIX/etc traditions, but isn't as flexible as ipython and other scripting language shells. I believe in a dichotomy between tradition and objective innovation, and for the latter what we really need is JavaScript (aka TheScript) everywhere, including the UNIX command shell.
Back to top
View user's profile Send private message
avx
Advocate
Advocate


Joined: 21 Jun 2004
Posts: 2070

PostPosted: Fri Jun 03, 2011 12:35 pm    Post subject: Reply with quote

Found this yesterday, imho pretty nifty. FISH like 'live' syntax coloring for ZSH:
https://github.com/nicoulaj/zsh-syntax-highlighting
_________________
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
Back to top
View user's profile Send private message
mv
Advocate
Advocate


Joined: 20 Apr 2005
Posts: 3998

PostPosted: Fri Jun 03, 2011 7:00 pm    Post subject: Reply with quote

avx wrote:
Found this yesterday, imho pretty nifty. FISH like 'live' syntax coloring for ZSH

A live ebuild for this is in the mv overlay (available over layman).
Back to top
View user's profile Send private message
avx
Advocate
Advocate


Joined: 21 Jun 2004
Posts: 2070

PostPosted: Fri Jun 03, 2011 8:51 pm    Post subject: Reply with quote

mv wrote:
avx wrote:
Found this yesterday, imho pretty nifty. FISH like 'live' syntax coloring for ZSH

A live ebuild for this is in the mv overlay (available over layman).
Danke :)
_________________
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
Back to top
View user's profile Send private message
NotQuiteSane
Guru
Guru


Joined: 30 Jan 2005
Posts: 471
Location: Klamath Falls, Jefferson, USA, North America, Midgarth

PostPosted: Tue Jul 26, 2011 5:25 am    Post subject: Reply with quote

Gogiel wrote:
My PROMPT is
Code:
PROMPT=$'%{\e[0;32m%}%B[%b%{\e[0m%}%n%{\e[0;32m%}@%{\e[0m%}%(4c,./%1~,%~)%{\e[0;32m%}%B]%b% %(?,%{\e[0;32m%}:%)%{\e[0m%},%{\e[0;31m%}:(%{\e[0m%}) %# '

Last part is tricky. When previous program exit with error there's red ':(' in prompt. Otherwise there's green ':)'.


Very nice. I used a good chunk of your code to make my prompt:

Code:
# NQS's prompt, based off of
# http://forums.gentoo.org/viewtopic-p-3690849.html?sid=753a61864e669836fc5121f9800360e3#3690849
# and
# http://dotfiles.org/~mental/.zshrc (gave me the idea)
# Also http://www.understudy.net/custom.html#table1 for varibles


PS1=$'%{\e[1;34m%}%~ on terminal %l, %BCommand #%!%b\
%B[%b%n@%m%{\e[0m%}%B]%b %(?,%{\e[0;32m%} OK ,%{\e[0;31m%} FAIL )%# %{\e[0m%}'

RPS1=$'%{\e[1;34m%}20%D-%*%{\e[0m%}'


Screenshot

.zshrc

NQS
_________________
These opinions are mine, mine I say! Piss off and get your own.

As I see it -- An irregular blog, Improved with new location

To delete French language packs from system use 'sudo rm -fr /'
Back to top
View user's profile Send private message
nicoulaj
n00b
n00b


Joined: 28 Aug 2011
Posts: 1

PostPosted: Sun Aug 28, 2011 12:32 pm    Post subject: Reply with quote

I have moved the zsh-syntax-highlighting script and other projects here: http://github.com/zsh-users
Back to top
View user's profile Send private message
LiamOS
n00b
n00b


Joined: 06 Jun 2012
Posts: 56
Location: Kerry/Dublin, Ireland

PostPosted: Sun Jul 29, 2012 9:37 pm    Post subject: Reply with quote

Got a lot of cool ideas from this thread.

Here's a prompt I made earlier. It's nice, but a bit fiddley if you need your .zshrc to perform other functions.
Edit: Definitely don't use it.
Code:

HISTFILE=~/.zsh_history
HISTSIZE=30000
SAVEHIST=30000
bindkey -e

zstyle :compinstall filename '/home/liam/.zshrc'

autoload -Uz compinit
compinit

alias l="ls -F --color=auto"
alias ls="ls --color=auto"
alias la="ls -A --color=auto"

autoload -U colors && colors

# This causes this file to be re-sourced after each command.
periodic() { source ~/.zshrc; }
PERIOD=1

# When this file is re-sourced, the following variables are reassigned.
i=$[${RANDOM}%5]
j=$[${RANDOM}%5]
k=$[${RANDOM}%5]
l=$[${RANDOM}%5]

# Now follow the prompt colour choices based on the random numbers.
if [ $i -eq 0 ]; then
  colour1="red"
elif [ $i -eq 1 ]; then
  colour1="cyan"
elif [ $i -eq 2 ]; then
  colour1="green"
elif [ $i -eq 3 ]; then
  colour1="magenta"
elif [ $i -eq 4 ]; then
  colour1="yellow"
elif [ $i -eq 5 ]; then
  colour1="white"
fi

if [ $j -eq 0 ]; then
  colour2="red"
elif [ $j -eq 1 ]; then
  colour2="cyan"
elif [ $j -eq 2 ]; then
  colour2="green"
elif [ $j -eq 3 ]; then
  colour2="magenta"
elif [ $j -eq 4 ]; then
  colour2="yellow"
elif [ $j -eq 5 ]; then
  colour2="white"
fi

if [ $k -eq 0 ]; then
  colour3="red"
elif [ $k -eq 1 ]; then
  colour3="cyan"
elif [ $k -eq 2 ]; then
  colour3="green"
elif [ $k -eq 3 ]; then
  colour3="magenta"
elif [ $k -eq 4 ]; then
  colour3="yellow"
elif [ $k -eq 5 ]; then
  colour3="white"
fi

if [ $l -eq 0 ]; then
  colour4="red"
elif [ $l -eq 1 ]; then
  colour4="cyan"
elif [ $l -eq 2 ]; then
  colour4="green"
elif [ $l -eq 3 ]; then
  colour4="magenta"
elif [ $l -eq 4 ]; then
  colour4="yellow"
elif [ $l -eq 5 ]; then
  colour4="white"
fi

# Now we roll the fortune dice!
p=$[${RANDOM}%100]
if [ $p -eq 0 ]; then
  echo " "
  fortune
fi

PROMPT="
%{$fg[$colour1]%}%B%n%b%{$reset_color%} %{$fg[$colour3]%}%B>%b%{$reset_color%} %{$fg[$colour4]%}%B%M%b%{$reset_color%}%{$fg[$colour3]%}%B:%b%{$reset_color%} %{$fg[$colour2]%}%B%~%b%{$reset_color%} %{$fg[$colour1]%}%B|%b%{$reset_color%}
%{$fg[$colour3]%}%B$%b%{$reset_color%} "


Basically, the prompt is
user > host.domain: directory |
$
and its colours change randomly each use.
_________________
CFLAGS=" -O999999"


Last edited by LiamOS on Mon Jul 30, 2012 2:51 pm; edited 1 time in total
Back to top
View user's profile Send private message
khayyam
Advocate
Advocate


Joined: 07 Jun 2012
Posts: 2151

PostPosted: Mon Jul 30, 2012 9:29 am    Post subject: Reply with quote

LiamOS ...

for me colour functions as as visual clue and I think I'd find your prompt more of an annoyance than an aid, but each to their own. Plus, for general use I wouldn't want to source my .zshrc on each command, and I question the wisdom of doing this simply for the purpose of aesthetics.

My prompt provides a visual (colour) clue of two factors: the UID the shell is running under, and the location (local/remote).

Code:
# PROMPTS (local and ssh/remote)

# Colours (256 on a compatable terminal) are set via a numerical
# value '{n}' and not ANSI escape sequence ... see: .zsh/scripts/spectrum.zsh

if [[ -z ${SSH_CLIENT} && ${UID} -gt "0" ]] ; then
    PS1=$'[%F{2}%n%f@%F{2}%m%f: %F{4}%3~%f]%# '
    RPS1=$'%F{1} %f[%F{1}%B%h%b%F{1}%f]'
elif [[ -z ${SSH_CLIENT} && ${UID} -eq "0" ]] ; then
    PS1=$'[%F{1}%n%f@%F{1}%m%f: %F{4}%3~%f]%# '
    RPS1=$'%F{1} %f[%F{1}%B%h%b%F{1}%f]'
elif [[ -n ${SSH_CLIENT} && ${UID} -gt "0" ]] ; then
    PS1=$'[%F{2}%n%f@%F{6}%m%f: %F{4}%3~%f]%# '
    RPS1=$'%F{1} %f[%F{1}%B%h%b%F{1}%f]'
elif [[ -n ${SSH_CLIENT} && ${UID} -eq "0" ]] ; then
    PS1=$'[%F{1}%n%f@%F{6}%m%f: %F{4}%3~%f]%# '
    RPS1=$'%F{1} %f[%F{1}%B%h%b%F{1}%f]'
else
    PS1='%n@%m %B%3~%b %# '
fi

The spectum.zsh is from P.C. Shyamshankar (here).

The prompt is fairly simple (by zsh standards) with just user, host, path, and history (RPS1 ... on the right side) ... and the additional visual clues.

best ... khay


Last edited by khayyam on Mon Jul 30, 2012 9:55 am; edited 1 time in total
Back to top
View user's profile Send private message
mv
Advocate
Advocate


Joined: 20 Apr 2005
Posts: 3998

PostPosted: Mon Jul 30, 2012 9:54 am    Post subject: Reply with quote

khayyam wrote:
for me colour functions as as visual clue

++
Quote:
Plus, for general use I wouldn't want to source my .zshrc on each command

Actually, it is even worse since it is sourced each second and not each command - which makes no sense concerning prompt colors. I would use PS1=$(....${RANDOM}...) if I would want different colors for every prompt.
Quote:
My prompt provides a visual (colour) clue of two factors: the UID the shell is running under, and the location (local/remote).
[...]
The prompt is fairly simple (by zsh standards) with just user, host, path, and history (RPS1 ... on the right side) ... and the additional visual clues.

IMHO this is exactly how a good prompt should be. Perhaps it is too simple if you use xterm/screen/tmux since then you might want to set some soft/hard status lines. Also, perhaps, you might want to cut paths if they become so long that they almost fill a line.
If you want to add both, you might want to use the set_prompt script (available from the mv overlay).
Note: A feature of the script is that you can also use it for bash if you have to... :wink:
Back to top
View user's profile Send private message
khayyam
Advocate
Advocate


Joined: 07 Jun 2012
Posts: 2151

PostPosted: Mon Jul 30, 2012 10:19 am    Post subject: Reply with quote

mv wrote:
khayyam wrote:
[...]The prompt is fairly simple (by zsh standards) with just user, host, path, and history (RPS1 ... on the right side) ... and the additional visual clues.

IMHO this is exactly how a good prompt should be. Perhaps it is too simple if you use xterm/screen/tmux since then you might want to set some soft/hard status lines.

mv ... I use a precmd/preexec function for status, and this is only for tmux as my terminals don't have titlebars (tiled WM).

mv wrote:
Also, perhaps, you might want to cut paths if they become so long that they almost fill a line.

'%3~' will do exactly this (truncate to three directories).

mv wrote:
If you want to add both, you might want to use the set_prompt script (available from the mv overlay).

I'm not sure I looked at this, but I will ... thanks for putting together app-shells/zsh-run-help btw ...

best ... khay
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Gentoo Chat All times are GMT
Goto page Previous  1, 2, 3 ... 9, 10, 11, 12, 13  Next
Page 10 of 13

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum