add extra options to pure style

- non-permanent content location (left or right)
- show current time
- prompt height (one or two lines)
- prompt spacing (with empty line between prompts or without)
This commit is contained in:
romkatv 2020-02-02 06:49:17 +01:00
parent eb9da89ad9
commit 4599ad9f2c
6 changed files with 109 additions and 52 deletions

View file

@ -34,7 +34,7 @@
dir # current directory
vcs # git status
# =========================[ Line #2 ]=========================
newline
newline # \n
# prompt_char # prompt symbol
)
@ -89,7 +89,7 @@
timewarrior # timewarrior tracking status (https://timewarrior.net/)
# time # current time
# =========================[ Line #2 ]=========================
newline
newline # \n
# public_ip # public IP address
# proxy # system-wide http/https/ftp proxy
# battery # internal battery

View file

@ -34,7 +34,7 @@
dir # current directory
vcs # git status
# =========================[ Line #2 ]=========================
newline
newline # \n
prompt_char # prompt symbol
)
@ -88,7 +88,7 @@
timewarrior # timewarrior tracking status (https://timewarrior.net/)
# time # current time
# =========================[ Line #2 ]=========================
newline
newline # \n
# public_ip # public IP address
# proxy # system-wide http/https/ftp proxy
# battery # internal battery

View file

@ -34,7 +34,7 @@
dir # current directory
vcs # git status
# =========================[ Line #2 ]=========================
newline
newline # \n
prompt_char # prompt symbol
)

View file

@ -42,17 +42,27 @@
# Left prompt segments.
typeset -g POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(
# =========================[ Line #1 ]=========================
dir # current directory
vcs # git status
context # user@host
command_execution_time # previous command duration
# =========================[ Line #2 ]=========================
newline # \n
virtualenv # python virtual environment
prompt_char # prompt symbol
)
# Right prompt segments.
typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=()
typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(
# =========================[ Line #1 ]=========================
# command_execution_time # previous command duration
# virtualenv # python virtual environment
# context # user@host
# time # current time
# =========================[ Line #2 ]=========================
newline # \n
)
# Basic style options that define the overall prompt look.
typeset -g POWERLEVEL9K_BACKGROUND= # transparent background
@ -62,7 +72,7 @@
typeset -g POWERLEVEL9K_VISUAL_IDENTIFIER_EXPANSION= # no segment icons
# Add an empty line before each prompt except the first. This doesn't emulate the bug
# in Pure that makes prompt drift down whenever you use the ALT-C binding from fzf or similar.
# in Pure that makes prompt drift down whenever you use the Alt-C binding from fzf or similar.
typeset -g POWERLEVEL9K_PROMPT_ADD_NEWLINE=true
# Magenta prompt symbol if the last command succeeded.
@ -135,6 +145,15 @@
# Remove space between '⇣' and '⇡' and all trailing spaces.
typeset -g POWERLEVEL9K_VCS_CONTENT_EXPANSION='${${P9K_CONTENT/⇣* ⇡/⇣⇡}// }'
# Grey current time.
typeset -g POWERLEVEL9K_TIME_FOREGROUND=$grey
# Format for the current time: 09:51:02. See `man 3 strftime`.
typeset -g POWERLEVEL9K_TIME_FORMAT='%D{%H:%M:%S}'
# If set to true, time will update when you hit enter. This way prompts for the past
# commands will contain the start times of their commands rather than the end times of
# their preceding commands.
typeset -g POWERLEVEL9K_TIME_UPDATE_ON_COMMAND=false
# Transient prompt works similarly to the builtin transient_rprompt option. It trims down prompt
# when accepting a command line. Supported values:
#

View file

@ -34,7 +34,7 @@
dir # current directory
vcs # git status
# =========================[ Line #2 ]=========================
newline
newline # \n
# prompt_char # prompt symbol
)

View file

@ -80,12 +80,12 @@ local -ra classic_right=(
)
local -ra pure_left=(
'' '%F{$pure_color[blue]}~/src%f %F{$pure_color[grey]}master%f %F{$pure_color[yellow]}5s%f'
'' '%F{$pure_color[blue]}~/src%f %F{$pure_color[grey]}master%f ${pure_use_rprompt-%F{$pure_color[yellow]\}5s%f }'
'' '%F{$pure_color[magenta]}%f ${buffer:-█}'
)
local -ra pure_right=(
'' ''
'${pure_use_rprompt+%F{$pure_color[yellow]\}5s%f${show_time:+ }}${show_time:+%F{$pure_color[grey]\}16:23:42%f}' ''
'' ''
)
@ -769,7 +769,7 @@ function ask_ornaments_color() {
}
function ask_time() {
if (( wizard_columns < 80 )); then
if (( wizard_columns < 80 )) && [[ $style != pure ]]; then
show_time=
return 0
fi
@ -801,6 +801,35 @@ function ask_time() {
done
}
function ask_use_rprompt() {
[[ $style != pure ]] && return
while true; do
clear
flowing -c "%BNon-permanent content location%b"
print -P ""
print -P "%B(1) Left.%b"
print -P ""
print_prompt
print -P ""
print -P "%B(2) Right.%b"
print -P ""
pure_use_rprompt= print_prompt
print -P ""
print -P "(r) Restart from the beginning."
print -P "(q) Quit and do nothing."
print -P ""
local key=
read -k key${(%):-"?%BChoice [12rq]: %b"} || quit -c
case $key in
q) quit;;
r) return 1;;
1) break;;
2) pure_use_rprompt=; options+=rpromt; break;;
esac
done
}
function os_icon_name() {
local uname="$(uname)"
if [[ $uname == Linux && "$(uname -o 2>/dev/null)" == Android ]]; then
@ -846,7 +875,7 @@ function os_icon_name() {
}
function ask_extra_icons() {
if [[ $POWERLEVEL9K_MODE == (powerline|compatible) ]]; then
if [[ $style == pure || $POWERLEVEL9K_MODE == (powerline|compatible) ]]; then
return 0
fi
local os_icon=${(g::)icons[$(os_icon_name)]}
@ -900,6 +929,7 @@ function ask_extra_icons() {
}
function ask_prefixes() {
[[ $style == pure ]] && return
local concise=('' '' '')
local fluent=('on ' 'took ' 'at ')
if (( wizard_columns < 80 )); then
@ -1201,9 +1231,7 @@ function ask_num_lines() {
}
function ask_gap_char() {
if [[ $num_lines != 2 ]]; then
return 0
fi
[[ $num_lines != 2 || $style == pure ]] && return
while true; do
clear
flowing -c "%BPrompt Connection%b"
@ -1599,10 +1627,6 @@ function generate_config() {
sub RIGHT_PROMPT_LAST_SEGMENT_END_SYMBOL "'$right_tail'"
fi
if [[ -n $show_time ]]; then
uncomment time
fi
if [[ -n ${(j::)extra_icons} ]]; then
local branch_icon=${icons[VCS_BRANCH_ICON]// }
sub VCS_BRANCH_ICON "'$branch_icon '"
@ -1633,15 +1657,6 @@ function generate_config() {
fi
fi
if (( num_lines == 1 )); then
local -a tmp
local line
for line in "$lines[@]"; do
[[ $line == (' newline'|*'===[ Line #'*) ]] || tmp+=$line
done
lines=("$tmp[@]")
fi
sub MULTILINE_FIRST_PROMPT_GAP_CHAR "'$gap_char'"
if [[ $style == (classic|rainbow) && $num_lines == 2 ]]; then
@ -1683,10 +1698,32 @@ function generate_config() {
uncomment vi_mode
fi
fi
(( empty_line )) && sub PROMPT_ADD_NEWLINE true || sub PROMPT_ADD_NEWLINE false
fi
if (( $+pure_use_rprompt )); then
local segment
for segment in command_execution_time virtualenv context; do
rep " $segment" " tmp_$segment"
uncomment $segment
rep " tmp_$segment " " # $segment"
done
fi
if [[ -n $show_time ]]; then
uncomment time
fi
if (( num_lines == 1 )); then
local -a tmp
local line
for line in "$lines[@]"; do
[[ $line == (' newline'*|*'===[ Line #'*) ]] || tmp+=$line
done
lines=("$tmp[@]")
fi
(( empty_line )) && sub PROMPT_ADD_NEWLINE true || sub PROMPT_ADD_NEWLINE false
sub INSTANT_PROMPT $instant_prompt
(( transient_prompt )) && sub TRANSIENT_PROMPT always
@ -1793,6 +1830,8 @@ while true; do
local -A pure_color=(${(kv)pure_original})
fi
unset pure_use_rprompt
ask_font || continue
ask_diamond || continue
if [[ $AWESOME_GLYPHS_LOADED == 1 ]]; then
@ -1847,27 +1886,26 @@ while true; do
right_head=$fade_in
fi
_p9k_init_icons
ask_narrow_icons || continue
ask_style || continue
ask_color_scheme || continue
if [[ $style != pure ]]; then
ask_color || continue
ask_time || continue
ask_separators || continue
ask_heads || continue
ask_tails || continue
ask_num_lines || continue
ask_gap_char || continue
ask_frame || continue
ask_ornaments_color || continue
ask_empty_line || continue
ask_extra_icons || continue
ask_prefixes || continue
fi
ask_transient_prompt || continue
ask_instant_prompt || continue
ask_config_overwrite || continue
ask_zshrc_edit || continue
ask_narrow_icons || continue
ask_style || continue
ask_color_scheme || continue
ask_color || continue
ask_use_rprompt || continue
ask_time || continue
ask_separators || continue
ask_heads || continue
ask_tails || continue
ask_num_lines || continue
ask_gap_char || continue
ask_frame || continue
ask_ornaments_color || continue
ask_empty_line || continue
ask_extra_icons || continue
ask_prefixes || continue
ask_transient_prompt || continue
ask_instant_prompt || continue
ask_config_overwrite || continue
ask_zshrc_edit || continue
break
done
@ -1882,7 +1920,7 @@ if [[ -n $zshrc_backup ]]; then
fi
generate_config || return
change_zshrc || return
change_zshrc || return
print -rP ""
flowing +c File feature requests and bug reports at "$(href https://github.com/romkatv/powerlevel10k/issues)."