# SET PROMPTS - see also http://aperiodic.net/phil/prompt/ # vim:syn=zsh where debugme >/dev/null 2>&1 || debugme() { true; } debugme setting system name/id/color prefs [ -r "${ZDOTDIR:=$HOME}/sysprefs" ] && source "$ZDOTDIR/sysprefs" PRIME_HOST=${PRIME_HOST:-cayenne} PRIME_UID=${PRIME_UID:-1000} PRIME_COLOR=${PRIME_COLOR:-1;33} debugme setting prompt_subst setopt prompt_subst # allow variable substitution debugme aliasing prompt-fixers # allow escape from colors and titlebar alias fix_prompt='export PROMPT="[%n@%m %~]%# "; unset RPROMPT; precmd() {;}' # alias calendar in prompt alias hcal_prompt='precmd() { PROMPT=''; unset RPROMPT; clear; cal -3; }' alias cal_prompt='precmd() { PROMPT=''; unset RPROMPT; clear; cal `date -d "last month" +"%m %Y"`; cal; cal `date -d "next month" +"%m %Y"`; }' debugme switch to determine support by reported terminal type case $TERM in rxvt* | vt100* | xterm* | Linux | dtterm* ) debugme rxvt, vt100, xterm, xterm-color, Linux, or dtterm # overall Prompt Color, $PC if echo "$OS" |grep -qiE 'linux|bsd' >/dev/null 2>&1 then [ "$(hostname -s)" = "$PRIME_HOST" ] && PC=$PRIME_COLOR || PC='0;32' else PC='0;31' fi PR='0;32' # green square brackets surrounding prompt function PSC() { echo -n "%{\e[${*}m%}"; } # insert color specifying chars # except on Linux console, title_say prints to titlebar [ "$TERM" != "Linux" ] && TSAY='print -Pn "\e]0;${*}\a"' # Username with Color tags: checks below + username (%n) + revert color # %(if uid=me, then '', else %(if priviledged, then white-on-red, else red)) #UCOLOR="%($PRIME_UID#,,%(!,`PSC '0;41'`,`PSC '0;31'`))%n$(PSC $PC)" # %(if me, then name, else red %(if priviledged, stand-out name, else name)) UCOLOR="%($PRIME_UID#,`PSC $PC`%n,`PSC '0;31'`%(!,%S%n%s,%n))`PSC $PC`" # If the last command returned 0 (true), prompt hash is green, otherwise red ERR="%(0?,`PSC '0;32'`,`PSC '1;31'`)" # Color STDERR red - Doesn't belong here, but we know that colors work here # taken from http://gentoo-wiki.com/TIP_Advanced_zsh_Completion #exec 2>>(while read line; do # print '\e[91m'${(q)line}'\e[0m' > /dev/tty; done &) ;; * ) debugme terminal type unknown, no colors, no title function PSC() { true; } # no color support? no problem!) UCOLOR="%n" # user name with (no) color tags ;; esac debugme title_say will report text to the titlebar if that is safe to do # safely print to titlebar (and stdout unless -q is passed) title_say() { [ "$1" != "-q" ] && echo "$*" || shift # without -q, print to stdout [ -n "$TSAY" ] && eval $TSAY # when safe, print to titlebar } # ensure we have the PWD path-shortening function function is_installed() { #[ "$1" = '-not' ] && shift && check='-z' || check='-n' #[ $check "$(which $1 2>/dev/null)" ] which "$1" 2>/dev/null |grep "$1$" >/dev/null } [ -z "$USER" ] && USER=`whoami || who ami || echo $LOGNAME` 2>/dev/null debugme set PWD-shortener if ! is_installed PWD; then [ -n "$CYGWIN" ] && cygpwd='s:^/cygdrive/([a-z])(/|$):\1\:/:;' is_installed perl \ && function PWD() { echo "$*" |perl -pne 's:^'"$HOME"':~:;'"$cygpwd"'s:^(.{10}).{4}.*(.{20})$:$1...$2:;'; } \ || alias PWD=echo fi debugme call PWD-shortener on each prompt and report it with title_say function precmd() { PTH="$(PWD $(print -Pn %~))" # shortened path for display title_say -q "%n@%m: %~" # titlebar text to display (if compatible) } debugme set prompt and right-prompt PROMPT="$(PSC $PR)[$UCOLOR@%m$(PSC '0;33') \$PTH$(PSC $PR)]$ERR%#$(PSC '0;0') " RPROMPT="$(PSC '0;34')%w %*$(PSC '0;0')" # right-aligned date, mm/dd/yy hh:mm:ss # these aren't needed anymore unset PR PC ERR UCOLOR PRIME_HOST PRIME_COLOR PRIME_UID