Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Funky zsh prompts
- X-seq: zsh-users 1432
- From: Adam Spiers <adam@xxxxxxxxxxxxxxxxxxxxxxx>
- To: ZSH User Mailinglist <zsh-users@xxxxxxxxxxxxxxx>
- Subject: Funky zsh prompts
- Date: Thu, 26 Mar 1998 21:25:11 +0000
- In-reply-to: <Pine.GSO.3.95q.980326123805.4625A-100000@petzval>; from C. v. Stuckrad on Thu, Mar 26, 1998 at 12:58:34PM +0100
- Mail-followup-to: ZSH User Mailinglist <zsh-users@xxxxxxxxxxxxxxx>
- References: <199803251727.RAA05268@xxxxxxxxxxxxxxxx> <Pine.GSO.3.95q.980326123805.4625A-100000@petzval>
- Reply-to: Adam Spiers <adam.spiers@xxxxxxxxxxxx>
C. v. Stuckrad (stucki@xxxxxxxxxxxxxxxxx) wrote:
> On Wed, 25 Mar 1998, Andrew Main wrote:
>
> > >Benbar came up with the amusing idea of making the smiley prompt change
> > >randomly every time I hit return (or even change to something that
> > >reflects the load of the machine).
> >
> > Cool idea.
Very cool! I think it's about time I posted my BPFH :-)
Any suggestions for improving it welcome.
-------- 8< -------- 8< --------
reset_colour="$(echo -n '\e[0m')"
bold_colour="$(echo -n '\e[1m')"
# Foreground
grey="$(echo -n '\e[30m')"
red="$(echo -n '\e[31m')"
green="$(echo -n '\e[32m')"
yellow="$(echo -n '\e[33m')"
blue="$(echo -n '\e[34m')"
magenta="$(echo -n '\e[35m')"
cyan="$(echo -n '\e[36m')"
white="$(echo -n '\e[37m')"
# Background
bg_grey="$(echo -n '\e[40m')"
bg_red="$(echo -n '\e[41m')"
bg_green="$(echo -n '\e[42m')"
bg_yellow="$(echo -n '\e[43m')"
bg_blue="$(echo -n '\e[44m')"
bg_magenta="$(echo -n '\e[45m')"
bg_cyan="$(echo -n '\e[46m')"
bg_white="$(echo -n '\e[47m')"
BASE_PROMPT="%{$bg_blue%}%m:%n%{$reset_colour%} "
POST_PROMPT="%{$reset_colour%}"
BASE_PROMPT_NO_COLOUR=$(echo "$BASE_PROMPT" | perl -pe "s/%{.*?%}//g")
POST_PROMPT_NO_COLOUR=$(echo "$POST_PROMPT" | perl -pe "s/%{.*?%}//g")
# Define prompts
PROMPT_NEWLINE=$(echo -ne "\n%{\r%}")
function precmd {
setopt noxtrace localoptions
local base_prompt base_prompt_etc prompt_length space_left
base_prompt=$(print -P "$BASE_PROMPT_NO_COLOUR")
base_prompt_etc=$(print -P "$base_prompt%(4~|...|)%3.")
prompt_length=${#base_prompt_etc}
# echo "Prompt length is $prompt_length"
# echo "Base prompt length is $#base_prompt"
if [[ $prompt_length -lt 40 ]]; then
PATH_PROMPT="%{$bold_colour$cyan%}%(4~|...|)%3.%{$white%}"
else
space_left=$(( $COLUMNS - $#base_prompt - 2 ))
# echo "Space left is $space_left"
PATH_PROMPT="%{$bold_colour$green%}%${space_left}<...<%~$PROMPT_NEWLINE%{$white%}"
fi
PS1="$BASE_PROMPT$PATH_PROMPT %# $POST_PROMPT"
PS2="$BASE_PROMPT$PATH_PROMPT %_> $POST_PROMPT"
PS3="$BASE_PROMPT$PATH_PROMPT ?# $POST_PROMPT"
}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author