about summary refs log tree commit diff
path: root/Functions/Prompts/prompt_oliver_setup
blob: c4a28b705602d78b29404d4a67eeaffdae9973d5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# oliver prompt theme

prompt_oliver_help() {
  cat <<'ENDHELP'
With this prompt theme, the prompt contains the current directory,
history number, number of jobs (if non-zero) and the previous
command's exit code (if non-zero) and a final character which
depends on priviledges.

The colour of the prompt depends on two associative arrays -
$pcolour and $tcolour. Each array is indexed by the name of the
local host. Alternatively, the colour can be set with parameters
to prompt. To specify colours, use English words like 'yellow',
optionally preceded by 'bold'.

The hostname and username are also included unless they are in the
$normal_hosts or $normal_users array.
ENDHELP
}

prompt_oliver_setup() {
  prompt_opts=( cr subst percent )

  [[ "${(t)pcolour}" != assoc* ]] && typeset -Ag pcolour
  [[ "${(t)tcolour}" != assoc* ]] && typeset -Ag tcolour
  local pcol=${1:-${pcolour[${HOST:=`hostname`}]:-yellow}}
  local pcolr=$fg[${pcol#bold}]
  [[ $pcol = bold* ]] && pcolr=$bold_color$pcolr
  
  local tcol=${2:-${tcolour[$HOST]:-white}}
  local tcolr=$reset_color$fg[${tcol#bold}]
  [[ $tcol = bold* ]] && tcolr=$tcolr$bold_color
  
  local a host="%m:" user="%n "
  [[ $HOST == (${(j(|))~normal_hosts}) ]] && host=""
  [[ ${USER:-`whoami`} == (root|${(j(|))~normal_users}) ]] && user=""

  PS1="%{$pcolr%}$user$host%~%"'$((COLUMNS-12))'"(l.$prompt_newline. )[%h%1(j.%%%j.)%0(?..:%?)]%# %{$tcolr%}"
}

prompt_oliver_setup "$@"