OpenBSD CARP router/firewall zsh shell prompt

From WTFwiki
Revision as of 09:25, 8 November 2009 by Jontow (talk | contribs) (add zsh/openbsd/carp prompt hack)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Reasoning

Recently, I've been working with CARP clustered routers and firewalls pretty often,
and found that too often I'm troubleshooting the wrong machine.. This little hack
should help prevent that. It changes the hostname portion of my zsh shell prompt to
reflect whether the current machine is a master or a backup in the cluster.

It is only tested in zsh on OpenBSD.. if you try this elsewhere.. please update this page.

Zsh Prompt

My prompt looks like this:

 ^:jontow@ort1:~%

The 'ort1' portion is what this changes.. if you leave 'PROMPT_PERCENT=true' in here, it
should also take effect when you 'sudo zsh' or otherwise elevate privileges.

 if [ "$(uname -s)" = "OpenBSD" ]; then
         # Are we the master?
         if [ "$(ifconfig carp | grep "carp:" | grep -e "MASTER" | head -1)" != "" ]; then
                 PROMPT_HOST="^[[1;32m%m^[[0;0m"
         else
                 PROMPT_HOST="^[[1;31m%m^[[0;0m"
         fi
 else
         PROMPT_HOST="%m"
 fi

 PROMPT_PERCENT=true  ; export PROMPT_PERCENT
 PROMPT="%(?,^,_):%n@${PROMPT_HOST}:%~%# " ; export PROMPT