# The Prompt PS1='%m(%35<...<%~) %(?..!%?! )%# ' # This section sets useful variables for various things... HOST="$(hostname)" HOST="${HOST%%.*}" UNAME="$(uname)" # title/precmd/postcmd function precmd() { title "zsh - $PWD" } function preexec() { # The full command line comes in as "$1" local cmd="$1" local -a args # add '--' in case $1 is only one word to work around a bug in ${(z)foo} # in zsh 4.3.9. tmpcmd="$1 --" args=${(z)tmpcmd} # remove the '--' we added as a bug workaround.. # per zsh manpages, removing an element means assigning () args[${#args}]=() if [ "${args[1]}" = "fg" ] ; then local jobnum="${args[2]}" if [ -z "$jobnum" ] ; then # If no jobnum specified, find the current job. for i in ${(k)jobtexts}; do [ -z "${jobstates[$i]%%*:+:*}" ] && jobnum=$i done fi cmd="${jobtexts[${jobnum#%}]}" else fi title "$cmd" } function title() { # This is madness. # We replace literal '%' with '%%' # Also use ${(V) ...} to make nonvisible chars printable (think cat -v) # Replace newlines with '; ' local value="${${${(V)1//\%/\%\%}//'\n'/; }//'\t'/ }" local location location="$HOST" [ "$USERNAME" != "$LOGNAME" ] && location="${USERNAME}@${location}" # Special format for use with print -Pn value="%70>...>$value%<<" unset PROMPT_SUBST case $TERM in screen) # Put this in your .screenrc: # hardstatus string "[%n] %h - %t" # termcapinfo xterm 'hs:ts=\E]2;:fs=\007:ds=\E]2;screen (not title yet)\007' print -Pn "\ek${value}\e\\" # screen title (in windowlist) print -Pn "\e_${location}\e\\" # screen location ;; xterm*) print -Pn "\e]0;$value\a" ;; esac setopt LOCAL_OPTIONS }