zsh-users
 help / color / mirror / code / Atom feed
From: Adam Spiers <adam@thelonious.new.ox.ac.uk>
To: ZSH User Mailinglist <zsh-users@math.gatech.edu>
Subject: Funky zsh prompts
Date: Thu, 26 Mar 1998 21:25:11 +0000	[thread overview]
Message-ID: <19980326212511.17303@thelonious.new.ox.ac.uk> (raw)
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

C. v. Stuckrad (stucki@math.fu-berlin.de) 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"
}


  parent reply	other threads:[~1998-03-26 21:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <Pine.GSO.3.96.980325155059.26447D-100000@flivoreuse>
1998-03-25 17:27 ` Zsh question Andrew Main
1998-03-26 11:58   ` Zsh question (more smileys in the prompt) C. v. Stuckrad
1998-03-26 18:40     ` Andrew Main
1998-03-26 21:25     ` Adam Spiers [this message]
1998-03-26 22:11       ` Funky zsh prompts Mike Smith
1998-03-31 18:27         ` Sven Guckes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=19980326212511.17303@thelonious.new.ox.ac.uk \
    --to=adam@thelonious.new.ox.ac.uk \
    --cc=adam.spiers@new.ox.ac.uk \
    --cc=zsh-users@math.gatech.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).