aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/prompt_adam3_setup
diff options
context:
space:
mode:
authorDennis Eriksen <d@ennis.no>2023-01-02 14:06:23 +0100
committerDennis Eriksen <d@ennis.no>2023-01-02 14:06:23 +0100
commitd647d5597c140c2b96157e245559f431d13395dc (patch)
treecb1ec4d6d184014503eeaf7c938d319cd49e79a6 /prompt_adam3_setup
parentrewriting prompt. wip (diff)
downloadadam3-d647d5597c140c2b96157e245559f431d13395dc.tar.gz
change the way we assemble the prompt. Now we cas measure the length and slip into double-line-mode when the prompt exceeds 50% of the terminal
Diffstat (limited to '')
-rw-r--r--prompt_adam3_setup69
1 files changed, 40 insertions, 29 deletions
diff --git a/prompt_adam3_setup b/prompt_adam3_setup
index ad6fefb..c3ef586 100644
--- a/prompt_adam3_setup
+++ b/prompt_adam3_setup
@@ -23,19 +23,24 @@ prompt_adam3_setup () {
autoload -Uz vcs_info
# colors
- typeset -g PROMPT_ADAM3_COLOR1=${1:-'multi'}
- typeset -g PROMPT_ADAM3_COLOR2=${2:-'blue'}
- typeset -g PROMPT_ADAM3_COLOR3=${3:-'cyan'}
+ typeset PROMPT_ADAM3_COLOR1=${1:-'multi'}
+ typeset PROMPT_ADAM3_COLOR2=${2:-'blue'}
+ typeset PROMPT_ADAM3_COLOR3=${3:-'cyan'}
typeset -g PROMPT_ADAM3_COLOR4=${4:-'green'}
# Prepare prompt
typeset -g PROMPT_ADAM3_PS1
- # Promptchar
- typeset -g PROMPT_ADAM3_PROMPTCHAR='%B%F{%(!.red.white)}%#%f%b'
+ # Promptchar (including exitcode)
+ typeset -g PROMPT_ADAM3_PROMPTCHAR='%(?..[%F{red}%?%f] )%B%F{%(!.red.white)}%#%f%b '
# same as above, but with $ instead of % as promptchar for unprivileged users
#typeset -g PROMPT_ADAM3_PROMPTCHAR='%B%(!.%F{red}#.F{white}$)%f%b'
+ # DIR in single-line-mode
+ typeset -g PROMPT_ADAM3_SL_DIR="%B%F{$PROMPT_ADAM3_COLOR3}%-40<..<%(5~|%-1~/../%3~|%4~)%f%b%<< "
+ # DIR in double-line-mode
+ typeset -g PROMPT_ADAM3_DL_DIR="%B%F{$PROMPT_ADAM3_COLOR3}%-10<..<%~%f%b%<<"
+
# Prepare som local variables
local -i hm=15 # max chars in hostname. Recalculate if above.
@@ -109,35 +114,41 @@ prompt_adam3_setup () {
prompt_adam3_precmd () {
setopt localoptions extendedglob noxtrace
- local nl=$'\n'
+ # time
+ local time="%F{$PROMPT_ADAM3_COLOR4}%*%f"
- PS1="${PROMPT_ADAM3_PS1}"
+ # vcs
+ vcs_info #$vcs_info_msg_0_
- # Change prompt layout at 70 cols. If more - single line. If less - double line.
- if (( COLUMNS > 70 )); then
- PS1+="%B%F{$PROMPT_ADAM3_COLOR3}%-40<..<%(4~,..,)%3~%f%b%<< "
- RPS1="%F{$PROMPT_ADAM3_COLOR4}%*%f"
- else
- PS1+="%B%F{$PROMPT_ADAM3_COLOR3}%-10<..<%~%f%b%<<"
-
- # Do clock on same line. RPS1 does not support multiline.
- RPS1=
- # Calculate prompt-length by first removing all zero-length characters. From
- # prompt_bart_setup in zsh.
- local -i prompt_length=${#${(S%%)PS1//\%([BSUbfksu]|[FK]\{*\})/}}
- #local spaces=$((COLUMNS - prompt_length + 2))
- #local right="%F{$PROMPT_ADAM3_COLOR4}%*%f"
- #PS1+="${(l:$spaces:)right}$nl"
- PS1+="${(l:$((COLUMNS - prompt_length +2)):):-"%F{$PROMPT_ADAM3_COLOR4}%*%f"}$nl"
- fi
+ local prom
+ prom=$PROMPT_ADAM3_PS1
+ prom+=$PROMPT_ADAM3_SL_DIR
+ prom+=$vcs_info_msg_0_
+ prom+=$PROMPT_ADAM3_PROMPTCHAR
+
+ # Calculate prompt-length by first removing all zero-length characters. From
+ # prompt_bart_setup in zsh.
+ local prompt_length=${#${(S%%)prom//\%([BSUbfksu]|[FK]\{*\})/}}
- vcs_info
- PS1+="${vcs_info_msg_0_}"
+ # If the prompt is over half the terminal, we go into multiline-mode.
+ if (( (COLUMNS / 2) < prompt_length )); then
+ prom=$PROMPT_ADAM3_PS1 # reset prompt
+ prom+=$PROMPT_ADAM3_DL_DIR # dir
- # Display exit-code
- PS1+="%(?..[%F{red}%?%f] )"
+ # We need to recalculate prompt_length to know where to put time
+ prompt_length=${#${(S%%)prom//\%([BSUbfksu]|[FK]\{*\})/}}
+
+ # Add time. Left-pad with spaces.
+ prom+=${(l:$((COLUMNS - prompt_length + 1 )):)time}
+ prom+=$'\n' # newline
+ prom+=$vcs_info_msg_0_ # vcs
+ prom+=$PROMPT_ADAM3_PROMPTCHAR # promptchar
+ RPS1= # RPS1 does not support multiline, so reset it when we're in multiline
+ else
+ RPS1=$time
+ fi
- PS1+="$PROMPT_ADAM3_PROMPTCHAR "
+ PS1=$prom
(( ${+VIRTUAL_ENV} )) && PS1="%F{208}(${VIRTUAL_ENV:t})%f ${PS1}"
PS2="${PS1}%_> %b%f%k"
PS3="${PS1}?# %b%f%k"