You are not logged in.

#1 2011-11-07 22:05:49

094TQ5
Member
Registered: 2011-10-12
Posts: 6

ZSH using a different PS1 depending on hostname? [SOLVED]

SOLVED
Mikachu on irc.freenode.net #zsh gave me a good solution:

case $HOST in
    TARDIS)
        hostcolor=blue
        ;;
    CentzonTotochtin)
        hostcolor=cyan
        ;;
    Highwind)
        hostcolor=white
        ;;
    *)
        hostcolor=gray
        ;;
esac
PS1="%{$fg[$hostcolor]%}%B%m%b%u%{$reset_color%}:%{$fg[green]%}%2~%{$fg[magenta]%}%%%{$reset_color%} "
#PS1 thanks to Mikachu on irc.freenode.net #zsh

/SOLVED


A little background
I've got around to setting up git in my home directory (leaving a '*' in ~/.git/info/exclude, and using 'git add -f $FILE') to make sure all my machines are using the same dotfiles, but I use a different PS1 based on what machine I'm using.  I'd love to have a single .zshrc I could drop into the git repo and use for all machines, as opposed to say, zsh evaluating a seperate '~/.PS1' I set up by hand on each machine.

But getting to the point:
My PS1 is this:

PS1="%{$fg[cyan]%}%B%m%b%u%{$reset_color%}:%{$fg[green]%}%2~%{$fg[magenta]%}%%%{$reset_color%} "

the only difference between the .zshrc on each machine is that the hostname is given a different color, so that the machine 'TARDIS' might have the hostname in PS1 as blue, machine 'Centzon' might have the hostname as cyan, and if the .zshrc is on any other host, the hostname in PS1 is just grey.  I'm not sure how to go about this with .zshrc, but here's a rough idea:

eval hostname
    if hostname=TARDIS
        PS1="%{$fg[blue]%}%B%m%b%u%{$reset_color%}:%{$fg[green]%}%2~%{$fg[magenta]%}%%%{$reset_color%} "
    if hostname=Centzon
        PS1="%{$fg[cyan]%}%B%m%b%u%{$reset_color%}:%{$fg[green]%}%2~%{$fg[magenta]%}%%%{$reset_color%} "
    else
        PS1="%{$fg[grey]%}%B%m%b%u%{$reset_color%}:%{$fg[green]%}%2~%{$fg[magenta]%}%%%{$reset_color%} "

Has anyone come up with something like this?  If not, how would I do something like this in ZSH?

Last edited by 094TQ5 (2011-11-08 00:31:42)

Offline

Board footer

Powered by FluxBB