From 4f3d2ffe7251a17aa10e00ed30d55f6fd9d65002 Mon Sep 17 00:00:00 2001 From: Roman Perepelitsa Date: Fri, 10 Sep 2021 13:21:31 +0200 Subject: new prompt segment: toolbox (https://github.com/containers/toolbox) #1560 --- internal/icons.zsh | 6 ++++++ internal/p10k.zsh | 35 ++++++++++++++++++++++++++++++++--- internal/wizard.zsh | 2 ++ 3 files changed, 40 insertions(+), 3 deletions(-) (limited to 'internal') diff --git a/internal/icons.zsh b/internal/icons.zsh index bf5a1a11..dfbe0a00 100644 --- a/internal/icons.zsh +++ b/internal/icons.zsh @@ -145,6 +145,7 @@ function _p9k_init_icons() { PACKAGE_ICON 'pkg' JULIA_ICON 'jl' SCALA_ICON 'scala' + TOOLBOX_ICON '\u2B22' # ⬢ ) ;; 'awesome-fontconfig') @@ -274,6 +275,7 @@ function _p9k_init_icons() { PACKAGE_ICON 'pkg' JULIA_ICON 'jl' SCALA_ICON 'scala' + TOOLBOX_ICON '\u2B22' # ⬢ ) ;; 'awesome-mapped-fontconfig') @@ -406,6 +408,7 @@ function _p9k_init_icons() { PACKAGE_ICON 'pkg' JULIA_ICON 'jl' SCALA_ICON 'scala' + TOOLBOX_ICON '\u2B22' # ⬢ ) ;; 'nerdfont-complete'|'nerdfont-fontconfig') @@ -536,6 +539,7 @@ function _p9k_init_icons() { PACKAGE_ICON '\uF8D6' #  JULIA_ICON '\uE624' #  SCALA_ICON '\uE737' #  + TOOLBOX_ICON '\uE20F'$s #  ) ;; ascii) @@ -663,6 +667,7 @@ function _p9k_init_icons() { PACKAGE_ICON 'pkg' JULIA_ICON 'jl' SCALA_ICON 'scala' + TOOLBOX_ICON 'toolbox' ) ;; *) @@ -792,6 +797,7 @@ function _p9k_init_icons() { PACKAGE_ICON 'pkg' JULIA_ICON 'jl' SCALA_ICON 'scala' + TOOLBOX_ICON '\u2B22' # ⬢ ) ;; esac diff --git a/internal/p10k.zsh b/internal/p10k.zsh index c50292f2..98090d99 100644 --- a/internal/p10k.zsh +++ b/internal/p10k.zsh @@ -1651,6 +1651,20 @@ prompt_host() { instant_prompt_host() { prompt_host; } +################################################################ +# Toolbox: https://github.com/containers/toolbox +function prompt_toolbox() { + _p9k_prompt_segment $0 $_p9k_color1 yellow TOOLBOX_ICON 0 '' $P9K_TOOLBOX_NAME +} + +_p9k_prompt_toolbox_init() { + typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$P9K_TOOLBOX_NAME' +} + +function instant_prompt_toolbox() { + _p9k_prompt_segment prompt_toolbox $_p9k_color1 yellow TOOLBOX_ICON 1 '$P9K_TOOLBOX_NAME' '$P9K_TOOLBOX_NAME' +} + ################################################################ # The 'custom` prompt provides a way for users to invoke commands and display # the output in a segment. @@ -5906,7 +5920,7 @@ _p9k_set_instant_prompt() { [[ -n $RPROMPT ]] || unset RPROMPT } -typeset -gri __p9k_instant_prompt_version=42 +typeset -gri __p9k_instant_prompt_version=43 _p9k_dump_instant_prompt() { local user=${(%):-%n} @@ -6117,6 +6131,9 @@ _p9k_dump_instant_prompt() { unfunction p10k-on-post-widget' fi >&$fd print -r -- ' + () { +'$functions[_p9k_init_toolbox]' + } trap "unset -m _p9k__\*; unfunction p10k" EXIT local -a _p9k_t=("${(@ps:$us:)${tail%%$rs*}}") if [[ $+VTE_VERSION == 1 || $TERM_PROGRAM == Hyper ]] && (( $+commands[stty] )); then @@ -8123,6 +8140,17 @@ _p9k_init_ssh() { [[ $w =~ "\(?($ipv4|$ipv6|$hostname)\)?\$" ]] && P9K_SSH=1 } +_p9k_init_toolbox() { + [[ -z $P9K_TOOLBOX_NAME && + -e /run/.toolboxenv && + -f /run/.containerenv && + -r /run/.containerenv ]] || return 0 + local name=(${(Q)${${(@M)${(f)"$(